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
3939 if
4040 lambda
4141 list
42−mac
4342 newline
4443 not
4544 or
@@ -62,6 +61,15 @@ string? · 16 unmodified lines
6261
6362 `= < > <= >= + - * /`
6463
64+## Things that need work/testing or not implemented at all
65+
66+```
67+let
68+mac
69+setcar
70+setcdr
71+```
72+
6573 ### Math (optional, see `aa_math.*`)
6674
6775 ```
aa.c+8−10
@@ -308,15 +308,12 @@ equal(aaObject *a, aaObject *b) · 307 unmodified lines
308308 return a == b;
309309 }
310310
311− if(TYPE(a) == AA_TPAIR){
312− for(; !ISNULL(a); a = CDR(a), b = CDR(b)){
313− if(!equal(CAR(a), CAR(b)))
314− return 0;
315− }
316− return a == b;
311+ for(; TYPE(a) == AA_TPAIR && TYPE(b) == AA_TPAIR && !ISNULL(a) && !ISNULL(b) && a != b; a = CDR(a), b = CDR(b)){
312+ if(!equal(CAR(a), CAR(b)))
313+ return 0;
317314 }
318315
319− return 0;
316+ return a == b;
320317 }
321318
322319 static int
@@ -512,15 +509,15 @@ objfmt(Fmt *f) · 189 unmodified lines
512509
513510 case AA_TPAIR:
514511 fmtrune(f, '(');
515− for(;;){
512+ do{
516513 fmtprint(f, "%§", CAR(obj));
517514 obj = CDR(obj);
518515 if(ISNULL(obj))
519516 break;
520517 fmtrune(f, ' ');
521− }
518+ }while(TYPE(obj) == AA_TPAIR);
522519 if(!ISNULL(obj))
523− fmtprint(f, " . %§", obj);
520+ fmtprint(f, ". %§", obj);
524521 fmtrune(f, ')');
525522 break;
526523
@@ -853,6 +850,7 @@ eval(aaContext *ctx, aaObject *obj, aaObject *env, aaObject **newenv) · 326 unmodified lines
853850 case P_CONS:
854851 va = evalarg();
855852 res = aa_cons(ctx, va, evalarg());
853+ noargs();
856854 break;
857855
858856 case P_CAR:
test.scm+5−0
@@ -57,3 +57,8 @@ · 56 unmodified lines
5757 (test '(not "lol") #f)
5858 (test '(not #t) #f)
5959 (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