I wrote a code to reverse a list and all its sublists recursively :
(defun rev1( list final )
( if ( eq list () )
final
( if ( atom ( car list ) )
( rev1( cdr list ) ( cons ( car list ) final ) )
( rev1( cdr list ) ( cons ( rev1( car list ) () ) final ) ))))
(defun rev(list)
( rev1 list () ) )
The problem is that if I call the function with : ( rev '( 1 2 '( 3 2 1 ) 3 ) )
the expected output should be (3 (1 2 3) 2 1)
but instead of this what I get is : (3 ((1 2 3) QUOTE) 2 1)
and I do not understand why. Could anyone explain me where's the problem?
The
'
character is a reader macro, i.e. the Lisp reader will expand it into a call toquote
. The CLHS entry onquote
gives the following evaluation examples:Hence: