Discussion of Common Lisp
-
vignezds
- Posts: 7
- Joined: Tue Nov 18, 2014 4:26 am
Post
by vignezds » Tue Nov 25, 2014 4:29 am
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:
Code: Select all
(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..
-
logxor
- Posts: 20
- Joined: Tue May 27, 2014 10:56 am
- Location: Portland, OR
Post
by logxor » Tue Nov 25, 2014 2:15 pm
Pro tip—you have no hope of understanding your own macros without MACROEXPAND-1. Try expanding the call form:
Code: Select all
? (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.
-
vignezds
- Posts: 7
- Joined: Tue Nov 18, 2014 4:26 am
Post
by vignezds » Tue Nov 25, 2014 2:33 pm
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
-
porky11
- Posts: 25
- Joined: Fri May 02, 2014 6:46 am
Post
by porky11 » Tue Nov 25, 2014 4:19 pm
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.
-
logxor
- Posts: 20
- Joined: Tue May 27, 2014 10:56 am
- Location: Portland, OR
Post
by logxor » Tue Nov 25, 2014 8:03 pm
-
vignezds
- Posts: 7
- Joined: Tue Nov 18, 2014 4:26 am
Post
by vignezds » Wed Nov 26, 2014 10:20 am
Thank You for your suggestion. 'll go through it.