2 ; Copyright © 2016 Keith Packard <keithp@keithp.com>
4 ; This program is free software; you can redistribute it and/or modify
5 ; it under the terms of the GNU General Public License as published by
6 ; the Free Software Foundation, either version 2 of the License, or
7 ; (at your option) any later version.
9 ; This program is distributed in the hope that it will be useful, but
10 ; WITHOUT ANY WARRANTY; without even the implied warranty of
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ; General Public License for more details.
14 ; Lisp code placed in ROM
16 ; return a list containing all of the arguments
18 (set (quote list) (lexpr (l) l))
21 ; Define a variable without returning the value
22 ; Useful when defining functions to avoid
23 ; having lots of output generated
26 (setq def (macro (name val rest)
39 ; A slightly more convenient form
40 ; for defining lambdas.
42 ; (defun <name> (<params>) s-exprs)
45 (def defun (macro (name args exprs)
60 ; basic list accessors
63 (defun cadr (l) (car (cdr l)))
65 (defun caddr (l) (car (cdr (cdr l))))
68 (cond ((= n 0) (car list))
69 ((nth (cdr list) (1- n)))
73 ; simple math operators
75 (defun 1+ (x) (+ x 1))
76 (defun 1- (x) (- x 1))
78 ; define a set of local
79 ; variables and then evaluate
82 ; (let (var-defines) sexprs)
84 ; where var-defines are either
94 ; (let ((x 1) (y)) (setq y (+ x 1)) y)
96 (def let (macro (vars exprs)
97 ((lambda (make-names make-exprs make-nils)
101 ; make the list of names in the let
104 (setq make-names (lambda (vars)
106 (cons (car (car vars))
107 (make-names (cdr vars))))
112 ; the set of expressions is
113 ; the list of set expressions
115 ; expressions to evaluate
117 (setq make-exprs (lambda (vars exprs)
126 (make-exprs (cdr vars) exprs)
135 ; the parameters to the lambda is a list
136 ; of nils of the right length
138 (setq make-nils (lambda (vars)
139 (cond (vars (cons nil (make-nils (cdr vars))))
143 ; prepend the set operations
146 (setq exprs (make-exprs vars exprs))
154 (cond ((cdr exprs) (cons 'progn exprs))
174 (cond ((setq ret (car l))
182 ; execute to resolve macros
189 (cond ((setq ret (car l))
191 ((setq ret (setq l nil)))
199 ; execute to resolve macros