diff options
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | lib.c | 28 | ||||
-rw-r--r-- | lib.h | 2 | ||||
-rw-r--r-- | tests/012/ashwin.expected | 0 | ||||
-rw-r--r-- | tests/012/ashwin.tl | 8 | ||||
-rw-r--r-- | txr.1 | 35 |
6 files changed, 63 insertions, 12 deletions
@@ -6813,8 +6813,10 @@ void eval_init(void) reg_fun(intern(lit("assoc"), user_package), func_n2(assoc)); reg_fun(intern(lit("assql"), user_package), func_n2(assql)); + reg_fun(intern(lit("assq"), user_package), func_n2(assq)); reg_fun(intern(lit("rassoc"), user_package), func_n2(rassoc)); reg_fun(intern(lit("rassql"), user_package), func_n2(rassql)); + reg_fun(intern(lit("rassq"), user_package), func_n2(rassq)); reg_fun(intern(lit("acons"), user_package), func_n3(acons)); reg_fun(intern(lit("acons-new"), user_package), func_n3(acons_new)); reg_fun(intern(lit("aconsql-new"), user_package), func_n3(aconsql_new)); @@ -8178,6 +8178,20 @@ val assql(val key, val list) return nil; } +val assq(val key, val list) +{ + list = nullify(list); + + while (list) { + val elem = car(list); + if (eq(car(elem), key)) + return elem; + list = cdr(list); + } + + return nil; +} + val rassoc(val key, val list) { list = nullify(list); @@ -8206,6 +8220,20 @@ val rassql(val key, val list) return nil; } +val rassq(val key, val list) +{ + list = nullify(list); + + while (list) { + val elem = car(list); + if (eq(cdr(elem), key)) + return elem; + list = cdr(list); + } + + return nil; +} + val acons(val car, val cdr, val list) { return cons(cons(car, cdr), list); @@ -1066,8 +1066,10 @@ mem_t *cptr_handle(val cobj, val type_sym, val self); mem_t **cptr_addr_of(val cptr, val type_sym, val self); val assoc(val key, val list); val assql(val key, val list); +val assq(val key, val list); val rassoc(val key, val list); val rassql(val key, val list); +val rassq(val key, val list); val acons(val car, val cdr, val list); val acons_new(val key, val value, val list); val acons_new_c(val key, loc new_p, loc list); diff --git a/tests/012/ashwin.expected b/tests/012/ashwin.expected new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/012/ashwin.expected diff --git a/tests/012/ashwin.tl b/tests/012/ashwin.tl new file mode 100644 index 00000000..66226f2c --- /dev/null +++ b/tests/012/ashwin.tl @@ -0,0 +1,8 @@ +(load "../common") + +(defvarl a-list '((a . 42) (b . 73))) +(defvarl key 'a) + +(test (cdr (assq key a-list)) 42) +(test (cdr (assq 'b a-list)) 73) +(test (cdr (assq 'c a-list)) nil) @@ -20394,28 +20394,35 @@ The first such cons is returned. If no such cons is found, .code nil is returned. -.coNP Function @ assql +.coNP Functions @ assq and @ assql .synb +.mets (assq < key << alist ) .mets (assql < key << alist ) .syne .desc The +.code assq +and .code assql -function is just like +functions are very similar to .codn assoc , -except that the equality test -is determined using the +with the only difference being that they determine equality using, +respectively, the +.code eq +and .code eql -function rather than +functions rather than .codn equal . -.coNP Functions @ rassql and @ rassoc +.coNP Functions @, rassq @ rassql and @ rassoc .synb +.mets (rassq < value << alist ) .mets (rassql < value << alist ) .mets (rassoc < value << alist ) .syne .desc The +.codn rassq , .code rassql and .code rassoc @@ -20432,7 +20439,7 @@ rather than the field. The -.code rassql +.code rassoc function searches association list .meta alist for a cons whose @@ -20440,18 +20447,22 @@ for a cons whose field equivalent to .meta value according to the -.code eql +.code equal function. If such a cons is found, it is returned. Otherwise .code nil is returned. The -.code rassoc -function searches in the same way as +.code rassq +and .code rassql -but compares values using -.codn equal . +functions search in the same way as +.code rassoc +but compares values using, respectively, +.code eq +and +.codn eql . .coNP Function @ acons .synb |