home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 January / enter-2004-01.iso / files / maxima-5.9.0.exe / {app} / share / maxima / 5.9.0 / src / maxmac.lisp < prev    next >
Encoding:
Text File  |  2003-02-09  |  21.2 KB  |  655 lines

  1. ;;; -*-  Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;;     The data in this file contains enhancments.                    ;;;;;
  4. ;;;                                                                    ;;;;;
  5. ;;;  Copyright (c) 1984,1987 by William Schelter,University of Texas   ;;;;;
  6. ;;;     All rights reserved                                            ;;;;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;;;  (c) Copyright 1976, 1983 Massachusetts Institute of Technology      ;;;
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10.  
  11. (in-package "MAXIMA")
  12. (macsyma-module maxmac #-lispm macro)
  13.  
  14. ;; This file contains miscellaneous macros used in Macsyma source files.
  15. ;; This file must run and compile in PDP10 Lisp, Multics Lisp, Franz Lisp,
  16. ;; and LMLisp.
  17.  
  18. ;; General purpose macros which are used in Lisp code, but not widely enough
  19. ;; accepted to be a part of Lisp systems.
  20.  
  21. ;; For evaluable declarations placed in macro files. This is a DWIM form
  22. ;; saying "evaluate this form if you think it matters." If we tried hard
  23. ;; we could come up with a better way to actually do it. -gjc
  24.  
  25. (defmacro for-declarations (&rest l)
  26.   `(map-eval-for-declarations ',l))
  27.  
  28. (defun map-eval-for-declarations (l) (mapc #'eval-for-declarations l))
  29.  
  30. (defun eval-for-declarations (form)
  31.   (if (and (not (atom form))
  32.        (symbolp (car form))
  33.        ;; we want an fboundp which gives T for special forms too.
  34.        (OR (fboundp (car form))
  35.            #+NIL (SI:MACRO-DEFINITION (CAR FORM))
  36.            #+NIL (EQ (CAR FORM) 'SPECIAL)))
  37.       (eval form)))
  38.  
  39.  
  40. (defmacro optimizing-declarations (dcls &body body) dcls
  41.   #+NIL `(locally (declare (optimize ,@dcls)) ,@body)
  42.   #-NIL `(progn ,@body))
  43.  
  44. ;; All these updating macros should be made from the same generalized
  45. ;; push/pop scheme as I mentioned to LispForum. As they are defined now
  46. ;; they have inconsistent return-values and multiple-evaluations of
  47. ;; arguments. -gjc
  48.  
  49. (DEFMACRO ADDL (ITEM LIST)
  50.       `(OR (MEMQ ,ITEM ,LIST) (SETQ ,LIST (CONS ,ITEM ,LIST))))
  51.  
  52. #-Multics (PROGN 'COMPILE
  53.  
  54.  
  55. (DEFMACRO INCREMENT (COUNTER &OPTIONAL INCREMENT)
  56.   (IF INCREMENT
  57.       `(SETF ,COUNTER (f+ ,COUNTER ,INCREMENT))
  58.       `(SETF ,COUNTER (f1+ ,COUNTER))))
  59.  
  60.  
  61. (DEFMACRO DECREMENT (COUNTER &OPTIONAL DECREMENT)
  62.   (IF DECREMENT
  63.       `(SETF ,COUNTER (f- ,COUNTER ,DECREMENT))
  64.       `(SETF ,COUNTER (f1- ,COUNTER))))
  65.  
  66. (DEFMACRO COMPLEMENT (SWITCH) `(SETF ,SWITCH (NOT ,SWITCH)))
  67.  
  68. ) ;; End of Lispm conditionalization.
  69.  
  70.  
  71. ;; 'writefilep' and 'ttyoff' are system independent ways of expressing
  72. ;; the Maclisp ^R and ^W.
  73. ;; In Franz Lisp, we make writefilep equivalent to ptport, which isn't
  74. ;; exactly correct since ptport is not just a boolean variable.  However
  75. ;; it works in most cases.  
  76. ;;
  77. (eval-when (compile eval load)
  78.    (defvar writefilep #-Franz '^R #+Franz 'ptport)
  79.    (defvar ttyoff    '^W))
  80.  
  81. ;; (IFN A B) --> (COND ((NOT A) B))
  82. ;; (IFN A B C D) --> (COND ((NOT A) B) (T C D))
  83. ;; (IFN A B) is equivalent to (OR A B) as (IF A B) is equivalent to (AND A B).
  84.  
  85. (DEFMACRO IFN (PREDICATE THEN . ELSE)
  86.       (COND ((NULL ELSE) `(COND ((NOT ,PREDICATE) ,THEN)))
  87.         (T `(COND ((NOT ,PREDICATE) ,THEN) (T . ,ELSE)))))
  88.  
  89. (DEFMACRO FN (BVL &REST BODY)
  90.       `(FUNCTION (LAMBDA ,BVL . ,BODY)))
  91.  
  92. ;; Like PUSH, but works at the other end.
  93.  
  94. (DEFMACRO TUCHUS (LIST OBJECT)
  95.       `(SETF ,LIST (NCONC ,LIST (NCONS ,OBJECT))))
  96.  
  97. ;; Copy a single cons, the top level and all levels (repectively) of a piece of
  98. ;; list structure.  Something similar for strings, structures, etc. would be
  99. ;; useful.  These functions should all be open-coded subrs.
  100.  
  101. (DEFMACRO COPY-CONS (CONS)
  102.   (IF (ATOM CONS)
  103.       `(CONS (CAR ,CONS) (CDR ,CONS))
  104.       (LET ((VAR (GENSYM)))
  105.        `(LET ((,VAR ,CONS)) `(CONS (CAR ,VAR) (CDR ,VAR))))))
  106.  
  107. (DEFMACRO COPY-TOP-LEVEL (LIST)
  108.   #+(or cl NIL) `(COPY-LIST ,LIST)
  109.   #-(or cl NIL) `(APPEND ,LIST NIL))
  110.  
  111. (DEFMACRO COPY-ALL-LEVELS (LIST)
  112.   #+(or cl NIL) `(COPY-TREE ,LIST)
  113.   #-(or lispm NIL) `(SUBST NIL NIL ,LIST))
  114.  
  115. ;; Old names kept around for compatibility.
  116.  
  117. (DEFMACRO COPY1* (LIST)
  118.   #+(or cl NIL) `(COPY-LIST ,LIST)
  119.   #-(or cl NIL) `(APPEND ,LIST NIL))
  120. (DEFMACRO COPY1 (LIST)
  121.   #+(or cl NIL) `(COPY-LIST ,LIST)
  122.   #-(or cl NIL) `(APPEND ,LIST NIL))
  123. #-Franz
  124. (DEFMACRO COPY (LIST)
  125.   #+(or cl nil  symbolics) `(COPY-TREE ,LIST)
  126.   #-(or cl nil symbolics) `(SUBST NIL NIL ,LIST))
  127.  
  128. ;; Use this instead of GETL when looking for "function" properties,
  129. ;; i.e. one of EXPR, SUBR, LSUBR, FEXPR, FSUBR, MACRO.
  130. ;; Use FBOUNDP, SYMBOL-FUNCTION, or FMAKUNBOUND if possible.
  131.  
  132. (DEFMACRO GETL-FUN (FUN L)
  133.       #+MacLisp `(GETL ,FUN ,L)
  134.       #+CL   `(GETL-LM-FCN-PROP ,FUN ,L)
  135.       #+Franz   `(GETL-FRANZ-FCN-PROP ,FUN ,L)
  136.       #+NIL     `(GETL-NIL-FCN-PROP ,FUN ,L)
  137.       )
  138.  
  139. ;; Non-destructive versions of DELQ and DELETE.  Already part of NIL
  140. ;; and LMLisp.  These should be rewritten as SUBRS and placed
  141. ;; in UTILS.  The subr versions can be more memory efficient.
  142.  
  143. ;#-(OR Lispm NIL Multics Franz cl)
  144. ;(DEFMACRO REMQ (ITEM LIST &OPTIONAL (COUNT () COUNTING?))
  145. ;      (IF COUNTING? `(DELQ ,ITEM (APPEND ,LIST NIL) ,COUNT)
  146. ;          `(DELQ ,ITEM (APPEND ,LIST NIL))))
  147.  
  148.  
  149. (DEFMACRO REMQ (ITEM LIST &OPTIONAL (COUNT () COUNTING?))
  150.  `(remove ,item ,list :test 'eq ,@ (and counting? `(:count ,count))))
  151.  
  152. ;#+cl ;in clmacs
  153. ;(DEFMACRO ZL-REMOVE (ITEM LIST &OPTIONAL (COUNT () COUNTING?))
  154. ; `(remove ,item ,list :test 'equal ,@ (and counting? `(:count ,count))))    
  155.  
  156. ;#-(OR Lispm NIL Multics Franz)
  157. ;(DEFMACRO zl-REMOVE (ITEM LIST &OPTIONAL (COUNT () COUNTING?))
  158. ;      (IF COUNTING? `(zl-DELETE ,ITEM (APPEND ,LIST NIL) ,COUNT)
  159. ;          `(zl-DELETE ,ITEM (APPEND ,LIST NIL))))
  160.  
  161. #-Lispm (DEFMACRO CATCH-ALL (FORM) `(CATCH NIL ,FORM))
  162.  
  163. ;; (EXCH A B) exchanges the bindings of A and B
  164. ;; Maybe it should turn into (PSETF A B B A)?
  165.  
  166. (DEFMACRO EXCH (X Y) `(SETF ,X (PROG1 ,Y (SETF ,Y ,X))))
  167.  
  168. ;; These are here for old code only.
  169. ;; Use FIFTH rather than CADDDDR.  Better, use DEFSTRUCT.
  170.  
  171. #-Franz (DEFMACRO CADDADR (X) `(CAR (CDDADR ,X)))
  172. #-Franz (DEFMACRO CADDDDR (X) `(CAR (CDDDDR ,X)))
  173.  
  174. ;; The following is a bit cleaner than the kludgy (PROGN 'COMPILE . <FORMS>)
  175.  
  176. (DEFMACRO COMPILE-FORMS (&REST <FORMS>) `(PROGN 'COMPILE . ,<FORMS>))
  177.  
  178.  
  179. ;; The following macros pertain only to Macsyma.
  180.  
  181. ;; Widely used macro for printing error messages.  We should be able
  182. ;; to come up with something better.  On large address space systems
  183. ;; this should signal -- hack later.  Soon to be flushed in favor
  184. ;; of new Macsyma error system.  Yea!
  185.  
  186. ;; Obsolete.  Use MERROR.
  187.  
  188. (DEFMACRO ERLIST (MESSAGE)
  189.   (MAXIMA-ERROR "ERLIST is obsolete, all calls to it have been removed, so where
  190.      did you dig this one up loser?" message))
  191.  
  192. ;; All functions are present on non-autoloading systems.  Definition
  193. ;; for autoloading systems is in SUPRV.
  194. ;; If you have dynamic linking you might as well take advantage of it.
  195.  
  196. #-(OR PDP10 NIL)
  197. (DEFMACRO FIND-FUNCTION (FUNCTION) FUNCTION NIL)
  198.  
  199. ;; Facility for loading auxilliary macro files such as RATMAC or MHAYAT.
  200. ;; Global macro files are loaded by the prelude file.
  201.  
  202. #+LISPM (DEFUN MACRO-DIR (X) (FORMAT NIL "LMMAXQ;~A QFASL" X))
  203. #+PDP10 (DEFUN MACRO-DIR (X) `((LIBMAX) ,X))
  204. #+Franz (defun macro-dir (x)  (cond ((cdr (zl-ASSOC x '((rzmac  . "rz//macros")
  205.                              (mhayat . "rat//mhayat")
  206.                              (ratmac . "rat//ratmac")))))
  207.                     (t (concat "libmax//" x))))
  208. #+NIL (defun macro-dir (x) (merge-pathname-defaults x "[VASL]"))
  209.  
  210. (comment Sample definition only on
  211.      ITS   see "LIBMAX;MODULE"
  212.      LISPM see "LMMAX;SYSDEF"
  213.      NIL   see   "VAXMAX;VAXCL"
  214.      Multics see "???"
  215.      Franz see "/usr/lib/lisp/machacks.l"
  216. ()
  217. (defmacro macsyma-module (name &rest options)
  218.   (maybe-load-macros options)
  219.   (maybe-load-declarations options)
  220.   `(eval-when (compile eval load)
  221.       (print '(loading ,name) msgfiles)
  222.       (defprop ,name t loaded?)
  223.       ,@(maybe-have-some-runtime-options options)))
  224. )
  225.  
  226. ;; Except on the Lisp Machine, load the specified macro files.
  227. ;; On the Lisp Machine, the DEFSYSTEM facility is used for loading
  228. ;; macro files, so just check that the file is loaded. This is
  229. ;; a useful error check, has saved a lot of time since Defsystem
  230. ;; is far from fool-proof. See LMMAX;SYSDEF for the Lispm
  231. ;; definition of MACSYMA-MODULE.
  232.  
  233. #+CL
  234. (DEFUN LOAD-MACSYMA-MACROS-AT-RUNTIME (&REST L)
  235.   (MAPCAR #'(LAMBDA (X)
  236.           (IF (GET X 'MACSYMA-MODULE)
  237.            X 
  238.            (ERROR  "Missing Macsyma macro file -- ~A" X)))
  239.       L))
  240. #-CL
  241. (DEFUN LOAD-MACSYMA-MACROS-AT-RUNTIME (&REST L)
  242.   (MAPCAR #'load-when-needed L))
  243.  
  244. (DEFMACRO LOAD-MACSYMA-MACROS (&REST MACRO-FILES)
  245.   `(COMMENT *MACRO*FILES*
  246.         ,(APPLY #'LOAD-MACSYMA-MACROS-AT-RUNTIME MACRO-FILES)))
  247.  
  248.  
  249. #+Multics
  250. (defmacro find-documentation-file (x)
  251.   (cond ((eq x 'manual)
  252.      `(let ((filep (probe-file (list (catenate macsyma-dir ">documentation")
  253.                      "macsyma.manual"))))
  254.         (cond (filep filep)
  255.           (t (MAXIMA-ERROR "Cannot MAXIMA-FIND the Macsyma manual")))))
  256.     ((eq x 'manual-index)
  257.      `(let ((filep (probe-file (list (catenate macsyma-dir ">documentation")
  258.                      "macsyma.index.lisp"))))
  259.         (cond (filep filep)
  260.           (t (MAXIMA-ERROR "Cannot MAXIMA-FIND the Macsyma manual index")))))
  261.     (t (MAXIMA-ERROR "Unknown documentation: " x))))
  262.  
  263. #+Multics
  264. (defmacro load-documentation-file (x)
  265.   `(load (find-documentation-file ,x)))
  266.  
  267. ;;;Reset the stream to its starting position.
  268. (defmacro rewind-stream (stream)
  269.   
  270. #-(or LispM NIL) `(filpos ,stream 0)
  271. ;#+LispM          `(send ,stream ':rewind)
  272. #+cl `(file-position ,stream 0)
  273. #+NIL            `(open ,stream))
  274.  
  275. ;; Used to temporarily bind contexts in such a way as to not cause
  276. ;; the context garbage collector to run. Used when you don't want to
  277. ;; stash away contexts for later use, but simply want to run a piece
  278. ;; of code in a new context which will be destroyed when the code finishes.
  279. ;; Note that this code COULD use an unwind-protect to be safe but since
  280. ;; it will not cause out and out errors we leave it out.
  281.  
  282. (defmacro with-new-context (sub-context &rest forms)
  283.   `(let ((context (context ,@sub-context)))
  284.      (prog1 ,@forms
  285.         (context-unwinder))))
  286.  
  287.  
  288. ;; For creating a macsyma evaluator variable binding context.
  289. ;; (MBINDING (VARIABLES &OPTIONAL VALUES FUNCTION-NAME)
  290. ;;    ... BODY ...)
  291.  
  292. (DEFMACRO MBINDING (VARIABLE-SPECIFICATION &REST BODY &AUX (TEMP (GENSYM)))
  293.   `(LET ((,TEMP ,(CAR VARIABLE-SPECIFICATION)))
  294.      ;; Don't optimize out this temporary, even if (CAR VARIABLE-SPECICIATION)
  295.      ;; is an ATOM. We don't want to risk side-effects.
  296.      ,(CASE (LENGTH VARIABLE-SPECIFICATION)
  297.     ((1)
  298.      `(MBINDING-SUB ,TEMP ,TEMP NIL ,@BODY))
  299.     ((2)
  300.      `(MBINDING-SUB ,TEMP ,(CADR VARIABLE-SPECIFICATION) NIL ,@BODY))
  301.     ((3)
  302.      `(MBINDING-SUB ,TEMP ,(CADR VARIABLE-SPECIFICATION)
  303.             ,(CADDR VARIABLE-SPECIFICATION)
  304.             ,@BODY))
  305.     (T
  306.       (MAXIMA-ERROR "Bad variable specification:" variable-specification)))))
  307.  
  308. (DEFVAR MBINDING-USAGE
  309.   #+(and PDP10 Maclisp)    'PROG1
  310.   #+(and Multics Maclisp)  'UNWIND-PROTECT
  311.   #+Franz                  'PROG1
  312.   #+CL                  'UNWIND-PROTECT
  313.   #+NIL                    'UNWIND-PROTECT
  314.   )
  315.   
  316. (DEFMACRO MBINDING-SUB (VARIABLES VALUES FUNCTION-NAME &REST BODY
  317.                   &AUX (WIN (GENSYM)))
  318.   (CASE MBINDING-USAGE
  319.     ((PROG1)
  320.      `(PROG1 (PROGN (MBIND ,VARIABLES ,VALUES ,FUNCTION-NAME) ,@BODY)
  321.          (MUNBIND ,VARIABLES)))
  322.     ((UNWIND-PROTECT)
  323.      `(LET ((,WIN NIL))
  324.     (UNWIND-PROTECT
  325.      (PROGN (MBIND ,VARIABLES ,VALUES ,FUNCTION-NAME)
  326.         (SETQ ,WIN T)
  327.         ,@BODY)
  328.      (IF ,WIN (MUNBIND ,VARIABLES)))))
  329.     ((PROGV)
  330.      `(LET ((,WIN (MBINDING-CHECK ,VARIABLES ,VALUES ,FUNCTION-NAME)))
  331.     (PROGV ,VARIABLES
  332.            ,WIN
  333.            ,@BODY)))
  334.     (T
  335.      (MAXIMA-ERROR "Unknown setting of MBINDING-USAGE" MBINDING-USAGE))))
  336.  
  337. #+NIL
  338. (DEFMACRO MDEFPROP (A B C) `(MPUTPROP ',A ',B ',C))
  339.  
  340. #-Franz ;; Franz uses a function definition in COMM.
  341.     ;; For MLISTP its arg is known not to be an atom.
  342.     ;; Otherwise, just use $LISTP.
  343.     ;; MLISTP exists just to support a Franz hack, so you can just 
  344.     ;;   ignore it. - JPG
  345. (DEFMACRO MLISTP (X) `(EQ (CAAR ,X) 'MLIST))
  346.  
  347. ;; How About MTYPEP like (MTYPEP EXP 'TAN) or (MTYPEP EXP '*) - Jim.
  348. ;; Better, (EQ (MTYPEP EXP) 'TAN).
  349.  
  350. (DEFMACRO MTANP (X) 
  351.   `(LET ((THING ,X))
  352.      (AND (NOT (ATOM THING)) (EQ (CAAR THING) '%TAN))))
  353.  
  354. (DEFMACRO MATANP (X)
  355.   `(LET ((THING ,X))
  356.      (AND (NOT (ATOM THING)) (EQ (CAAR THING) '%ATAN))))
  357.  
  358. ;; Macros used in LIMIT, DEFINT, RESIDU.
  359. ;; If we get a lot of these, they can be split off into a separate macro
  360. ;; package.
  361.  
  362. (DEFMACRO REAL-INFINITYP (X) `(MEMQ ,X REAL-INFINITIES))
  363.  
  364. (DEFMACRO INFINITYP (X) `(MEMQ ,X INFINITIES))
  365.  
  366. (DEFMACRO REAL-EPSILONP (X) `(MEMQ ,X INFINITESIMALS))
  367.  
  368. (DEFMACRO FREE-EPSILONP (X)
  369.   `(DO ((ONE-EPS INFINITESIMALS (CDR ONE-EPS)))
  370.        ((NULL ONE-EPS) T)
  371.      (IF (NOT (FREE (CAR ONE-EPS) ,X))  (RETURN ()))))
  372.  
  373. (DEFMACRO FREE-INFP (X)
  374.   `(DO ((ONE-INF INFINITIES (CDR ONE-INF)))
  375.        ((NULL ONE-INF) T)
  376.      (IF (NOT (FREE (CAR ONE-INF) ,X))  (RETURN ()))))
  377.  
  378. (DEFMACRO INF-TYPEP (X)
  379.   `(CAR (AMONGL INFINITIES ,X)))
  380.  
  381. (DEFMACRO HOT-COEF (P)
  382.  `(PDIS (CADDR (CADR (RAT-NO-RATFAC ,P)))))
  383.  
  384. ;; Special form for declaring Macsyma external variables.  It may be used for
  385. ;; User level variables, or those referenced by other Lisp programs.
  386.  
  387. ;; Syntax is:
  388. ;; (DEFMVAR <name> &OPTIONAL <initial-value> <documentation> . <flags>) See
  389. ;; MC:LIBMAX;DEFINE > for complete documentation of syntax.  The code in this
  390. ;; file for DEFMVAR is for non-ITS systems only.  LIBMAX;DEFINE contains code
  391. ;; for ITS.  Other systems may process the documentation information as they
  392. ;; wish.
  393.  
  394. ;; Be sure to expand into DEFVAR and not into (DECLARE (SPECIAL ...)) as
  395. ;; certain systems do other things with DEFVAR.  The Lisp Machine, for
  396. ;; instance, annotates the file name.  On Multics and the Lisp Machine, expand
  397. ;; into DEFCONST since the entire Macsyma system is present before user files
  398. ;; are loaded, so there is no need to do the BOUNDP check.
  399. ;; What about people who want to subsequently change a value on lispm?
  400. ;; Use defconst only if you want something that is hardwired into function definitions
  401. ;; as on the lispm.  Also one may want to reload a file to reset some variables,
  402. ;; so if *reset-var* is true defmvar will restore the original value on lispm--Wfs
  403. ;; definition is in commac.
  404.  
  405. #-(or Franz ITS lispm cl)
  406. (DEFMACRO DEFMVAR (VARIABLE &OPTIONAL (INITIAL-VALUE NIL IV-P) DOCUMENTATION
  407.                             &REST FLAGS &AUX DEFINER TYPE)
  408.   DOCUMENTATION FLAGS ;; Ignored certain places.
  409.   (SETQ DEFINER #+(or Multics ) 'DEFCONST
  410.         #-(or Multics  ) 'DEFVAR)
  411.   #-(or Lispm NIL)
  412.   (SETQ TYPE (COND ((MEMQ 'fixnum FLAGS) 'fixnum)
  413.            ((MEMQ 'flonum FLAGS) 'flonum)
  414.            (T NIL)))
  415.   #+NIL (macsyma-defmvar-declarations variable flags)
  416.   `(PROGN 'COMPILE
  417.       ,(IF IV-P
  418.            `(,DEFINER ,VARIABLE ,INITIAL-VALUE
  419.             #+NIL ,@(AND DOCUMENTATION `(,DOCUMENTATION)))
  420.            `(,DEFINER ,VARIABLE #+LISPM () ))
  421.       #-NIL ,@(IF TYPE `((DECLARE (,TYPE ,VARIABLE))))))
  422.  
  423. ;;see commac
  424. #-(or cl lispm)
  425. (Defmacro DEFMFUN (function &body  REST &aux .n.)
  426.   #+NIL (macsyma-defmfun-declarations function rest)
  427.        `(DEFUN ,FUNCTION  ,REST))
  428.  
  429. #+LISPM
  430. (DEFPROP DEFMSPEC "Macsyma special form" SI:DEFINITION-TYPE-NAME)
  431.  
  432. ;; Special form for declaring Macsyma external procedures.  Version for ITS
  433. ;; is in LIBMAX;DEFINE.
  434. ;; Franz version is in libmax/vdefine.l
  435.  
  436.  
  437.  
  438. #+cl
  439. (DEFMACRO DEFMSPEC (FUNCTION . REST)
  440.   `(progn
  441.       (DEFUN-prop ( ,FUNCTION MFEXPR*) . ,REST)
  442.       #+lispm (SI::RECORD-SOURCE-FILE-NAME ',FUNCTION 'DEFMSPEC)))
  443.  
  444. ;#+LISPM
  445. ;(DEFMACRO DEFMSPEC (FUNCTION . REST)
  446. ;  `(LOCAL-DECLARE ((SYS:FUNCTION-PARENT ,FUNCTION DEFMSPEC))
  447. ;     (DEFUN (:PROPERTY ,FUNCTION MFEXPR*) . ,REST)
  448. ;     (SI:RECORD-SOURCE-FILE-NAME ',FUNCTION 'DEFMSPEC)
  449. ;     ))
  450.  
  451.  
  452. ;;How bout the following for a replacement for the defmspec type.
  453. ;;It gives the special form business and seems to work well in the
  454. ;;interpreter.  The translated and compiled forms for special functions
  455. ;;was a problem any way and we should leave the def%tr forms for
  456. ;;$sum etc. and maybe institute some new ones.  
  457. ;;Of course meval and translate have to be told what to do with
  458. ;;a macro but they needed to be told anyway.--wfs
  459.  
  460. ;;see commac
  461. ;#+lispm
  462. ;(defmacro defmspec (fn (aa) &rest rest &aux ans help )
  463. ;  (setq help (intern (format nil "~A-AUX" fn)))
  464. ;  (setq ans
  465. ;    (list    ;;copy-list aa
  466. ;    `(defmacro ,fn (&rest ,aa &aux e)(setq ,aa (copy-list ,aa))
  467. ;           (setq e (cons (list ',fn) ,aa))
  468. ;               `(meval* '(,', help  ',e)))
  469. ;    `(defun ,help (,aa) . ,rest)))
  470. ;  `(progn 'compile . , ans))
  471.  
  472. ;;eg.
  473. ;(defmspecial $ssum (l) (setq l (cdr l))
  474. ;  (if (= (length l) 4)
  475. ;      (dosum (car l) (cadr l) (meval (caddr l)) (meval (cadddr l)) t)
  476. ;      (wna-err '$$sum)))
  477.  
  478.  
  479. ;;;    The following MAUTOLOAD macro makes setting up autoload props for files
  480. ;;; on "standard" Macsyma directories easy, and clean. As an example, the
  481. ;;; code in SUPRV would look as folllows:
  482. ;;;
  483. ;;; (MAUTOLOAD (PURCOPY '(FASL DSK MACSYM))
  484. ;;;  (LIMIT   $LIMIT $LDEFINT)
  485. ;;;  (IRINTE  INTE)
  486. ;;;  (MATCOM  $MATCHDECLARE $DEFMATCH $TELLSIMP $TELLSIMPAFTER $DEFRULE)
  487. ;;;  (MATRUN  $DISPRULE $REMRULE $APPLY1 $APPLYB1 $APPLY2 $APPLYB2
  488. ;;;          FINDBE FINDFUN FINDEXPON FINDBASE PART+ PART*)
  489. ;;;   ...
  490. ;;;
  491. ;;;  ((LISPT FASL DSK LIBLSP) $TECO $TSTRING $TECMAC $EMACS $EDIT)
  492. ;;;
  493. ;;;   ... )
  494. ;;;
  495. ;;;    The reason the file-spec list evals, is so that one may do a PURCOPY as
  496. ;;; above, and also one could imagine having a status request here to obtain
  497. ;;; the canonical file spec's.
  498. ;;;    Note that the first arg must be of the form (FN2 DEV DIR) if a file
  499. ;;; mask is being used; this macro could be much more elaborate.
  500.  
  501. #+ITS
  502. (DEFMACRO MAUTOLOAD (FN2-DEV-DIR &REST MASTER-LIST)
  503.   `(DOLIST (L ',MASTER-LIST)
  504.      (DO ((FILE (IF (ATOM (CAR L))
  505.             (CONS (CAR L) ,FN2-DEV-DIR)
  506.             (CAR L)))
  507.       (FUNLIST (CDR L) (CDR FUNLIST)))
  508.      ((NULL FUNLIST))
  509.        (PUTPROP (CAR FUNLIST) FILE 'AUTOLOAD))))
  510.  
  511. #-Multics
  512. (DEFMACRO SYS-DEFAULTF (X) `(DEFAULTF ,X))
  513. ;;; For #+Multics a function definition for SYS-DEFAULTF can be found 
  514. ;;; in SUPRV.
  515.  
  516. (defmacro sys-user-id ()
  517.   #+Franz '(getenv '|USER|)
  518.   #+lispm 'user-id
  519.   #+Multics '(status uname)
  520.   #-(or Franz Multics lispm) '(status userid))
  521.  
  522. (defmacro sys-free-memory ()
  523.   #-(or Multics lispm) '(status memfree)
  524.   #+(or Multics lispm) 10000.) ;This should look at the pdir size
  525.                                ;and mung it to give a good approximation.
  526.  
  527. ;; Setf hacking.
  528. ;;
  529. ;;
  530. ;;(defsetf GET ((() sym tag) value) T 
  531. ;;   (eval-ordered* '(nsym ntag nvalue)
  532. ;;          `(,sym ,tag ,value)
  533. ;;          '`((PUTPROP ,nsym ,nvalue ,ntag))))
  534.  
  535. #+PDP10
  536. (defsetf MGET ((() sym tag) value) T 
  537.   (eval-ordered* '(nsym ntag nvalue)
  538.          `(,sym ,tag ,value)
  539.          '`((MPUTPROP ,nsym ,nvalue ,ntag))))
  540.  
  541. #+PDP10
  542. (defsetf $GET ((() sym tag) value) T 
  543.   (eval-ordered* '(nsym ntag nvalue)
  544.          `(,sym ,tag ,value)
  545.          '`(($PUT ,nsym ,nvalue ,ntag))))
  546.  
  547. #+Franz
  548. (defsetf mget (expr value)
  549.    `(mputprop ,(cadr expr) ,value ,(caddr expr)))
  550.  
  551. #+Franz
  552. (defsetf $get (expr value)
  553.    `($put ,(cadr expr) ,value ,(caddr expr)))
  554.  
  555. #+NIL
  556. (DEFPROP MGET SETF-MGET SI:SETF-SUBR)
  557. #+NIL
  558. (DEFPROP $GET SETF-$GET SI:SETF-SUBR)
  559.  
  560. ;;DIFFERENT version of setf on Multics and LM ...Bummer... -JIM 3/4/81
  561. #+MULTICS
  562. (defsetf MGET (sym tag) value
  563.   `(MPUTPROP ,sym ,value ,tag))
  564.  
  565. (DEFMFUN MGET (ATOM IND)
  566.   (LET ((PROPS (AND (SYMBOLP ATOM) (GET ATOM 'MPROPS))))
  567.     (AND PROPS (GETf (cdr PROPS) IND))))
  568.  
  569. #+(or cl ti)
  570. (defsetf MGET (sym tag) (value)
  571.   `(MPUTPROP ,sym ,value ,tag))
  572.  
  573. (defmacro old-get (plist tag)
  574.   `(getf (cdr ,plist) ,tag))
  575.  
  576. #+ MULTICS
  577. (defsetf $GET (sym tag) value
  578.   `($PUT ,sym ,value ,tag))
  579.  
  580. (DEFMFUN $GET (ATOM IND) (PROP1 '$GET ATOM NIL IND))
  581.  
  582. #+(or cl ti)
  583. (defsetf $GET (sym tag) (value)
  584.   `($PUT ,sym ,value ,tag))
  585. ;
  586. ;#+(and LISPM (not (or cl ti)))
  587. ;(DEFUN (:PROPERTY MGET SI:SETF) (REF VAL)
  588. ;  `(MPUTPROP ,(SECOND REF) ,VAL ,(THIRD REF)))
  589. ;
  590. ;#+(and LISPM (not (or cl ti)))
  591. ;(DEFUN (:PROPERTY $GET SI:SETF) (REF VAL)
  592. ;  `($PUT ,(SECOND REF) ,VAL ,(THIRD REF)))
  593.  
  594. (defmacro initialize-random-seed ()
  595.   #+(or PDP10 NIL) '(sstatus random 0)
  596.   #+CL () ;;(si:random-initialize si:random-array) obsolete. what now?
  597.   )
  598.  
  599. ;; These idiot macros are used in some places in macsyma.
  600. ;; The LISPM doesn't "go that high" with the series. DO NOT USE THESE
  601. ;; in new code. -gjc
  602. ;; NIL (common-lisp) has the nth accessors through to tenth, the rest
  603. ;; frobs through to rest5.  However i had thought that the latter were
  604. ;; obsolete, and had been going to flush them. --gsb
  605. #-(or cl ti NIL)
  606. (DEFMACRO EIGHTH  (FORM) `(CADDDR (CDDDDR ,FORM)))
  607. #-(or cl ti NIL)
  608. (DEFMACRO NINTH   (FORM) `(CAR (CDDDDR (CDDDDR ,FORM))))
  609. #-(or cl ti NIL)
  610. (DEFMACRO TENTH      (FORM) `(CADR (CDDDDR (CDDDDR ,FORM))))
  611. #-NIL
  612. (DEFMACRO REST5 (FORM) `(CDR (CDDDDR ,FORM)))
  613. (DEFMACRO REST6 (FORM) `(CDDR (CDDDDR ,FORM)))
  614.  
  615. ;;; We should probably move these into the compatibility package on
  616. ;;; mulitcs.
  617.  
  618. #+Multics
  619. (defmacro *break (breakp mess)
  620.   `(apply 'break `(,,mess ,',breakp)))
  621.  
  622. ;;; To satisfy GJC's speed mainia I resisted changing these in the
  623. ;;; code. -Jim.
  624.  
  625. #+Multics
  626. (defmacro +tyi (&rest args)
  627.   `(tyi ,@args))
  628.  
  629. #+Multics 
  630. (defmacro +tyo (&rest args)
  631.   `(tyo ,@args))
  632.  
  633. ;;; Let the compiler know that x is a fixnum. I guess it will also
  634. ;;; then optimize the call to +.
  635. #+Multics
  636. (defmacro fixnum-identity (x)
  637.   `(f+ ,x))
  638.  
  639. ;;this was not called.
  640. ;(defmacro get-symbol-array-pointer (x)
  641. ;  #+franz `(getd ,x)
  642. ;  #+nil `(si:get-symbol-array-pointer ,x)
  643. ;  #+cl `(symbol-array ,x)
  644. ;  #+maclisp `(get ,x 'array))
  645.  
  646.  
  647. (defmacro  mdefprop (sym val indicator)
  648.   `(mputprop ',sym ',val ',indicator))
  649.  
  650.  
  651. (DEFMFUN MPUTPROP (ATOM VAL IND)
  652.   (LET ((PROPS (GET ATOM 'MPROPS)))
  653.     (IF (NULL PROPS) (PUTPROP ATOM (SETQ PROPS (NCONS NIL)) 'MPROPS))
  654.     (PUTPROP PROPS VAL IND)))
  655.