0
votes

I want to make user-program which extract elements a which have element b (given by parameter) as pair in list.

Like, if I give c as parameter and list ((c a) (c b) (d f) (d g)), result should be 'a' 'b';

So I define a function as below,

(defun myr (b a) (if (= CAAR(a) b) CDAR(a) 'nope myr(b CDR(a))));

and call like this

myr(b ((b a) (b c) (a d) (a f)))

But result is like variable myr has no value

Its my first time in Lisp, So just tell me what keyword should I search for will be great help for me.

Thank you for reading.

1

1 Answers

6
votes

You really need to start with a good lisp book, e.g., PCL or ACL. You will save yourself a lot of time.

Lisp syntax is different from C. In C, you call a function f with arguments х and y like this: f(x,y). In Lisp, you do it like this: (f x y).

When you invoke your function myr(...), you put the symbol myr in the variable position, not function position, which causes the error you reported.

You also need to use quote as appropriate.