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.

list as an argument

3 posts · 4183 views

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

(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.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Re: list as an argument

thank you very much
Actually , I have found very nice and helpful persons here thank you a lot