list as an argument

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.

list as an argument

Postby omarasl » Sat Dec 01, 2012 7:20 am

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))
(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
Posts: 12
Joined: Sun Nov 25, 2012 6:19 am

Re: list as an argument

Postby Goheeca » Sat Dec 01, 2012 7:57 am

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.
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.
User avatar
Posts: 271
Joined: Thu May 10, 2012 12:54 pm

Re: list as an argument

Postby omarasl » Sat Dec 01, 2012 9:33 am

thank you very much
Actually , I have found very nice and helpful persons here thank you a lot
Posts: 12
Joined: Sun Nov 25, 2012 6:19 am

Return to Homework

Who is online

Users browsing this forum: No registered users and 1 guest