This page contains the description of the following commands abs, absolute-pathp, acos, acosh, add, addn, addl, addprop, add-to-it-list, add-to-path, alloc_function, alphalessp, alphalessp1, and, any, append, append2, append1, apply, apply_seq, apropos, array_info, array_name, array_to_list, array_to_seq, arg, args, arguments, asin, asinh, assoc, assq, atan, atanh, atan2, atom,
The Lisp and symbolic abs functions return the absolute value of the argument. The Lisp function requires a number as argument; the symbolic function is an extension of it.
[Endymion] (abs 10) 10 [Endymion] (abs -10) 10 [Endymion] (abs 1.2L0) 0.12L1 [Endymion] (abs -1.2L0) 0.12L1 [Endymion] (abs #C(3 4)) 5 [Endymion] (equal (abs (exp #C(30. 40.))) (exp 30.0)) true [Endymion] (phase (exp #C(30. 2.5))) 2.5 [Endymion] (abs "foo") abs : not a number : foo
The following rules are used to simplify an absolute value: abs(abs(x)) simplifies to abs(x); abs(a^b) simplifies to abs(a)^b if the exponent is an integer, this can be simplified again. In the case of a product, the absolute value of each factor is computed, these quantities are multiplied together.
(1) abs(abs(a)); (1) |a| (2) abs(a^2)=abs(a^3); 2 3 (2) a = |a| (3) abs(a*abs(a^2))=abs(a*abs(a^3)); 3 4 (3) |a| = a (4) abs(a^2*abs(a^2))=abs(a^2*abs(a^3)); 4 5 (4) a = |a| (5) abs(a^2*abs(a^2)*b*abs(c))=abs(a^2*abs(a^3)*b*abs(c)); 4 5 (5) |a b c| = |a b c| (6) abs(-a)=abs(-3*a); (6) |a| = |3 a| (7) abs(a^(3/2))* abs(a^(3/2)) * abs(a^(3/2)); 3 3/2 (7) a |a | (8) abs(%e)=abs(%i); (8) %e = 1
The absolute-pathp function takes one argument. It calls expand-path. If this fails, the return value is false. Otherwise, we have a character string. The returns value is true if the first character is slash, false otherwise. The function could be defined as
(defun absolute-pathp (x) (let ((y (expand-path x))) (if (and (stringp y) (> (strlen y) 0) (eq (sref y 0) #//)) true false)))
Example
[Endymion] (absolute-pathp 'foo) () [Endymion] (absolute-pathp '/foo) true [Endymion] (absolute-pathp "foo") () [Endymion] (absolute-pathp "/foo") true [Endymion] (absolute-pathp "$HOME") true [Endymion] (absolute-pathp "~grimm") true [Endymion] (absolute-pathp "~unknown") () [Endymion] (absolute-pathp "$SHELL") true [Endymion] (expand-path "$SHELL") /bin/bash [Endymion] (absolute-pathp 123) () [Endymion] (absolute-pathp '("/")) ()
The add-to-it-list function takes one argument, that is a symbol or a list of symbols. It adds them to the front of the ITsoft list #:sys-package:itsoft (unless these are already in the list). The function could be defined as follows:
(defun add-to-it-list (L) (if (consp L) (progn (while (consp L) (add-to-it-list (car L)) (setq L (cdr L))) #:sys-package:itsoft) (if (not (symbolp L)) (error 'add-to-it-list errnva L)) (unless (or (memq L #:sys-package:itsoft) (and (consp #:sys-package:itsoft) (eq L (cdr (tail #:sys-package:itsoft))))) (if #:sys-package:itsoft (setq #:sys-package:itsoft (cons L #:sys-package:itsoft)) (setq #:sys-package:itsoft (list L #:sys-package:itsoft)))) #:sys-package:itsoft))
Example
[Endymion] (#:sys-package:itsoft) (foo bar) [Endymion] (add-to-it-list 'a) (a foo bar) [Endymion] (add-to-it-list 'b) (b a foo bar) [Endymion] (add-to-it-list 'b) (b a foo bar) [Endymion] (add-to-it-list '(a b c)) (c b a foo bar) [Endymion] #:sys-package:itsoft (c b a foo bar)
This function returns the sum of its two arguments. The Lisp function accepts only numbers (polynomials, matrices, etc), the symbolic function accepts symbolic expressions.
(1) add(1=2,2=1); (1) 3 = 3 (2) add(); add : wrong number of arguments : 0 this should be 2 (3) add("foo",true); Bad type in arithmetic function: string for foo Bad type in arithmetic function: boolean for TRUE Error : Cannot compute : add(foo, TRUE)
This function returns the sum of the items of its argument. The Lisp function ca be called as (addl (list 1 2 3)), we show below examples for the symbolic function. Note in line (6) theat the compiler has replaced the call to addl by a call to the + function.
(1) L:=[x,y,z]; << addl([x,y,z]), addl(L) >>; (1) [x, y, z] (2) <<x + y + z, x + y + z>> (3) y:="true"?; z:=false?; L:=[x,y,z]; (5) [x, true, false] (6) addl([x,y,z]); addl(L); + : Cannot compute : +(x, false, true) addl : Cannot compute : +(x, false, true)
This function returns the sum of its arguments. It is the functional version of the + operator
(1) [addn(), addn(10), addn(10,100), addn(10,100,1000)];
(1) [0, 10, 110, 1110]
The addprop function takes three arguments. The first one has to be a symbol. It adds to the property list of this symbol a new pair (key,value). It returns the value. For an example, see putprop.
The add-to-path function takes one argument. If this argument is not a name, the function returns nil. Otherwise it adds a component in front of #:system:llib-directory #:system:llmod-directory, #:system:llobj-directory. This component is obtained by append a suffix to the argument (one of llib, llmod, llobj). A final slash in the argument is optional.
[Endymion] (add-to-path "/foo/bar") /foo/bar/ [Endymion] (add-to-path 12) () [Endymion] #:system:llib-directory (/foo/bar/llib/ ./ /user/grimm/home/cvs/endymion/lisp/) [Endymion] #:system:llmod-directory (/foo/bar/llmod/ ./ /user/grimm/home/cvs/endymion/lisp/) [Endymion] #:system:llobj-directory (/foo/bar/llobj/ ./ /user/grimm/home/cvs/endymion/lisp/)
The function alphalessp takes two arguments, they are strings (or converted to strings). The function returns zero in the case where the strings are the same, minus one if the first string is smaller than the second and plus one otherwise. The alphalessp1 function behaves the same, but it returns true instead of zero or minus one, and false instead of plus one.
(defun alphalessp1 (x y) (if (eq (alphalessp x y) 1) () true)) (defun alphalessp (x y) (alpha-aux (explode x) (explode y))) (defun alpha-aux (x y) (cond ((and (null x) (null y)) 0) ((null x) -1) ((null y) 1) ((< (car x) (car y)) -1) ((> (car x) (car y)) 1) (true (alpha-aux (cdr x) (cdr y)))))
Example
[Endymion] (alphalessp 1/2 "foo") -1 [Endymion] (alphalessp "foo" 1/2) 1 [Endymion] (alphalessp 'a 'a) 0 [Endymion] (alphalessp 'b 'a) 1 [Endymion] (alphalessp 'a 'b) -1 [Endymion] (alphalessp 'bb 'bbb) -1 [Endymion] (alphalessp 'bbb 'bb) 1 [Endymion] (alphalessp #"bbb" #"bb") 1 [Endymion] (alphalessp 1.25 1.3) -1 [Endymion] (alphalessp1 'a 'a) true [Endymion] (alphalessp1 'a 'b) true [Endymion] (alphalessp1 'b 'a) ()
The and special form evaluates its arguments one after the other. If one evaluation gives nil, evaluation stops, and this is the return value. Otherwise, the return value is the value of the last argument. If no argument is given, the value is true.
[Endymion] (and) true [Endymion] (and 1 2 3) 3 [Endymion] (and 1 () (car 0)) () [Endymion] (and (read) (read) (read)) 1 () () [Endymion] (and (read) (read) (read)) 1 2 3 3
The symbolic macros and and or can be used only inside a conditional. With two arguments, the expansion of a and b is if a then (if b then true else false) else false, the expansion of a or b is if a then true else (if b then true else false). Inside If, expansion is trivial (as seen in the example below). In the test below, variables a, b and c are undefined (hence evaluate to a symbol of the same name), and are not considered false in a conditional.
(1) If a or b and c then 1 else 2; Macro expansion -> a or b and c Macro expansion <- if a then true else (if b and c then true else false) Macro expansion -> b and c Macro expansion <- if b then (if c then true else false) else false (1) 1 (2) if(a and b or c) then 1 else 2; Macro expansion -> a and b or c Macro expansion <- if a and b then true else (if c then true else false) Macro expansion -> a and b Macro expansion <- if a then (if b then true else false) else false (2) 1 (3) If a and b or c then 1 else 2; (3) 1 (4) If a or b and c then 1 else 2; (4) 1
The any function returns true if any application of f to the k-th element of the arguments returns true; see map. See the compiler for the symbolic macro.
The append function takes a variable number of arguments. Non-list arguments are ignored. Other arguments are appended. All arguments but the last are copied. The function could be defined as
(defun append L (if (null L) () (if (null (cdr L)) (car L) (append2 (car L) (apply 'append (cdr L)))))) (defun append2 (l1 l2) (if (atom l1) l2 (cons (car l1) (append2 (cdr l1) l2))))
Example
[Endymion] (append '(a b c) '(x y)) (a b c x y) [Endymion] (append 1 '(x y) 2 '(z)) (x y z) [Endymion] (append 1 '(x y . u) 2 '(z . v)) (x y z . v) [Endymion] (setq l1 '((a) b c)) ((a) b c) [Endymion] (eq (append l1 ()) l1) () [Endymion] (equal (append l1 ()) l1) true [Endymion] (eq (car (append l1 ())) (car l1)) true [Endymion] (append) ()
(1) append([1,2],[3,4],[5,6]);
(1) [1, 2, 3, 4, 5, 6]
The append2 function is the version with two arguments of append.
[Endymion] (append2 '(1 2 3) '(4 5 6)) (1 2 3 4 5 6) [Endymion] (append2) append2 : wrong number of arguments : 0 this should be 2
The append1 function takes two arguments. It adds the second argument at the end of the first argument (if the first argument is not a list, the empty list will be used instead). It can be defined as
(defun append1 (x y) (append x (cons y ()))
Example
[Endymion] (append1) append1 : wrong number of arguments : 0 this should be 2 [Endymion] (append1 '(1 2) 3) (1 2 3) [Endymion] (append1 '(1 2 . xx) '(yy . zz)) (1 2 (yy . zz)) [Endymion] (append1 'x 'y) (y)
The apply function takes two arguments. The first one should be a function, the second an argument list. The function is applied to the list. The symbolic function expects a symbolic list; as the following example shows, fn can be a Lisp function: apply(#'print, [1,2]); See also funcall.
[Endymion] (apply 'fn '(1 2 . 3)) apply : bad end of list : (fn 1 2 . 3) [Endymion] (apply) apply : wrong number of arguments : 0 this should be 2 [Endymion] (apply 'car ()) car : wrong number of arguments : 0 this should be 1 [Endymion] (apply 'if ()) apply : undefined function : if [Endymion] (apply 'ifn ()) apply : undefined function : ifn [Endymion] (apply 'cons '(1 2)) (1 . 2) [Endymion] (apply 'ibase ()) 10 [Endymion] (apply (if (<= 12 13) 'car 'cdr) '((1 . 2))) 1 [Endymion] (apply (lambda (x) (list x x)) '(1)) (1 1) [Endymion] (apply (lambda (x y) (list y x)) '(1 2)) (2 1)
The call apply_seq(f,A,w) constructs a sequence B such that the i-th element Bi is f(Ai,w), where Ai is is the i-th element of A.
(1) F(x,y):= [x,y]; (1) <FUNCTION: F> (2) A:=apply_seq(F,1...10, 17); (2) <UninitializedSequence: apply, <FUNCTION: F>, <UninitializedSequence: interval, 1 ... 10>, 17> (3) a:=makeseq(A); (3) <InitializedSequence: apply, <FUNCTION: F>, <InitializedSequence: interval, 1, 10, 1>, 17> (4) seq_to_list(a); (4) [[1, 17], [2, 17], [3, 17], [4, 17], [5, 17], [6, 17], [7, 17], [8, 17], [9, 17], [10, 17]]
The apropos function takes zero, one, or two arguments. If no argument is given, the result is nil. The same is true if the first argument cannot be converted to a string. The apropos function considers all symbols that contain this string in their name. If the second argument is true, only useful symbols are taken (symbols that have a plist, a cval or a fval). If the second argument function, only functions are considered. If the second argument sym_function, only symbolic functions are considered. The return value of the the function is the symbolic list of these symbols.
(3) apropos("cons"); (3) [reconstruct_ring, btcons, constant, constantp, constants, xcons, check-cons, cons-to-bf, console, bf-to-cons, mcons, cons, cons, bfcons, makeconstant, consp, defcompconstant, ncons, defconstant] (4) apropos("cons",function); (4) [reconstruct_ring, constantp, xcons, cons-to-bf, bf-to-cons, mcons, cons, cons, makeconstant, consp, ncons, defconstant] (5) apropos("cons",sym_function); (5) [reconstruct_ring, cons] (6) apropos("cons",true); (6) [reconstruct_ring, constantp, constants, xcons, cons-to-bf, bf-to-cons, mcons, cons, cons, makeconstant, consp, ncons, defconstant]
This function returns informations about the array. See the array documentation for an example.
This function returns the name of the argument, it has to be an array.
(5) array_name(23); array_name : not an array : 23 (6) x:=makearray(w^2, lisp,all,12); (6) <ARRAY: w**2> (7) array_name(x); (7) w**2
Both functions array_to_seq and array_to_list take an array as arguments and construct a list of items. Each item is a list, say [a,b,c] where a== x[b,c], i.e. the value of the array at the positions b, c. The first function converts the list into a sequence. This is usually not needed. See also the array documentation.
(22) /* array initialisation omitted */ (22) array_to_list(x); (22) [[2, 0, 2], [1, 0, 1], [0, 0, 0], [102, 1, 2], [101, 1, 1], [100, 1, 0]] (23) array_to_seq(x); (23) <UninitializedSequence: array> (24) makeseq(%); (24) <InitializedSequence: list, [[2, 0, 2], [1, 0, 1], [0, 0, 0], [102, 1, 2], [101, 1, 1], [100, 1, 0]]> (25) for w in x do print(w); [2, 0, 2] [1, 0, 1] [0, 0, 0] [102, 1, 2] [101, 1, 1] [100, 1, 0] (25) done (26) array_to_seq(0); array_to_seq : not an array : 0 (27) array_to_list(0); array_to_list : not an array : 0
The construct arg(i) can be used in the conditional part of a symbolic macro, see the compiler. The construct arg(i) or args(i), or arguments(i) can be used in the body of a symbolic macro, see the compiler.
The arg function takes a variable number of arguments. These arguments are numbers. The result is a part of the list &nobind. Let's call this list l0. Each argument xi defines li as a function of li-1 as follows: if xi is positive, element number xi is chosen; if it is negative, the first minus xi elements are discarded. An error is signaled in the case where xi is too big in magnitude. The function could be defined as follows
(defun arg L (let ((x &nobind)) (while (consp L) (let ((y (car L))) (setq L (cdr L)) (if (not (integerp y)) (error 'arg errnia y)) (if (> y 0) (progn (setq y (- y 1)) (while (> y 0) (setq x (cdr x) y (- y 1))) (setq x (car x))) (while (< y 0) (setq x (cdr x) y (+ y 1)))))) x))
In general, arg is used inside a function, like test below. It is useful when compiling, because, in this case, the argument list is not created: (arg 2) returns the second argument found on the stack. Note how test can be defined so that at least 3 arguments are required.
[Endymion] (setq &nobind '((1 2 3) (4 5 6) (7 8 9))) ((1 2 3) (4 5 6) (7 8 9)) [Endymion] (arg) ((1 2 3) (4 5 6) (7 8 9)) [Endymion] (arg 1) (1 2 3) [Endymion] (arg 2) (4 5 6) [Endymion] (arg 3) (7 8 9) [Endymion] (arg 1 1) 1 [Endymion] (arg 1 2) 2 [Endymion] (arg 1 3) 3 [Endymion] (arg 1 0) (1 2 3) [Endymion] (arg 1 -1) (2 3) [Endymion] (arg 1 -2) (3) [Endymion] (arg 1 -3) () [Endymion] (arg 5) arg : illegal binding : ((1 2 3) (4 5 6) (7 8 9)) [Endymion] (arg -5) arg : illegal binding : ((1 2 3) (4 5 6) (7 8 9)) [Endymion] (arg 'foo) arg : not a fixnum : foo [Endymion] (defun test (#:system:nb-args -4) &nobind (list (arg 1) (arg 3))) test [Endymion] (test 1 2) test : wrong number of arguments : 2 this should be at least 3 [Endymion] (test 1 2 3 4) (1 3)
The four functions assq, assoc, rassq and rassoc take to arguments, an item and an association list. If the second argument is not a list, the result is nil. In the association list, all elements that are not conses are ignored. The function returns the first cons that matches; it returns nil if no cons matches. In the case of assq, a cons matches if its CAR is x, tested via eq; in the case of assoc, a cons matches if its CAR is x, tested via equal; in the case of rassq, a cons matches if its CDR is x, tested via eq; In the case of rassoc, a cons matches if its CDR is x, tested via equal. The functions could be defined as
(defun assq (x al) (cond ((atom al) ()) ((and (consp (car al)) (eq (caar al) x)) (car al)) (true (assq x (cdr al))))) (defun assoc (x al) (cond ((atom al) ()) ((and (consp (car al)) (equal (caar al) x)) (car al)) (true (assq x (cdr al)))))
Example
[Endymion] (setq x1 "foo" x2 '(bar)) (bar) [Endymion] (setq L '((a . b) (a . c) (1 . 2) (1 . 3) ("foo" . 4) (#.x1 5) [Endymion] (6 (bar)) (7 . #.x2))) ((a . b) (a . c) (1 . 2) (1 . 3) (foo . 4) (foo 5) (6 (bar)) (7 bar)) [Endymion] (assq 'a L) (a . b) [Endymion] (assoc 'a L) (a . b) [Endymion] (assq 1 L) (1 . 2) [Endymion] (assoc 1 L) (1 . 2) [Endymion] (assoc "foo" L) (foo . 4) [Endymion] (assq "foo" L) () [Endymion] (assq x1 L) (foo 5) [Endymion] (rassq 'C L) () [Endymion] (rassq 'c L) (a . c) [Endymion] (rassoc 'c L) (a . c) [Endymion] (rassq 2 L) (1 . 2) [Endymion] (rassoc 2 L) (1 . 2) [Endymion] (rassq '(bar) L) () [Endymion] (rassoc '(bar) L) (7 bar) [Endymion] (rassq x2 L) (7 bar)
The functions asin, acos and atan are the inverse trignometric functions. The functions asinh, acosh and atanh are the inverse hyperbolic functions. These functions take a real or complex number as argument. We describe also phase and atan2.
Since trigonometric functions are periodic, their inverse are not well defined. In the case of asin and acos, we use the C library if the argument is between -1 and 1. The asin function is defined as follows. Let x be the argument, y the square root of 1-x*x, s=ix+y, and a=-i*log(s). The sine of a is (s-1/s)/2i. By construction 1/s= y-ix, sin(a) is x. If x is real, greater than one in magnitude, then y is pure imaginary, its imaginary part is positive. Otherwise its real part is positive. It is easy to check that the real part of s is postive; this implies that the imaginary part of the log of s (hence the real part of a) is between -π/2 and π/2. By definiion, we have acos(x) is π/2-asin(x); this gives a number whse real part is between 0 and π
The definition of asinh is simpler. It is log(s), where s= x+y, y=sqrt(1+x*x). This gives a number whose imaginary part is between -π/2 and π/2. This is a real number if the argument is real. In the case of acosh, we compute a=log(s), where s= x+y, y=sqrt(x*x-1). We return either a or -a, the one that has positive imaginary part. The value of atanh(x) is half the log of (1+x)/(1-x). Imaginary part is between -π/2 and π/2.
Finally atan(x) is defined as follows. If a=-ilog(s), then tan(a)=(s*s-1)/(s*s+1)/i. This is x if y =sqrt(1+x*x) and s =(1+ix)/y. Real part is between -π/2 and π/2. If z is a complex number, with real part x, imaginary part y, then (phase z) is the same as (atan2 y x). The function atan2 takes two arguments, say y and x. It returns a such that sin(a)=Ly, and cos(a)= Lx for some L. This means tan(a)=y/x. In the case where x and y are real, then L is real, chosen positive. Real part is between -π and π; otherwise real part is between -π/2 and π/2.
[Endymion] (phase 1) 0 [Endymion] (phase -1) 3.14159265358979 [Endymion] (phase #C(1 -2)) -1.10714871779409 [Endymion] (atan2 -2 1) -1.10714871779409 [Endymion] (atan2 2 -1) 2.0344439357957 [Endymion] (asin 0.2L0) 0.201357920790330791455125552217623L0 [Endymion] (asin 2.0) [-1.31695789692482i+1.5707963267949] [Endymion] (asin #C(2.0 3.0)) [1.98338702991653i+0.570652784321097] [Endymion] (acos #C(2.0 3.0)) [-1.98338702991653i+1.0001435424738] [Endymion] (acos .5) 1.0471975511966 [Endymion] (acos -.5) 2.0943951023932 [Endymion] (asinh 1) 0.881373587019543 [Endymion] (asinh #C(1 2)) [1.06344002357775i+1.46935174436819] [Endymion] (asinh #C(1 -2)) [-1.06344002357775i+1.46935174436819] [Endymion] (acosh -1) [3.14159265358979i] [Endymion] (acosh 2) 1.31695789692482 [Endymion] (acosh #C(3 4.)) [0.93681246115572i+2.30550903124348] [Endymion] (atanh .5) 0.549306144334055 [Endymion] (atanh 1.5) [1.5707963267949i+0.80471895621705] [Endymion] (atanh #C(1.2 1.5)) [1.15088337628505i+0.282533380744472] [Endymion] (atan 1) 0.785398163397448 [Endymion] (atan #C(1 2)) [0.402359478108525i+1.33897252229449] [Endymion] (phase #C(3.62357754476674 9.32039085967226)) 1.2 [Endymion] (atan2 9.32039085967226 3.62357754476674) 1.2 [Endymion] (atan2 9.32039085967226 -3.62357754476674) 1.94159265358979 [Endymion] (atan2 -9.32039085967226 -3.62357754476674) -1.94159265358979 [Endymion] (atan2 -9.32039085967226 3.62357754476674) -1.2
The atom function takes one argument. It returns true if it is a non-list, it returns false if it is a list. The function could be defined as
(defun atom (x) (not (eq (type-of x) 'cons)))
Example
[Endymion] (atom '(foo)) () [Endymion] (atom "(foo)") true [Endymion] (atom 123) true [Endymion] (atom #[1 2 3]) true
back to home page © INRIA 2005, 2006 Last modified $Date: 2009/01/08 17:43:30 $