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)
49 (cons 'lambda (cons args exprs))
54 ; basic list accessors
57 (defun cadr (l) (car (cdr l)))
59 (defun caddr (l) (car (cdr (cdr l))))
62 (cond ((= n 0) (car list))
63 ((nth (cdr list) (1- n)))
67 ; simple math operators
69 (defun 1+ (x) (+ x 1))
70 (defun 1- (x) (- x 1))
72 ; define a set of local
73 ; variables and then evaluate
76 ; (let (var-defines) sexprs)
78 ; where var-defines are either
88 ; (let ((x 1) (y)) (setq y (+ x 1)) y)
90 (def let (macro (vars exprs)
91 ((lambda (make-names make-exprs make-nils)
94 ; make the list of names in the let
97 (setq make-names (lambda (vars)
99 (cons (car (car vars))
100 (make-names (cdr vars))))
105 ; the set of expressions is
106 ; the list of set expressions
108 ; expressions to evaluate
110 (setq make-exprs (lambda (vars exprs)
118 (make-exprs (cdr vars) exprs)
126 ; the parameters to the lambda is a list
127 ; of nils of the right length
129 (setq make-nils (lambda (vars)
130 (cond (vars (cons nil (make-nils (cdr vars))))
134 ; prepend the set operations
137 (setq exprs (make-exprs vars exprs))
141 (cons (cons 'lambda (cons (make-names vars) exprs))
157 (cond ((setq ret (car l))
165 ; execute to resolve macros
172 (cond ((setq ret (car l))
174 ((setq ret (setq l nil)))
182 ; execute to resolve macros