Page 1 of 1

assoc-if bug?

PostPosted: Fri Nov 01, 2019 10:36 pm
by dbane
I'm using OpenLisp 10.7.0. On macOS Catalina if that's relevant.

This works as expected:

Code: Select all
? (assoc 'b '((a . 1) (b . 2) (c . 3)))
;; elapsed time =  0.0000s, (0 gc).
= (b . 2)
?


However, this doesn't:

Code: Select all
? (assoc-if (lambda (key) (string= key "b")) '(("a" . 1) ("b" . 2) ("c" . 3)))
** <domain-error> : function 'string=' requires a <string> received 1.
?


Is the bug on my side or in OpenLisp?

Re: assoc-if bug?

PostPosted: Fri Nov 01, 2019 11:20 pm
by dbane
Just FYI, this is the behaviour I expected from reading the Reference Manual:

Code: Select all
(defun my-assoc-if (fn a-list)
  (if (null a-list)
    nil
    (let ((kv (car a-list)))
      (if (funcall fn (car kv))
        kv
        (my-assoc-if fn (cdr a-list))))))