This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Problem in executing the code

6 posts · 6088 views

Hello Friends, Now I got some idea about Functions but I am not able to understand about macro's. For example here is a code:
(defmacro reverse-list ( list )
    `(if (atom ,@list)
        ,@list 
      (reverse (mapcar #'reverse-list ,@list))))


`(reverse-list (list(1 2 3 4 5)))
I am not getting answer for this, what goes wrong here??, some one help me to sort out..

Re: Problem in executing the code

Pro tip—you have no hope of understanding your own macros without MACROEXPAND-1. Try expanding the call form:
? (macroexpand-1 `(reverse-list (list(1 2 3 4 5))))
(IF (ATOM LIST (1 2 3 4 5))
    LIST
    (1 2 3 4 5)
    (REVERSE (MAPCAR #'REVERSE-LIST LIST (1 2 3 4 5))))
Comma-at-sign is the splicing operator, so the list being spliced loses its identity and gets absorbed into the outer form.

Re: Problem in executing the code

Yes, as you said, I am very much new to this language, so kindly help me with some tutorials where I can find function example and corresponding macro

Re: Problem in executing the code

i think, you should read books. there are some good ones online for free (like the ones Paul Graham wrote). (the only lang i learnt this way)
But if you understand the basics it should often be enough to read the entrys for the operations in common lisp hyperspec, there also are many examples.

Re: Problem in executing the code

Thank You for your suggestion. 'll go through it.