Page 1 of 1

list as an argument

Posted: Sat Dec 01, 2012 7:20 am
by omarasl
hello everybody I know this is simple question but please help me because I am very beginner .
my question is how to use a list as an argument in my functions .
for example when I found this function to insert an element in sorted list :
(defun sorted-list-insert (L E)
"Insert element E into a sorted list L to produce a new sorted list."
(if (null L)
(list E)
(if (> E (first L))
(cons (first L) (sorted-list-insert (rest L) E))
(if (= E (first L))
L
(cons E L)))))

how I can use the list (1 2 4 ) and the element 3
because when I tried to apply this function in this way
sorted-list-insert ((1 2 4) 3) I had this error (1 2 4) is not a function name try using symbol instead .
then I called it as :
(setq `x (1 2 4))
(sorted-list-insert (x 3)) I have undefined function x
please help me to do that
thanks

Re: list as an argument

Posted: Sat Dec 01, 2012 7:57 am
by Goheeca

Code: Select all

(sorted-list-insert '(1 2 4) 3)
Everything what is wrapped in parentheses is treated as a function/macro call or an application of operator. You have quote macro at disposal which returns what it gets and the apostroph is syntactic sugar (a standard reader macro) for the quote macro.

Re: list as an argument

Posted: Sat Dec 01, 2012 9:33 am
by omarasl
thank you very much
Actually , I have found very nice and helpful persons here thank you a lot