altos/lisp: Clean up OS integration bits, add defun
[fw/altos] / src / lisp / ao_lisp_const.lisp
index 621fefc4f9ecfe3c9798210398a5edcbc6f40b40..08a511d9cf0ec380e4fc696956b9e329eb4fdf4b 100644 (file)
 (setq 1+ (lambda (x) (+ x 1)))
 (setq 1- (lambda (x) (- x 1)))
 
-                                       ; define a variable without returning the value
+                                       ;
+                                       ; Define a variable without returning the value
+                                       ; Useful when defining functions to avoid
+                                       ; having lots of output generated
+                                       ;
 
-(set 'def (macro (def-param)
+(setdef (macro (def-param)
                 (list
                  'progn
                  (list
                 )
                )
      )
+
+                                       ;
+                                       ; A slightly more convenient form
+                                       ; for defining lambdas.
+                                       ;
+                                       ; (defun <name> (<params>) s-exprs)
+                                       ;
+
+(def defun (macro (defun-param)
+                   (let ((name (car defun-param))
+                         (args (cadr defun-param))
+                         (exprs (cdr (cdr defun-param))))
+                     (list
+                      def
+                      name
+                      (list
+                       'lambda
+                       args
+                       (cond ((cdr exprs)
+                              (cons progn exprs))
+                             ((car exprs))
+                             )
+                       )
+                      )
+                     )
+                   )
+     )