3
Suppose they were defined:
(defun xxx (x) (+ 1 x)) (setf xxx 5)
What is the value of the following expressions?
- (xxx 2)
- (xxx (+ (xxx 5) 3))
- (+ 4 xxx)
- (xxx xxx)
3
Suppose they were defined:
(defun xxx (x) (+ 1 x)) (setf xxx 5)
What is the value of the following expressions?
4
That defines from here xxx
as a function that adds 1 to xxx
:
(defun xxx (x) (+ 1 x))
That defines from here xxx
as having the value 5:
(setf xxx 5)
LISP keeps values and functions separate. That is, you have a variable xxx
with the value 5 and a function xxx
adding up to one more.
When you do that:
(print (xxx 2))
You are calling the function xxx
and passing it 2 as parameter. The result is 3.
Thereby:
(print (xxx (+ (xxx 5) 3)))
You are calling the function xxx
and passing it 5 as parameter, resulting in 6. Then sum 3, which gives 9. Calls the function xxx
again passing the 9, and gives 10.
Already in that:
(print (+ 4 xxx))
The xxx
is number 5. Adding with 4 is 9.
Finally, this:
(print (xxx xxx))
You call the function xxx
with the value of xxx
(which is 5). Therefore, this results in 6.
Thank you very much. Gave to understand well with your answer, helped quite . Grateful!
Until I learned now, @Gustavoaryel mark how you accept the answer.
Browser other questions tagged lisp
You are not signed in. Login or sign up in order to post.
Why don’t you test this on a Isps interpreter and see the answer? Or do you want an explanation of the answer given?
– Victor Stafusa
Tip, when testing, use
(print (xxx 2))
, for example.– Victor Stafusa
I’m learning LISP on my own and I’m not understanding very well I would like to understand even if it was with 1 example only the rest I turn around !
– Gustavo Aryel
Check this site: http://rextester.com/l/common_lisp_online_compiler
– Victor Stafusa
It worked in this example of xxx 2 , gave 3 as a result !. I would like to understand the answer given .
– Gustavo Aryel