| | |
Lisp question
Please support our Legacy and Other Languages advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2006
Posts: 32
Reputation:
Solved Threads: 0
I am trying to write a simple Lisp function for my Articficial Intelligence class and am running into a problem. The compiler is seeing the line [inline] format t "Enter a number, press return and enter another number"[/inline] as a an error. It is the placement of the line of code that is causing this error because if I move it, it will display but, I need it to start the function. I am sure it is something simple that I am missing. Please help
Here is the error it is giving me: (FORMAT T "Enter a number, press return and enter another number"). [condition type: TYPE-ERROR]
Thanks a bundle. ( I hope the code tags worked.)

(defun adder()((format t "Enter a number, press return and enter another number")(setq numberOne (read)) (setq numberTwo (read))(format t "~A plus ~A equals ~A" numberOne numberTwo (+ numberOne numberTwo))))
Here is the error it is giving me: (FORMAT T "Enter a number, press return and enter another number"). [condition type: TYPE-ERROR]
Thanks a bundle. ( I hope the code tags worked.)
Last edited by dmmckelv; Jun 13th, 2007 at 9:56 am.
It appears you have a superfluous opening parenthesis just before the FORMAT call:
Also, more tips for Lisp programming:
-Remember that the REPL automatically changes all S-expressions to upper case; leave capital letters out of variable names and out of FORMAT directives - "~a" for example.
-Format your code nicely - it makes it SO much easier to read (for everyone, most of all yourself).
EDIT: I also just noticed, something (silly me).
Note the use of PARSE-INTEGER.
Also, which Lisp implementation are you using? I haven't seen SETQ used outside of lexical bindings in a while (unless you're using Scheme, or a REALLY old implementation; pre-Common Lisp).
(defun adder () (format t "Enter a number, press return and enter another number") (setq number-one (read)) (setq number-two (read)) (format t "~a plus ~a equals ~a" number-one number-two (+ number-one number-two)))
-Remember that the REPL automatically changes all S-expressions to upper case; leave capital letters out of variable names and out of FORMAT directives - "~a" for example.
-Format your code nicely - it makes it SO much easier to read (for everyone, most of all yourself).
EDIT: I also just noticed, something (silly me).
(defun adder () (format t "Enter a number, press return and enter another number") (setq number-one (parse-integer (read))) (setq number-two (parse-integer (read))) ...)
Also, which Lisp implementation are you using? I haven't seen SETQ used outside of lexical bindings in a while (unless you're using Scheme, or a REALLY old implementation; pre-Common Lisp).
Last edited by indienick; Jun 14th, 2007 at 12:27 am.
Angel-headed hipsters burning for the ancient heavenly connection, to the starry dynamo in the machinery of the night.
-Ginsburg
Don't tell me to "google it" - I already have.
-Ginsburg
Don't tell me to "google it" - I already have.
•
•
Join Date: Nov 2006
Posts: 32
Reputation:
Solved Threads: 0
One little sneaky parenthesis can cause a lot of pain in LISP. You solved my problem. Thanks.
I could not implement the parse-integer, it gave me a type error.
Also, the other tips were helpful. They have made the rest of my homework look much better as well.
I am using Common-Lisp I am using International Allegro CL Free Express Edition 8.0 as my editor. Maybe the instructor is just old-school. This is my first introduction to LISP.
I could not implement the parse-integer, it gave me a type error.
Also, the other tips were helpful. They have made the rest of my homework look much better as well.
I am using Common-Lisp I am using International Allegro CL Free Express Edition 8.0 as my editor. Maybe the instructor is just old-school. This is my first introduction to LISP.
You're very welcome, dmmckelv. 
azimuth0: Thanks for the additional info - I've never used READ, and just assumed it returned any expression as a string type, and not the entire line. Bad call on my part. (My thinking is similar to the difference between INPUT and LINE INPUT in BASIC dialects).

azimuth0: Thanks for the additional info - I've never used READ, and just assumed it returned any expression as a string type, and not the entire line. Bad call on my part. (My thinking is similar to the difference between INPUT and LINE INPUT in BASIC dialects).
Angel-headed hipsters burning for the ancient heavenly connection, to the starry dynamo in the machinery of the night.
-Ginsburg
Don't tell me to "google it" - I already have.
-Ginsburg
Don't tell me to "google it" - I already have.
![]() |
Similar Threads
- Lisp (Legacy and Other Languages)
- Welcome PC Mod Kingdom peeps! (Geeks' Lounge)
- Laptop LCD built into a car? (Monitors, Displays and Video Cards)
- Changing Network Configuration (*nix Software)
Other Threads in the Legacy and Other Languages Forum
- Previous Thread: DOS Batch command to ping network IP
- Next Thread: UNIX environment problem.
Views: 1632 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Legacy and Other Languages





