What is wrong in this program:
(setq x (read))
(define y x)
(if (eql y 1) (write "1"))
(else (write "2"))
?
Simple program
-
- Posts: 447
- Joined: Sat Jun 28, 2008 7:49 am
- Location: Austin, TX
- Contact:
Re: Simple program
1. It looks like maybe it's Scheme code hanging out in the Common Lisp forum. Please make sure you post to the appropriate forum.
2. Lisp doesn't have an ELSE form. ELSE is typically just done as the third sub-form of an IF form. e.g: (IF <condition> <then-form> <else-form>)
What error are you getting?
2. Lisp doesn't have an ELSE form. ELSE is typically just done as the third sub-form of an IF form. e.g: (IF <condition> <then-form> <else-form>)
What error are you getting?
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/
Re: Simple program
You're trying to do things as if it is C or C++, lisp isn't written like that.
Note that (read) tries to read from T, it needs user input!
What are you learning with? PCL is pretty good.
As for what is wrong; DEFINE doesn't exist defaultly in CL, SETQ should only be used on already existing variables. ELSE doesn't exist either; it should be done as the second clause of IF. (Or same effect with other macros like COND, CASE etcetera.)
Code: Select all
(let*((x (read)) (y x)) ;LET for local variables, LET* is the variant where the order matters. (y is pretty pointless)
(if (eql y 1) (write "1") ;Note that print is more usually used for stuff like this.
(write "2")))
What are you learning with? PCL is pretty good.
As for what is wrong; DEFINE doesn't exist defaultly in CL, SETQ should only be used on already existing variables. ELSE doesn't exist either; it should be done as the second clause of IF. (Or same effect with other macros like COND, CASE etcetera.)