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)
63 ; basic list accessors
66 (defun cadr (l) (car (cdr l)))
68 (defun caddr (l) (car (cdr (cdr l))))
71 (cond ((= n 0) (car list))
72 ((nth (cdr list) (1- n)))
76 ; simple math operators
78 (defun 1+ (x) (+ x 1))
79 (defun 1- (x) (- x 1))
81 ; define a set of local
82 ; variables and then evaluate
85 ; (let (var-defines) sexprs)
87 ; where var-defines are either
97 ; (let ((x 1) (y)) (setq y (+ x 1)) y)
99 (def let (macro (vars exprs)
100 ((lambda (make-names make-exprs make-nils)
104 ; make the list of names in the let
107 (setq make-names (lambda (vars)
109 (cons (car (car vars))
110 (make-names (cdr vars))))
115 ; the set of expressions is
116 ; the list of set expressions
118 ; expressions to evaluate
120 (setq make-exprs (lambda (vars exprs)
129 (make-exprs (cdr vars) exprs)
138 ; the parameters to the lambda is a list
139 ; of nils of the right length
141 (setq make-nils (lambda (vars)
142 (cond (vars (cons nil (make-nils (cdr vars))))
146 ; prepend the set operations
149 (setq exprs (make-exprs vars exprs))
157 (cond ((cdr exprs) (cons 'progn exprs))
177 (cond ((setq ret (car l))
185 ; execute to resolve macros
192 (cond ((setq ret (car l))
194 ((setq ret (setq l nil)))
202 ; execute to resolve macros