1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; The data in this file contains enhancments. ;;;;;
5 ;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;;
6 ;;; All rights reserved ;;;;;
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;; (c) Copyright 1981 Massachusetts Institute of Technology ;;;
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13 (macsyma-module utils
)
15 ;;; General purpose Lisp utilities. This file contains runtime functions which
16 ;;; are simple extensions to Lisp. The functions here are not very general,
17 ;;; but generalized forms would be useful in future Lisp implementations.
19 ;;; No knowledge of the Macsyma system is kept here.
21 ;;; Every function in this file is known about externally.
23 (defmacro while
(cond &rest body
)
28 (defun maxima-getenv (envvar)
29 #+gcl
(si::getenv envvar
)
30 #+ecl
(si::getenv envvar
)
31 #+allegro
(system:getenv envvar
)
32 #+(or cmu scl
) (cdr (assoc envvar ext
:*environment-list
* :test
#'string
=))
33 #+sbcl
(sb-ext:posix-getenv envvar
)
34 #+clisp
(ext:getenv envvar
)
35 #+(or openmcl mcl
) (ccl::getenv envvar
)
36 #+lispworks
(hcl:getenv envvar
)
37 #+abcl
(ext:getenv envvar
)
40 ;; CMUCL needs because when maxima reaches EOF, it calls BYE, not $QUIT.
43 #+(or cmu scl clisp
) (ext:quit
)
45 #+allegro
(excl:exit
0 :quiet t
)
46 #+(or mcl openmcl
) (ccl:quit
)
49 #+lispworks
(lispworks:quit
)
50 #+abcl
(cl-user::quit
)
55 ;;; F is assumed to be a function of two arguments. It is mapped down L
56 ;;; and applied to consequtive pairs of elements of the list.
57 ;;; Useful for iterating over property lists.
60 (do ((llt l
(cddr llt
)) (lans))
62 (push (funcall f
(car llt
) (cadr llt
)) lans
)))
64 ;;; Like MAPCAR, except if an application of F to any of the elements of L
65 ;;; returns NIL, then the function returns NIL immediately.
67 (defun andmapcar (f l
&aux d answer
)
69 ((null l
) (nreverse answer
))
70 (setq d
(funcall f
(car l
)))
71 (if d
(push d answer
) (return nil
))))
73 ;;; Returns T if either A or B is NIL, but not both.
76 (or (and (not a
) b
) (and (not b
) a
)))
78 ;;; A MEMQ which works at all levels of a piece of list structure.
80 ;;; Note that (AMONG NIL '(A B C)) is T, however. This could cause bugs.
81 ;;; > This is false. (AMONG NIL anything) returns NIL always. -kmp
86 (t (or (among x
(car l
)) (among x
(cdr l
))))))
88 ;;; Similar to AMONG, but takes a list of objects to look for. If any
89 ;;; are found in L, returns T.
93 ((atom l
) (member l x
:test
#'eq
))
94 (t (or (amongl x
(car l
)) (amongl x
(cdr l
))))))
96 ;;; Tests to see whether one tree is a subtree of another.
98 ;;; Both arguments should be well-formed cons trees (so no cycles). If supplied,
99 ;;; TEST is used as an equality predicate.
101 (defun subtree-p (branch tree
&key
(test #'eql
))
102 (or (funcall test branch tree
)
103 (and (not (atom tree
))
105 :test
(lambda (x y
) (subtree-p x y
:test test
))))))
107 ;;; Takes a list in "alist" form and converts it to one in
108 ;;; "property list" form, i.e. ((A . B) (C . D)) --> (A B C D).
109 ;;; All elements of the list better be conses.
113 (t (list* (caar l
) (cdar l
) (dot2l (cdr l
))))))
115 ;;; (C-PUT sym value selector)
117 ;;; Make a symbol's property list look like a structure.
119 ;;; If the value to be stored is NIL,
120 ;;; then flush the property.
121 ;;; else store the value under the appropriate property.
124 (defun cput (bas val sel
)
129 (putprop bas val sel
))))