473,385 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Where do I post my questions related to LISP programming???

lifeisgreat20009
I didnt find any forum for that so I am posting here......

The problem is that I want to make a menu driven program in LISP.......

I have written all the functions that will be there in the menu options but I do not know how to implement a case statement in LISP........
I searched a lot for this on net but in vain..........

My guess is that the program should look like this.......

Expand|Select|Wrap|Line Numbers
  1.  
  2. defun  function1 ( parameters ...)
  3.   (
  4. .
  5. .
  6. .
  7.     )
  8.  
  9.  
  10. defun  function2 ( parameters ...)
  11.   (
  12. .
  13. .
  14. .
  15.     )
  16.  
  17.  
  18. defun  function3 ( parameters ...)
  19.   (
  20. .
  21. .
  22. .
  23.     )
  24.  
  25.  
  26. case
  27.  
  28. 1: function1
  29.  
  30. 2: function2
  31.  

and so on.......


plz somebody tell me how do I implement this case statement..........
Apr 13 '08 #1
6 1585
Stang02GT
1,208 Expert 1GB
Unfortunately i don't know anything about LISP but i commend you for looking around first and not just posting this question anywhere. Thank you!
Apr 13 '08 #2
Unfortunately i don't know anything about LISP but i commend you for looking around first and not just posting this question anywhere. Thank you!

I have made another version of my program using cond statement which is as follows. The problem is that it is returning nil as the answer every time......

please somebody tell me why is it not working ???


Expand|Select|Wrap|Line Numbers
  1. (defun  reverse-list-aux  (l  x)
  2.    (if  (null  l)
  3.           x
  4.       (reverse-list-aux  (cdr  l)  (cons  (car  l)  x))))
  5.  
  6.  
  7. ;***********************************************************************
  8.  
  9. (defun raise-aux (result number-list)
  10. (if (endp number-list)
  11. result
  12. (raise-aux (expt result (first number-list))
  13. (rest number-list))))
  14. (defun raise (x &rest numbers)
  15. (raise-aux x numbers))
  16.  
  17. ;***********************************************************************
  18.  
  19. (defun sum-list (list)
  20.             (if list
  21.                 (+ (car list) (sum-list (cdr list)))
  22.               0))
  23.  
  24.  
  25. ;***********************************************************************
  26. (defun rotate-left (l)
  27. (append (cdr l) (list (car l))))
  28.  
  29.  
  30.  
  31.  
  32.  
  33. ;***********************************************************************
  34.  
  35. (defun rotate-right (l)
  36. (append (last l) (list (butlast l))))
  37.  
  38.  
  39. ;***********************************************************************
  40.  
  41.  
  42. (setq p 1)
  43.  
  44. (defun
  45.  mymenu (p)
  46.  
  47. (cond 
  48.  
  49. ((equal p 1)
  50. (reverse-list-aux '(a b c d e f g h) () )
  51.  
  52. ((equal p 2)
  53. (raise '(2 3 5))
  54.  
  55. ((equal p 3)
  56. (sum-list '(2 3))
  57.  
  58. ((equal p 4)
  59. (rotate-left '(a b c))
  60.  
  61. ((equal p 5)
  62. (rotate-right '(a b c))
  63.  
  64. (t 'Sorry you can only give 1,2,3,4 as arguments))))))))
  65.  
  66. (mymenu '3)
  67.  
  68.  
  69.  
Apr 15 '08 #3
I have made the above program using cond statement . The problem is that it is returning nil as the answer every time......

please somebody tell me why is it not working ???


NOTE: All the functions defined in the above program are working well when run separately

i wanted to make this program using case statement but I dont know how to implement that. A searched a lot about case statement but in vain. plz help if anyone knows that.
Apr 16 '08 #4
Is there nobody who can help me with LISP artificial intelligent language ?????
Apr 17 '08 #5
The problem with your code is that you haven't matched the brackets -- see the comment below. You have to follow the pattern:

(cond (test result) (test result) (else result))

I have made another version of my program using cond statement which is as follows. The problem is that it is returning nil as the answer every time......

please somebody tell me why is it not working ???


Expand|Select|Wrap|Line Numbers
  1. (cond 
  2.  
  3. ((equal p 1)
  4. (reverse-list-aux '(a b c d e f g h) () )
  5. ) ; match the one before ((equal ...
  6. ((equal p 2)
  7. (raise '(2 3 5))
  8. )  ; match the one before ((equal ...
  9.  
  10.  
For your previous question, there is a case statement in Lisp:
Expand|Select|Wrap|Line Numbers
  1. (defun menu (p) (case p ((1) 'one) ((2) 'two) ((3) 'three)))
  2.  
See Paul Graham's ANSI Common Lisp or Peter Seibel's http://gigamonkeys.com/book/ for more information on Lisp.
Apr 24 '08 #6
The problem with your code is that you haven't matched the brackets -- see the comment below. You have to follow the pattern:

(cond (test result) (test result) (else result))



For your previous question, there is a case statement in Lisp:
Expand|Select|Wrap|Line Numbers
  1. (defun menu (p) (case p ((1) 'one) ((2) 'two) ((3) 'three)))
  2.  
See Paul Graham's ANSI Common Lisp or Peter Seibel's http://gigamonkeys.com/book/ for more information on Lisp.



Hey thanks so much .....
I tried the prog using case statement and its working fine except for the raise function....
I have run this program separately and its working fine but somehow its not working in this case menu driven program...

Its giving the following error..


CL-USER 6 > (menu 2)

Error: Undefined operator X in form (X NUMBERS).
1 (continue) Try invoking X again.
2 Return some values from the form (X NUMBERS).
3 Try invoking something other than X with the same arguments.
4 Set the symbol-function of X to another function.
5 Set the macro-function of X to another function.
6 (abort) Return to level 0.
7 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed, or :? for other options


Plzzz help me..........
thanks....................
Apr 27 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
3
by: Xiangliang Meng | last post by:
Hi, all. In 1998, I graduated from Computer Science Dept. in a university in China. Since then, I've been using C Language for almost 6 years. Although I'm using C++ in my current job, I'm also...
0
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
15
by: David T. Ashley | last post by:
I'll be using gcc under Red Hat Enterprise Linux. Where do I find information about the low-level calls to the operating system from compiled 'C'? For example, if I want to cause a process to...
33
by: NicolasG | last post by:
Hi, I want to be a professional python programmer, unfortunately I'm working on technical support and don't have the time/patience to start making projects my self. I tried to apply to some...
6
by: John Ladasky | last post by:
Hi folks, I've played around with neural nets for a while. I wrote my own slow, pure-Python NN package. I knew that there were Python NN packages out there -- but I couldn't really understand...
12
by: Djuro.Tost | last post by:
Thanks in advance... Robert...;)
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.