/* * This is an implementation of the basics of what would later become LISP * as described in the first AI memo by John McCarthy in 1958: * http://www.softwarepreservation.org/projects/LISP/MIT/AIM-001.pdf/view * * Since the paper leaves open many details (e.g. how symbols should work) * one cannot implement a complete language from its description. * Furthermore the language at this stage is lacking a type system: * there is no way of knowing whether a particular datum (esp. the address * part of a word) represents a plain number or an address of another word. * The description of the diff function seems to suggest that the distinction * would have been handled by the user functions operating on a list structure * and that the tag part would have been used as a type indicator typically. * This, however, makes general print and read functions impossible. * The read function McCarthy mentions has a format argument but it is not * further explained. A print function is not mentioned at all. * Some of the problems were perhaps addressed in the second AI memo, * of which only the first page survives (http://www.softwarepreservation.org/ * projects/LISP/MIT/AIM-2-page_1_from_Stoyan.pdf, the whereabouts of the * rest are not known). * The language as described in AI memo 3 is already quite different * from the earlier languages and is of little help clarifying the uncertain * points. * * Note that main() does nothing useful, it only contains some tests I did. * * Lastly, the peculiar C-style used is that of Tom Duff. */ #include #include #include typedef uint64_t word; #define FREE 0 /* free storage list */ word memory[1<<15]; word bit(word w, word n){ return w >> 35-n & 1; } word seg(word w, word m, word n){ return w >> 35-n & ~0+(1UL<0;n--) erase(n); } void printlis(word j){ if(j==0) return; putchar('('); for(;j;j=cdr(j)){ if(cir(j)==0) printf("%lo", car(j)); else if(cir(j)==1) printf("[%lo]", cwr(car(j))); else printlis(car(j)); if(cdr(j)) printf(", "); } putchar(')'); } void dumpmem(void){ int n; printf("mem:\n"); for(n=0;n < 1<<15;n++) printf("%lo\n", cwr(n)); } /* only some stupid tests */ int main(){ word x, y, l; printf("%lo %lo %lo %lo %lo %lo\n", pre(0700000000000), ind(0300000000000), sgn(0400000000000), dec(0012345000000), tag(0000000700000), add(0000000012345)); printf("%lo\n", comb4(07, 012345, 07, 054321)); printf("%lo\n", comb5(1, 3, 012345, 07, 054321)); printf("%lo\n", choice(0777777000000, 0333333754321, 0712345333333)); stwr(10, 0777777777777); printf("0: %lo\n", cwr(10)); stpr(10, 0); printf("1: %lo\n", cwr(10)); star(10, 012345); printf("2: %lo\n", cwr(10)); stdr(10, 054321); printf("3: %lo\n", cwr(10)); stsr(10, 1); printf("4: %lo\n", cwr(10)); initfree(); // dumpmem(); x=consw(01234); printf("%lo %lo\n", cwr(x), cwr(FREE)); y=consel(01234, 04321); printf("%lo\n", cwr(y)); l=consfl(01234, consls(consel(1, consel(2, 0)), consel(0333, 0))); printlis(l); putchar('\n'); eralis(l); printlis(listn(4, 1, 2, 3, 4)); putchar('\n'); return 0; }