Page 1 of 1

Write A menu for dictionary

Posted: Sun Nov 25, 2012 6:40 am
by omarasl
Hello every body ,
Actually I am very beginner in lisp and I have a home work to make some thing like dictionary .
I should make a menu that gives the user some choices like add new word or delete it or translate it .
I write this in txt file :

( loop
(print "==================================================================")
(print "Please Select One of This Choises ")
(print "==================================================================")
(print "==================================================================")
(print "1- translate ")
(print "2- add word ")
(print "3- delete word")
(print "0- exit")
(setf i (read))
(if (= i 1) (call translate) )
(if (= i 2) (call add))
(if (= i 3) (call delete))
(if (= i 4) (return "Good Bye"))
)

then when I load it like this ;
(load "t.lsp")
it write the print commands but at the end give this result :
"unexpected end of input stream "

please would you help me in this error
thank you

Re: Write A menu for dictionary

Posted: Tue Nov 27, 2012 4:20 pm
by sylwester
I tried you code with clisp and it does not fail in the manner you describe.
I'm thinking you might use a different implementation that demands a line feed in the last line and you got none perhaps?

Other than that you may want to separate parts of your code in functions and even put the loop into a function so that you can load and test your parts individually. It makes debugging/testing easier.

br,
Syl

Re: Write A menu for dictionary

Posted: Tue Nov 27, 2012 6:00 pm
by omarasl
thanks alot

Re: Write A menu for dictionary

Posted: Sun Jan 20, 2013 12:47 pm
by tppereir
Define this function

(defun menu ()
(print "==================================================================")
(print "Please Select One of This Choises ")
(print "==================================================================")
(print "==================================================================")
(print "1- translate ")
(print "2- add word ")
(print "3- delete word")
(print "0- exit")
(setf i (read))
(cond
((if (= i 1) (call translate) ))
((if (= i 2) (call add)) )
((if (= i 3) (call delete)) )
((if (= i 4) (return "Good Bye")) ) )
)

Call it later

(menu)

Re: Write A menu for dictionary

Posted: Sun Jan 20, 2013 1:02 pm
by omarasl
thank you very much .........
it seems good