History

fix cons; test car/cdr/cons

Sigrid Haflínudóttir committed 6 years ago

Commit b1908281 parent 8fe89503 files · +22 −11Browse files

Unified · Split

3 files
  1. README.md +9 −1
  2. aa.c +8 −10
  3. test.scm +5 −0
README.md+9−1
@@ -39,7 +39,6 @@ eval · 38 unmodified lines
39if39if
40lambda40lambda
41list41list
42mac
43newline42newline
44not43not
45or44or
@@ -62,6 +61,15 @@ string? · 16 unmodified lines
62 61
63`= < > <= >= + - * /`62`= < > <= >= + - * /`
64 63
64## Things that need work/testing or not implemented at all
65
66```
67let
68mac
69setcar
70setcdr
71```
72
65### Math (optional, see `aa_math.*`)73### Math (optional, see `aa_math.*`)
66 74
67```75```
aa.c+8−10
@@ -308,15 +308,12 @@ equal(aaObject *a, aaObject *b) · 307 unmodified lines
308 return a == b;308 return a == b;
309 }309 }
310 310
311 if(TYPE(a) == AA_TPAIR){311 for(; TYPE(a) == AA_TPAIR && TYPE(b) == AA_TPAIR && !ISNULL(a) && !ISNULL(b) && a != b; a = CDR(a), b = CDR(b)){
312 for(; !ISNULL(a); a = CDR(a), b = CDR(b)){312 if(!equal(CAR(a), CAR(b)))
313 if(!equal(CAR(a), CAR(b)))313 return 0;
314 return 0;
315 }
316 return a == b;
317 }314 }
318 315
319 return 0;316 return a == b;
320}317}
321 318
322static int319static int
@@ -512,15 +509,15 @@ objfmt(Fmt *f) · 189 unmodified lines
512 509
513 case AA_TPAIR:510 case AA_TPAIR:
514 fmtrune(f, '(');511 fmtrune(f, '(');
515 for(;;){512 do{
516 fmtprint(f, "%§", CAR(obj));513 fmtprint(f, "%§", CAR(obj));
517 obj = CDR(obj);514 obj = CDR(obj);
518 if(ISNULL(obj))515 if(ISNULL(obj))
519 break;516 break;
520 fmtrune(f, ' ');517 fmtrune(f, ' ');
521 }518 }while(TYPE(obj) == AA_TPAIR);
522 if(!ISNULL(obj))519 if(!ISNULL(obj))
523 fmtprint(f, " . %§", obj);520 fmtprint(f, ". %§", obj);
524 fmtrune(f, ')');521 fmtrune(f, ')');
525 break;522 break;
526 523
@@ -853,6 +850,7 @@ eval(aaContext *ctx, aaObject *obj, aaObject *env, aaObject **newenv) · 326 unmodified lines
853 case P_CONS:850 case P_CONS:
854 va = evalarg();851 va = evalarg();
855 res = aa_cons(ctx, va, evalarg());852 res = aa_cons(ctx, va, evalarg());
853 noargs();
856 break;854 break;
857 855
858 case P_CAR:856 case P_CAR:
test.scm+5−0
@@ -57,3 +57,8 @@ · 56 unmodified lines
57(test '(not "lol") #f)57(test '(not "lol") #f)
58(test '(not #t) #f)58(test '(not #t) #f)
59(test '(not #f) #t)59(test '(not #f) #t)
60
61(test '(car (cons 1 2)) 1)
62(test '(cdr (cons 1 2)) 2)
63(test '(car (cons 3 (list 1 2))) 3)
64(test '(cdr (cons 3 (list 1 2))) (list 1 2))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t