altos/lisp: Deal with memory compation in the middle of operations
[fw/altos] / src / lisp / ao_lisp_const.lisp
index 621fefc4f9ecfe3c9798210398a5edcbc6f40b40..c6f50e346c9dd8bb61fcbc12eee7c6525af1ea23 100644 (file)
@@ -7,16 +7,20 @@
 
                                        ; evaluate a list of sexprs
 
-(setq progn (lexpr (l) (last l)))
+;(setq progn (lexpr (l) (last l)))
 
                                        ; simple math operators
 
 (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))
+                             )
+                       )
+                      )
+                     )
+                   )
+     )