1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2% 3% File: PNK:LISP-MACROS.SL 4% Title: Various macros to make pure Lisp more tolerable 5% Author: Eric Benson 6% Created: 5 October 1981 7% Modified: 28-Aug-84 13:13:02 (Brian Beach) 8% Status: Open Source: BSD License 9% Mode: Lisp 10% Package: Kernel 11% Compiletime: 12% Runtime: 13% 14% (c) Copyright 1983, Hewlett-Packard Company, see the file 15% HP_disclaimer at the root of the PSL file tree 16% 17% (c) Copyright 1982, University of Utah 18% 19% Redistribution and use in source and binary forms, with or without 20% modification, are permitted provided that the following conditions are met: 21% 22% * Redistributions of source code must retain the relevant copyright 23% notice, this list of conditions and the following disclaimer. 24% * Redistributions in binary form must reproduce the above copyright 25% notice, this list of conditions and the following disclaimer in the 26% documentation and/or other materials provided with the distribution. 27% 28% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 29% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 30% THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 31% PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNERS OR 32% CONTRIBUTORS 33% BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 34% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 35% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 36% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 37% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39% POSSIBILITY OF SUCH DAMAGE. 40% 41%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 42% 43% Revisions: 44% 45% 01-Dec-83 14:49:53 (Brian Beach) 46% Translated from Rlisp to Lisp. 47% 48%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 49 50(compiletime 51 (flag '(inthiscase) 'internalfunction)) 52 53% Not a macro, but it belongs with these 54(df case (u) 55 %U is of form (CASE <integer exp> (<case-1> <exp-1>) . . .(<case-n> <exp-n>)). 56 57 % If <case-i> is NIL it is default, 58 % else is list of INT or (RANGE int int) 59 (prog (caseexpr def caselst bod) 60 (setq caseexpr (eval (car u))) 61 l 62 (unless (pairp (setq u (cdr u))) 63 (return (eval def))) 64 (setq caselst (caar u)) 65 (setq bod (cadar u)) 66 (when (or (not (pairp caselst)) 67 (memq (car caselst) '(otherwise default))) 68 (setq def bod) 69 (go l)) 70 (when (inthiscase caseexpr caselst) 71 (return (eval bod))) 72 (go l))) 73 74(de inthiscase (caseexpr cases) 75 (cond ((not (pairp cases)) nil) 76 ((and (pairp (car cases)) (eq (caar cases) 'range) 77 (geq caseexpr (cadar cases)) (leq caseexpr (caddar cases))) 78 t) 79 ((equal caseexpr (car cases)) t) 80 (t (inthiscase caseexpr (cdr cases))))) 81 82(dm setf (u) 83 %. General assignment macro 84 (expandsetf (cadr u) (caddr u))) 85 86(de expandsetf (lhs rhs) 87 (let (lhsop) 88 (cond ((atom lhs) (list 'setq lhs rhs)) 89 ((setq lhsop (get (car lhs) 'assign-op)) 90 (cons lhsop (append (cdr lhs) (list rhs)))) 91 % simple substitution case 92 ((setq lhsop (get (car lhs) 'setf-expand)) 93 (apply lhsop (list lhs rhs))) 94 % more complex transformation 95 ((and (setq lhsop (getd (car lhs))) 96 (equal (car lhsop) 'macro)) 97 (expandsetf (apply (cdr lhsop) (list lhs)) rhs)) 98 (t (stderror 99 (bldmsg "%r is not a known form for assignment" 100 (list 'setf lhs rhs))))))) 101 102(loadtime 103 (deflist '((getv putv) (car rplaca) (cdr rplacd) (indx setindx) 104 (sub setsub) (nth (lambda (l i x) 105 (rplaca (pnth l i) x) 106 x)) (eval set) (value set)) 107 'assign-op)) 108 109