473,320 Members | 1,841 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,320 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 1583
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.