bool subtype(node s, node t){ if (ispos(s)) s = s->body.position.contents; if (ispos(t)) t = t->body.position.contents; assert(istype(s) && istype(t)); s = typeforward(s); t = typeforward(t); if (s == t) return TRUE; if (s == bad_or_undefined_T || t == bad_or_undefined_T) return TRUE; if (isortype(s) && isortype(t)) { int i, j, slen, tlen; s = typedeftail(s); slen = length(s); t = typedeftail(t); tlen = length(t); for (i=1; i<=slen; i++) { for (j=1; j<=tlen; j++) { if (subtype(nth(s,i),nth(t,j))) goto okay; } return FALSE; okay:; } return TRUE; } if (isortype(s)) return FALSE; if (isortype(t)) { int j, tlen; t = typedeftail(t); tlen = length(t); for (j=1; j<=tlen; j++) { if (subtype(s,nth(t,j))) return TRUE; } return FALSE; } return FALSE; /* for other types, we assume that totypesRec has worked and made equivalent types identical */ }
void test_lisp_parse_1() { Value parsed = parse(blob_s("(test 1 2 3)")); expect_str(nth(parsed, 0), ":test"); expect(nth(parsed, 1).raw == int_value(1).raw); expect_str(parsed, "[:test, 1, 2, 3]"); decref(parsed); }
float getTukey(int ndat,float *dat,float *med,float *mad) { int niter=10; int n,i; float t,c,s; float u; double sdenom,snumer; float *a; if((a=(float*)malloc(sizeof(float)*ndat))==NULL) { fprintf(stderr,"Cannot allocate a in getTukey, ndat=%d\n",ndat); exit(-1); } memcpy(a,dat,sizeof(float)*ndat); *med=nth(ndat,a,(float)(ndat-1)*0.5); for(i=0;i<ndat;i++) { a[i]=(float)fabs((double)(a[i]-(*med))); } *mad=nth(ndat,a,((float)(ndat-1)*0.5)); free(a); s=(*mad)/0.6745; t=(*med); c=6.0; /* is recommended in Numerical Recipes */ if(*mad<0.01) return t; for(n=0;n<niter;n++) { snumer=0.; sdenom=0.; for(i=0;i<ndat;i++) { u=(dat[i]-t)/(c*s); if(u<1.0 && u>-1.0) { snumer+=dat[i]*(1.0-u*u)*(1.0-u*u); sdenom+=(1.0-u*u)*(1.0-u*u); } } if(sdenom!=0) { t=(float)(snumer/sdenom); } else { c*=1.1; } } return t; }
void erase_range(Container& container, insertion_data<T> const& data) { auto count = data.indexes.size(); auto size = data.ordered.size() / count; while (count != 1) { --count; auto first = nth(container, data.indexes[count]); auto last = first + static_cast<std::ptrdiff_t>(size); container.erase(first, last); } container.erase(nth(container, 1), container.end()); }
bool isSigNumEntry (Tree s, Tree& lbl, Tree& cur, Tree& min, Tree& max, Tree& step) { Tree params; if (isTree(s, SIGNUMENTRY, lbl, params)) { cur = nth(params, 0); min = nth(params, 1); max = nth(params, 2); step= nth(params, 3); return true; } else { return false; } }
bool isSigVSlider (Tree s, Tree& lbl, Tree& cur, Tree& min, Tree& max, Tree& step) { Tree params; if (isTree(s, SIGVSLIDER, lbl, params)) { cur = nth(params, 0); min = nth(params, 1); max = nth(params, 2); step= nth(params, 3); return true; } else { return false; } }
void pcl::registration::CorrespondenceRejectorMedianDistance::getRemainingCorrespondences ( const pcl::Correspondences& original_correspondences, pcl::Correspondences& remaining_correspondences) { std::vector <double> dists; dists.resize (original_correspondences.size ()); for (size_t i = 0; i < original_correspondences.size (); ++i) { if (data_container_) dists[i] = data_container_->getCorrespondenceScore (original_correspondences[i]); else dists[i] = original_correspondences[i].distance; } std::vector <double> nth (dists); nth_element (nth.begin (), nth.begin () + (nth.size () / 2), nth.end ()); median_distance_ = nth [nth.size () / 2]; unsigned int number_valid_correspondences = 0; remaining_correspondences.resize (original_correspondences.size ()); for (size_t i = 0; i < original_correspondences.size (); ++i) if (dists[i] <= median_distance_ * factor_) remaining_correspondences[number_valid_correspondences++] = original_correspondences[i]; remaining_correspondences.resize (number_valid_correspondences); }
Tree lrange (Tree l, int i, int j) { Tree r = gGlobal->nil; int c = j; while (c>i) r = cons( nth(l,--c), r); return r; }
int _tmain2(int argc, _TCHAR* argv[]) { //#ifdef _DEBUG // _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);//退出时检测泄漏 //#endif stack<int> si; si.push(1); si.push(2); si.push(3); while (!si.empty()) cout << spop(si) << endl; vector<int> dest = { 3, 4, 99, 6, 7, 8, 9 }; Nth nth(3); // find_if (beg, end, unaryPred) ; // 操作前:[beg,end)标示输入序列.unaryPred操作符是一元函数对象. // 操作后:确定输入序列中是否存在使unaryPred返回true的元素. // 返回值:如果存在使unaryPred返回true的元素,返回指向第一个该元素位置的迭代器. // 否则返回end. // 备注: 如果使用二元函数对象,需使用绑定器将其转换为一元函数对象使用. vector<int>::iterator nthItr = find_if(dest.begin(), dest.end(), nth); //dest内容为连续数字:3,4,5,6,……,12 cout << "3rd:" << *nthItr << endl; cout << "State:" << nth.GetCount() << endl; //int *p = new int; system("pause"); //_CrtDumpMemoryLeaks(); return 0; }
/* When the name selected changes to currName gets its type and definition */ static local VOID SetName(HWND hDlg, UINT currName, List names) { Name nm = nth(currName,names); if (nonNull(name(nm).type)) printType(stdstr,name(nm).type); else fprintf(stdstr,"<Unknown type>"); fprintf(stdstr, "\n"); SendDlgItemMessage(hDlg, LB_NAMESTYPE ,LB_RESETCONTENT, 0, 0L); SendDlgItemMessage(hDlg, LB_NAMESTYPE ,LB_ADDSTRING, 0, (LONG)(LPSTR) stdstrbuff); if (isCfun(nm)) fprintf(stdstr,"Data constructor"); else if (isMfun(nm)) fprintf(stdstr, "Class member"); else if (isSfun(nm)) fprintf(stdstr, "Selector function"); else if (name(nm).primDef) fprintf(stdstr, "Primitive"); fprintf(stdstr, "\n"); SendDlgItemMessage(hDlg, LB_NAMESNOTES ,LB_RESETCONTENT, 0, 0L); SendDlgItemMessage(hDlg, LB_NAMESNOTES ,LB_ADDSTRING, 0, (LONG)(LPSTR) stdstrbuff); }
void Menu::on() { Lith::on(); if(on_flag) { stfocus((Widget *)nth(0)); grab(this,greedy); } }
// All quotations wants a stack frame, except if they contain: // 1) calls to the special subprimitives, see #295. // 2) mega cache lookups, see #651 bool quotation_jit::stack_frame_p() { cell length = array_capacity(elements.untagged()); for (cell i = 0; i < length; i++) { cell obj = nth(i); cell tag = TAG(obj); if ((tag == WORD_TYPE && special_subprimitive_p(obj)) || (tag == ARRAY_TYPE && mega_lookup_p(i, length))) return false; } return true; }
static any ins_element(any list, int pos, int value) { any temp, tab; int i; tab = temp = list; temp = cons(box(value), nCdr(pos - 1, temp)); for (i = pos - 1; i > 0; i--) { temp = cons(car(nth(i, tab)), temp); } return temp; }
boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateHoliday(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model) { //<Name>Thanksgiving Day</Name> //<SpecMthd>Fourth</SpecMthd> //<DayOfWeek>Thursday</DayOfWeek> //<Month>November</Month> //<Name>Christmas Day</Name> //<SpecMthd>Date</SpecMthd> //<Month>December</Month> //<Day>25</Day> boost::optional<openstudio::model::ModelObject> result; QDomElement nameElement = element.firstChildElement("Name"); QDomElement specificationMethodElement = element.firstChildElement("SpecMthd"); OS_ASSERT(!nameElement.isNull()); OS_ASSERT(!specificationMethodElement.isNull()); if (specificationMethodElement.text() == "Date"){ QDomElement monthElement = element.firstChildElement("Month"); QDomElement dayElement = element.firstChildElement("Day"); OS_ASSERT(!monthElement.isNull()); OS_ASSERT(!dayElement.isNull()); MonthOfYear monthOfYear(toString(monthElement.text())); unsigned day = dayElement.text().toUInt(); result = model::RunPeriodControlSpecialDays(monthOfYear, day, model); result->setName(escapeName(nameElement.text())); }else{ QDomElement dayOfWeekElement = element.firstChildElement("DayOfWeek"); QDomElement monthElement = element.firstChildElement("Month"); OS_ASSERT(!dayOfWeekElement.isNull()); OS_ASSERT(!monthElement.isNull()); // fifth is treated equivalently to last std::string specificationMethod = toString(specificationMethodElement.text()); if (specificationMethod == "Last"){ specificationMethod = "Fifth"; } NthDayOfWeekInMonth nth(specificationMethod); DayOfWeek dayOfWeek(toString(dayOfWeekElement.text())); MonthOfYear monthOfYear(toString(monthElement.text())); result = model::RunPeriodControlSpecialDays(nth, dayOfWeek, monthOfYear, model); result->setName(escapeName(nameElement.text())); } return result; }
void insert_range(Container& container, insertion_data<T> const& data) { auto count = data.indexes.size(); auto size = data.ordered.size() / count; reserve(container, count); auto first = data.ordered.data(); auto last = first; for (std::size_t i = 0; i != count; ++i) { last += size; container.insert(nth(container, data.indexes[i]), first, last); first += size; } }
template<> void BlockLocationList::print() { print_short(); lprintf(": length %ld (max %ld) { ", (void*)long(len), (void*)long(max)); for (fint i = 0; i < length(); i++) { BlockLocation bl = nth(i); if (bl.memoized) { lprintf("[%#lx] ", bl.loc); } else { lprintf("%#lx ", bl.loc); } } lprintf("}\n"); }
float floatMAD(int ndat,float *dat) { float med,mad; int i; float *a; if((a=(float*)malloc(sizeof(float)*ndat))==NULL) { fprintf(stderr,"Cannot allocate a in floatMAD, ndat=%d\n",ndat); exit(-1); } memcpy(a,dat,sizeof(float)*ndat); med=nth(ndat,a,(float)(ndat-1)*0.5); for(i=0;i<ndat;i++) { a[i]=(float)fabs(a[i]-med); } mad=nth(ndat,a,(float)(ndat-1)*0.5); free(a); return mad; }
void interntype(node t){ assert(t->tag == type_tag); if (numtypes >= typelistsize) { if (typelistsize == 0) { typelistsize = 800; typelist = newarray(node,typelistsize); } else { int newtypelistsize = 2 * typelistsize; node *newtypelist = newarray(node,newtypelistsize); int i; for (i=0; i<numtypes; i++) newtypelist[i] = typelist[i]; typelist = newtypelist; typelistsize = newtypelistsize; } } typelist[numtypes] = t; t->body.type.seqno = numtypes; numtypes++; if (isortype(t)) { int i, nonnulls = 0; node m; node commons = NULL; for (i=1; ; i++) { node common = NULL; for (m = typedeftail(t); m != NULL; m = CDR(m)) { node n, u = CAR(m); if (u == null_T) goto out; if (!(isobjecttype(u) || istaggedobjecttype(u))) goto out; n = typedeftail(u); if (i > length(n)) goto out; u = nth(n,i); if (common == NULL) common = u; else if (!equal(common,u)) { goto out; } } if (common == NULL) break; push(commons,common); } out: commons = reverse(commons); t->body.type.commons = commons; for (m = typedeftail(t); m != NULL; m = CDR(m)) { if (CAR(m) != null_T) nonnulls ++; } if (nonnulls >= 2) t->body.type.flags |= composite_F; } }
int Menu::umenurelease1(int key,int state,int x,int y,Time time,Widget *org) { /* printf("Menu release %d,%d greedy=%d\n",x,y,greedy); */ greedygrab(1); stfocus((Widget *)nth(0)); if(x>=0 && x<gtw() && y>=0 && y<gth()) { ev.type=ButtonPress; calcpointer(); doevent(gtmain(),&ev); calcpointer(); ev.type=ButtonRelease; doevent(gtmain(),&ev); } return 0; }
string DocCompiler::generateFFun(Tree sig, Tree ff, Tree largs, int priority) { string code = ffname(ff); code += '('; string sep = ""; for (int i = 0; i< ffarity(ff); i++) { code += sep; code += CS(nth(largs, i), priority); sep = ", "; } code += ')'; gGlobal->gDocNoticeFlagMap["foreignfun"] = true; return "\\mathrm{ff"+code+"}"; }
float floatmedian(int ndat,float *dat) { /*Caution !! This routine is not quick if ndat is small.*/ float *a,m; if((a=(float*)malloc(sizeof(float)*ndat))==NULL) { fprintf(stderr,"Cannot allocate a in floatmedian, ndat=%d\n",ndat); exit(-1); } memcpy(a,dat,sizeof(float)*ndat); m=nth(ndat,a,(float)(ndat-1)*0.5); free(a); return m; }
/** * Generate code for a group of mutually recursive definitions */ void DocCompiler::generateRec(Tree sig, Tree var, Tree le, int priority) { int N = len(le); vector<bool> used(N); vector<int> delay(N); vector<string> vname(N); vector<string> ctype(N); // prepare each element of a recursive definition for(int i = 0; i < N; i++) { Tree e = sigProj(i, sig); // recreate each recursive definition if(fOccMarkup.retrieve(e)) { // this projection is used used[i] = true; // cerr << "generateRec : used[" << i << "] = true" << endl; getTypedNames(getCertifiedSigType(e), "r", ctype[i], vname[i]); gDocNoticeFlagMap["recursigs"] = true; // cerr << "- r : generateRec setVectorNameProperty : \"" << vname[i] << "\"" << endl; setVectorNameProperty(e, vname[i]); delay[i] = fOccMarkup.retrieve(e)->getMaxDelay(); } else { // this projection is not used therefore // we should not generate code for it used[i] = false; // cerr << "generateRec : used[" << i << "] = false" << endl; } } // generate delayline for each element of a recursive definition for(int i = 0; i < N; i++) { if(used[i]) { generateDelayLine(ctype[i], vname[i], delay[i], CS(nth(le, i), priority)); } } }
/* varlookup -- lookup a variable in the current context */ extern List *varlookup(const char *name, Binding *bp) { Var *var; if (iscounting(name)) { Term *term = nth(varlookup("*", bp), strtol(name, NULL, 10)); if (term == NULL) return NULL; return mklist(term, NULL); } validatevar(name); for (; bp != NULL; bp = bp->next) if (streq(name, bp->name)) return bp->defn; var = dictget(vars, name); if (var == NULL) return NULL; return var->defn; }
double nth(int n, List *xs) { if (n <= 0) return first(xs); else return nth(n-1, rest(xs)); }
ostream& boxpp::print (ostream& fout) const { int i, id; double r; prim0 p0; prim1 p1; prim2 p2; prim3 p3; prim4 p4; prim5 p5; Tree t1, t2, t3, ff, label, cur, min, max, step, type, name, file, arg, body, fun, args, abstr, genv, vis, lenv, ldef, slot, ident, rules; const char* str; xtended* xt = (xtended*) getUserData(box); // primitive elements if (xt) fout << xt->name(); else if (isBoxInt(box, &i)) fout << i; else if (isBoxReal(box, &r)) fout << T(r); else if (isBoxCut(box)) fout << '!'; else if (isBoxWire(box)) fout << '_'; else if (isBoxIdent(box, &str)) fout << str; else if (isBoxPrim0(box, &p0)) fout << prim0name(p0); else if (isBoxPrim1(box, &p1)) fout << prim1name(p1); else if (isBoxPrim2(box, &p2)) fout << prim2name(p2); else if (isBoxPrim3(box, &p3)) fout << prim3name(p3); else if (isBoxPrim4(box, &p4)) fout << prim4name(p4); else if (isBoxPrim5(box, &p5)) fout << prim5name(p5); else if (isBoxAbstr(box,arg,body)) fout << "\\" << boxpp(arg) << ".(" << boxpp(body) << ")"; else if (isBoxAppl(box, fun, args)) fout << boxpp(fun) << boxpp(args) ; else if (isBoxWithLocalDef(box, body, ldef)) fout << boxpp(body) << " with { " << envpp(ldef) << " }"; // foreign elements else if (isBoxFFun(box, ff)) { fout << "ffunction(" << type2str(ffrestype(ff)); Tree namelist = nth(ffsignature(ff),1); char sep = ' '; for (int i = 0; i < gFloatSize; i++) { fout << sep << tree2str(nth(namelist,i)); sep = '|'; } sep = '('; for (int i = 0; i < ffarity(ff); i++) { fout << sep << type2str(ffargtype(ff, i)); sep = ','; } fout << ')'; fout << ',' << ffincfile(ff) << ',' << fflibfile(ff) << ')'; } else if (isBoxFConst(box, type, name, file)) fout << "fconstant(" << type2str(tree2int(type)) << ' ' << tree2str(name) << ", " << tree2str(file) << ')'; else if (isBoxFVar(box, type, name, file)) fout << "fvariable(" << type2str(tree2int(type)) << ' ' << tree2str(name) << ", " << tree2str(file) << ')'; // block diagram binary operator else if (isBoxSeq(box, t1, t2)) streambinop(fout, t1, " : ", t2, 1, priority); else if (isBoxSplit(box, t1, t2)) streambinop(fout, t1, "<:", t2, 1, priority); else if (isBoxMerge(box, t1, t2)) streambinop(fout, t1, ":>", t2, 1, priority); else if (isBoxPar(box, t1, t2)) streambinop(fout, t1,",",t2, 2, priority); else if (isBoxRec(box, t1, t2)) streambinop(fout, t1,"~",t2, 4, priority); // iterative block diagram construction else if (isBoxIPar(box, t1, t2, t3)) fout << "par(" << boxpp(t1) << ", " << boxpp(t2) << ") {" << boxpp(t3) << "}"; else if (isBoxISeq(box, t1, t2, t3)) fout << "seq(" << boxpp(t1) << ", " << boxpp(t2) << ") {" << boxpp(t3) << "}"; else if (isBoxISum(box, t1, t2, t3)) fout << "sum(" << boxpp(t1) << ", " << boxpp(t2) << ") {" << boxpp(t3) << "}"; else if (isBoxIProd(box, t1, t2, t3)) fout << "prod(" << boxpp(t1) << ", " << boxpp(t2) << ") {" << boxpp(t3) << "}"; else if (isBoxInputs(box, t1)) fout << "inputs(" << boxpp(t1) << ")"; else if (isBoxOutputs(box, t1)) fout << "outputs(" << boxpp(t1) << ")"; // user interface else if (isBoxButton(box, label)) fout << "button(" << tree2quotedstr(label) << ')'; else if (isBoxCheckbox(box, label)) fout << "checkbox(" << tree2quotedstr(label) << ')'; else if (isBoxVSlider(box, label, cur, min, max, step)) { fout << "vslider(" << tree2quotedstr(label) << ", " << boxpp(cur) << ", " << boxpp(min) << ", " << boxpp(max) << ", " << boxpp(step)<< ')'; } else if (isBoxHSlider(box, label, cur, min, max, step)) { fout << "hslider(" << tree2quotedstr(label) << ", " << boxpp(cur) << ", " << boxpp(min) << ", " << boxpp(max) << ", " << boxpp(step)<< ')'; } else if (isBoxVGroup(box, label, t1)) { fout << "vgroup(" << tree2quotedstr(label) << ", " << boxpp(t1, 0) << ')'; } else if (isBoxHGroup(box, label, t1)) { fout << "hgroup(" << tree2quotedstr(label) << ", " << boxpp(t1, 0) << ')'; } else if (isBoxTGroup(box, label, t1)) { fout << "tgroup(" << tree2quotedstr(label) << ", " << boxpp(t1, 0) << ')'; } else if (isBoxHBargraph(box, label, min, max)) { fout << "hbargraph(" << tree2quotedstr(label) << ", " << boxpp(min) << ", " << boxpp(max) << ')'; } else if (isBoxVBargraph(box, label, min, max)) { fout << "vbargraph(" << tree2quotedstr(label) << ", " << boxpp(min) << ", " << boxpp(max) << ')'; } else if (isBoxNumEntry(box, label, cur, min, max, step)) { fout << "nentry(" << tree2quotedstr(label) << ", " << boxpp(cur) << ", " << boxpp(min) << ", " << boxpp(max) << ", " << boxpp(step)<< ')'; } else if (isNil(box)) { fout << "()" ; } else if (isList(box)) { Tree l = box; char sep = '('; do { fout << sep << boxpp(hd(l)); sep = ','; l = tl(l); } while (isList(l)); fout << ')'; } else if (isBoxWaveform(box)) { fout << "waveform"; char sep = '{'; for (int i=0; i<box->arity(); i++) { fout << sep << boxpp(box->branch(i)); sep = ','; } fout << '}'; /* size_t n = box->arity(); if (n < 6) { // small waveform, print all data fout << "waveform"; char sep = '{'; for (size_t i=0; i<n; i++) { fout << sep << boxpp(box->branch(i)); sep = ','; } fout << '}'; } else { // large waveform print only first and last values fout << "waveform{" << box->branch(0) << ", ..<" << n-2 << ">..," << box->branch(n-1) << "}"; } */ } else if (isBoxEnvironment(box)) { fout << "environment"; } else if (isClosure(box, abstr, genv, vis, lenv)) { fout << "closure[" << boxpp(abstr) << ", genv = " << envpp(genv) << ", lenv = " << envpp(lenv) << "]"; } else if (isBoxComponent(box, label)) { fout << "component(" << tree2quotedstr(label) << ')'; } else if (isBoxAccess(box, t1, t2)) { fout << boxpp(t1) << '.' << boxpp(t2); } else if (isImportFile(box, label)) { fout << "import(" << tree2quotedstr(label) << ')'; } else if (isBoxSlot(box, &id)) { //fout << "#" << id; fout << "x" << id; } else if (isBoxSymbolic(box, slot, body)) { fout << "\\(" << boxpp(slot) << ").(" << boxpp(body) << ")"; } // Pattern Matching Extensions else if (isBoxCase(box, rules)) { fout << "case {"; while (!isNil(rules)) { printRule(fout, hd(rules)); rules = tl(rules); } fout << "}"; } #if 1 // more useful for debugging output else if (isBoxPatternVar(box, ident)) { fout << "<" << boxpp(ident) << ">"; } #else // beautify messages involving lhs patterns else if (isBoxPatternVar(box, ident)) { fout << boxpp(ident); } #endif else if (isBoxPatternMatcher(box)) { fout << "PM[" << box << "]"; } else if (isBoxError(box)) { fout << "ERROR"; } //else if (isImportFile(box, filename)) { // printf("filename %s\n", tree2str(filename)); // fout << tree2quotedstr(filename); //} // None of the previous tests succeded, then it is not a valid box else { cerr << "Error in box::print() : " << *box << " is not a valid box" << endl; exit(1); } return fout; }
void totypesRec(node e) { int i, j; /* e is a list of TYPEs to be defined recursively The recursion is handled through the type fields of the symbols involved, which are assumed to be already set, or through TYPEs. TYPEs have no POSITIONs in them. Any type which turns out to be equivalent to a prior one has the address of the prior one inserted into its value field. We assume that the value fields have been run through ExpandType, so that each value field is an expression constructed from other TYPEs. This routine probably has bugs, with the result that the order of declarations makes a difference. */ numnewtypes = length(e); newtypeslist = newarray(node,numnewtypes); ttable = newarray(struct DISTIN *, numnewtypes); /* we could perform some hashing first */ for (i=0; i<numnewtypes; i++) { node t = nth(e,i+1); assert(istype(t)); newtypeslist[i] = t; assert(t->tag == type_tag); assert(!(t->body.type.flags & deferred_F)); t->body.type.seqno = i + numtypes; ttable[i] = newarray(struct DISTIN,numtypes+numnewtypes); for (j=0; j<numtypes+numnewtypes; j++) { ttable[i][j].listp = NULL; ttable[i][j].distinguishable = FALSE; } } for (i=numtypes; i<numnewtypes+numtypes; i++) { for (j=0; j<i; j++) { struct DISTIN *dd = table(i,j); node t = thetype(i), u = thetype(j), tval, uval, th, uh; assertpos(istype(t),t); assertpos(istype(u),u); if ((t->body.type.flags & basic_type_F) || (u->body.type.flags & basic_type_F)) { assert(t != u); differ: mark(i,j); continue; } tval = t -> body.type.definition; uval = u -> body.type.definition; assertpos(tval != NULL,t); assertpos(uval != NULL,u); if (equal(tval,uval)) continue; assertpos(iscons(tval),t); assertpos(iscons(uval),u); assert(! dd->distinguishable ); th = car(tval); uh = car(uval); tval = cdr(tval); uval = cdr(uval); if (th != uh) goto differ; if (th == or_K) { for (;tval != NULL && uval != NULL; tval = cdr(tval), uval = cdr(uval)) { node ti = typeforward(car(tval)); node tj = typeforward(car(uval)); int ii = typeseqno(ti); int jj = typeseqno(tj); if (ti == tj) continue; if (ii == -1 || jj == -1) goto differ; /* not defined yet... */ if (distinguishable(ii,jj)) goto differ; appendlt(ii,jj,i,j); } if (tval != NULL || uval != NULL) goto differ; } else if (th == object__K || th == tagged_object_K) { for (;tval != NULL && uval != NULL; tval = cdr(tval), uval = cdr(uval)) { node tmem = car(tval); node umem = car(uval); int ii, jj; node tt, uu; if (car(tmem) != car(umem)) goto differ; ii = typeseqno(tt=typeforward(cadr(tmem))); jj = typeseqno(uu=typeforward(cadr(umem))); if (tt==uu) continue; if (ii == -1 || jj == -1) goto differ; /* not defined yet... */ if (distinguishable(ii,jj)) goto differ; appendlt(ii,jj,i,j); } if (tval != NULL || uval != NULL) goto differ; } else if (th == array_K || th == tarray_K) { node tt,uu; int ii = typeseqno(tt=typeforward(car(tval))); int jj = typeseqno(uu=typeforward(car(uval))); if (tt!=uu) { if (ii == -1 || jj == -1) goto differ; /* not defined yet... */ else if (distinguishable(ii,jj)) goto differ; else if (!equal(cdr(tval),cdr(uval))) goto differ; else appendlt(ii,jj,i,j); } else { if (!equal(cdr(tval),cdr(uval))) goto differ; } } else if (th == function_S) { node ttt,uuu; node targs = car(tval); node uargs = car(uval); int iii = typeseqno(ttt=typeforward(cadr(tval))); int jjj = typeseqno(uuu=typeforward(cadr(uval))); if (ttt!=uuu) { if (iii == -1 || jjj == -1) goto differ; /* not defined yet... */ if (distinguishable(iii,jjj)) goto differ; } for (;targs != NULL && uargs != NULL; targs = cdr(targs), uargs = cdr(uargs)) { node tt,uu; int ii = typeseqno(tt=typeforward(car(targs))); int jj = typeseqno(uu=typeforward(car(uargs))); if (tt==uu) continue; if (ii == -1 || jj == -1) goto differ; /* not defined yet... */ if (distinguishable(ii,jj)) goto differ; } if (targs != NULL || uargs != NULL) goto differ; } else { assert(FALSE); return; } } } for (i=0; i<numnewtypes; i++) { for (j=0;j<i+numtypes;j++) { if (!distinguishable(i+numtypes,j)) { /* indistinguishable types are identified here */ node t = newtypeslist[i]; node n = t->body.type.name; if (n != NULL) { assert(n->tag == symbol_tag); n->body.symbol.value = thetype(j); } t->body.type.forward = thetype(j); t->body.type.flags = identified_F; newtypeslist[i] = NULL; break; } } } for (i=0; i<numnewtypes; i++) { if (newtypeslist[i] != NULL) { node t = newtypeslist[i]; interntype(t); } } }
flowgraph::iterator flowgraph::iterator::succ( unsigned int i ) const { return nth( n -> succ, i ); }
flowgraph::const_iterator flowgraph::const_iterator::pred( unsigned int i ) const { return nth( n -> pred, i ); }
int main(int argc, char **argv) { struct lnode *head = BuildOneTwoThree(); int i = nth(head, 2); printf("%d\n", i); }
int main(int argc, char *argv[]) { List *lista = init(); double fat_array[] = {58, 25, 89, 11, 71, 3, 38, 49, 4, 16, 13, 13, 97, 80, 37, 92, 17, 88, 77, 80, 21, 70, 81, 2}; printf("Making a new list of a long array.\n"); lista = cons_array(fat_array, (int) (sizeof(fat_array)/sizeof(double))); printf("first: %f\n", first(ref(lista))); printf("second: %f\n", first(rest(ref(lista)))); printf("third: %f\n", first(rest(rest(ref(lista))))); printf("nth 4: %f\n", nth(4, ref(lista))); printf("length: %i\n", length(ref(lista))); printf("Clearing the list by dereffing it.\n\n"); deref(&lista); printf("Creating a new list by means of variable number of arguments (!)\n"); lista = list(3, 3.14159, 1.618, 1.414213); printf("length: %i\n", length(ref(lista))); printf("[%f, %f, %f]\n\n", nth(0, ref(lista)), nth(1, ref(lista)), nth(2, ref(lista))); deref(&lista); printf("New list!! (consing lol.)\n"); lista = cons(1, cons(2, cons(3, cons(4, cons(5, lista))))); printf("[%f, %f, %f, %f, %f]\n", nth(0, ref(lista)), nth(1, ref(lista)), nth(2, ref(lista)), nth(3, ref(lista)), nth(4, ref(lista))); printf("Mapping x^2 over lista...\n"); map(square, lista); printf("[%f, %f, %f, %f, %f]\n\n", nth(0, ref(lista)), nth(1, ref(lista)), nth(2, ref(lista)), nth(3, ref(lista)), nth(4, ref(lista))); lista = reverse(lista); printf("List reversed!\n"); printf("[%f, %f, %f, %f, %f]\n\n", nth(0, ref(lista)), nth(1, ref(lista)), nth(2, ref(lista)), nth(3, ref(lista)), nth(4, ref(lista))); lista = take(4, lista); printf("Taking 4: [%f, %f, %f, %f]\n", nth(0, ref(lista)), nth(1, ref(lista)), nth(2, ref(lista)), nth(3, ref(lista))); lista = drop(2, lista); printf("Dropping 2: [%f, %f]\n\n", nth(0, ref(lista)), nth(1, ref(lista))); deref(&lista); printf("Ny lång lista igen, från samma array!!\n"); lista = cons_array(fat_array, (int) (sizeof(fat_array)/sizeof(double))); printf("Filtrerar ut element lägre än 50.\n"); lista = filter(lessthanfifty, lista); printf("first: %f\n", first(ref(lista))); printf("second: %f\n", first(rest(ref(lista)))); printf("third: %f\n", first(rest(rest(ref(lista))))); printf("nth 4: %f\n", nth(4, ref(lista))); printf("length: %i\n\n", length(ref(lista))); deref(&lista); printf("Address for dereffed lista: %X\n", (unsigned int) lista); return 0; }