Simple LISP reference


/ Published in: Lisp
Save to your folder(s)

This demonstrates, in as few lines as possible, the basic syntax of LISP. You should be able to figure out how to make more complex programs just by thinking about it. For example, if (+ '1 '2) is how you add numbers, then (* '1 '2) would multiply numbers. String them together for more complexity --- (* (+ '1 '2) (+ '3 '4)). Note that, with numbers, you can use '1 or 1 -- it's basically the same thing. With variables, it is different. Designed using CLISP.


Copy this code and paste it in your HTML
  1. (print 'hi)
  2.  
  3. (print "hello world")
  4.  
  5. (defun f(x)
  6. (cond ((null x) 'null)
  7. ('T 'not-null) ) )
  8.  
  9. (f 'blah)
  10.  
  11. (f NIL)
  12.  
  13. (defun g()
  14. (print 'hi)
  15. (print 'bye) )
  16.  
  17. (g)
  18.  
  19. (setq x 5)
  20.  
  21. (equal x 5)
  22.  
  23. (print x)
  24.  
  25. (print 'x)
  26.  
  27. (+ '5 '3)
  28.  
  29. (if 'T 1 2)
  30.  
  31. (if NIL 1 2)
  32.  
  33. (and 'T 'T)
  34.  
  35. (or 'T NIL)
  36.  
  37. (if (and 'T 'T) 1 2)
  38.  
  39. (car '(1 2 3 4 5))
  40.  
  41. (cdr '(1 2 3 4 5))

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.