Write A menu for dictionary

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.

Write A menu for dictionary

Postby omarasl » Sun Nov 25, 2012 6:40 am

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

Re: Write A menu for dictionary

Postby sylwester » Tue Nov 27, 2012 4:20 pm

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
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p
sylwester
 
Posts: 83
Joined: Mon Jul 11, 2011 2:53 pm

Re: Write A menu for dictionary

Postby omarasl » Tue Nov 27, 2012 6:00 pm

thanks alot
omarasl
 
Posts: 12
Joined: Sun Nov 25, 2012 6:19 am

Re: Write A menu for dictionary

Postby tppereir » Sun Jan 20, 2013 12:47 pm

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)
tppereir
 
Posts: 1
Joined: Sun Oct 23, 2011 4:57 pm

Re: Write A menu for dictionary

Postby omarasl » Sun Jan 20, 2013 1:02 pm

thank you very much .........
it seems good
omarasl
 
Posts: 12
Joined: Sun Nov 25, 2012 6:19 am


Return to Homework

Who is online

Users browsing this forum: No registered users and 0 guests

cron