This page contains the description of the following commands fact, fib, file-namestring, fillarray, fill_function, fillstring, fillvector, firstn, fix, float, floor, flush, flush, foo, for, format, fourier_outside, fourier_truncate, funcall,
This function assumes that n is a positive integer. It returns the product of all positive integers up to n. For instance (fact 10) is 3628800.
The Fibonacci function is defined by f(0)=0 f(1)=1 and f(n)=f(n-1)+f(n-2). An efficient algorithm is used. For instance (fib 20) is 6765. Note that the Fibonacci function is define d for negative numbers. If n is even f(-n)=f(n) and if n is odd f(-n)+f(n)=0.
The file-namestring function takes as argument a pathname (either an object of type pathname, or something that can be converted to a pathname, for instance a string or a symbol), like "foo/bar.gee" and returns the filename (here `bar.gee'). See pathname for examples.
The function takes two or three arguments. The first argument is an array, the second a function with one argument, and the last is a sequence. The behaviour is: For every I produced by the sequence, the value x=f(I) is computed, and x is stored in the table at indices I (of course it would be better if I is a valid list of indices). If the case where the array is of type lisp, the last argument is optional, if omitted the the sequence of all valid indices is used. See also here.
(1) x:=makearray("A", lisp, all, 2, 3); (1) <ARRAY: A> (2) f(a):= 100*car(a)+ car(cdr(a)); (2) <FUNCTION: f> (3) fillarray(a,f); (4) <ARRAY: A> (5) array_to_list(x); (5) [[2, 0, 2], [1, 0, 1], [0, 0, 0], [102, 1, 2], [101, 1, 1], [100, 1, 0]] (6) y:=makearray("A", hash, all, all,all); (6) <ARRAY: A> (7) S:=cartesian_product_seq([u,v,w],0...4); (7) <UninitializedSequence: CP, <vector: <UninitializedSequence: list, [u, v, w]>, <UninitializedSequence: interval, 0 ... 4>>> (9) fillarray(y,f,S); (9) <ARRAY: A> (11) array_to_list(y); (11) [[2 + 100 w, w, 2], [3 + 100 v, v, 3], [4 + 100 u, u, 4], [100 v, v, 0], [1 + 100 u, u, 1], [4 + 100 w, w, 4], [1 + 100 w, w, 1], [2 + 100 v, v, 2], [3 + 100 u, u, 3], [100 u, u, 0], [3 + 100 w, w, 3], [4 + 100 v, v, 4], [100 w, w, 0], [1 + 100 v, v, 1], [2 + 100 u, u, 2]] (12) fillarray(y,f); array_to_list : Makeseq : is hash : <ARRAY: A> (13) fillarray(y,f,0); apply_seq : not a sequence : 0 (14) fillarray(0,f,0); fillarray : not an array : 0
The fillstring function takes three or four arguments; the first argument is a string, or a wide string; the third argument is a character (an ASCII code if the first argument is a string, an extended code otherwise). Other arguments are integers; the function fills the string str, starting at n1 with the character c; if n2 is given this is the maximum number of characters to insert. The function can be defined as follows
(defun fillstring (str n1 cn . n2) (if n2 (setq n2 (car n2)) (setq n2 (lsh 2 30))) (unless (string str) (error 'fillstring errnsa str)) (unless (integerp n1) (error 'fillstring errnia n1)) (when (< n1 0) (error 'fillstring erroob n1)) (unless (integerp n2)( error 'fillstring errnia n2)) (when (< n2 0) (error 'fillstring erroob n2)) (unless (integerp c) (error 'fillstring errnia c)) (when (< c 0) (error 'fillstring erroob c)) (when (and (eq (type-of str) 'string) (> c 255)) (error 'fillstring erroob c)) (setq n2 (+ n1 n2)) (if (> n2 (strlen str)) (setq n2 (strlen str))) (for (i i1 1 (- n2 1)) (sset str i c)) str)
Example
[Endymion] (fillstring 'foo 1 2 3) fillstring : non string argument : foo [Endymion] (fillstring "foo" 1.2 2 3) fillstring : not a fixnum : 1.2 [Endymion] (fillstring "foo" 1 2 3.3) fillstring : not a fixnum : 3.3 [Endymion] (fillstring "foo" -1 2 3) fillstring : argument out of bounds : -1 [Endymion] (fillstring "foo" 1 2 -3) fillstring : argument out of bounds : -3 [Endymion] (fillstring "foobar" 1 #/X 2) fXXbar [Endymion] (fillstring "foobar" 0 #/Y 3) YYYbar [Endymion] (fillstring "foobar" 2 #/X) foXXXX [Endymion] (fillstring "foobar" 2 #/X 10) foXXXX [Endymion] (fillstring #"foobar" 2 1000 3) foϨϨϨr
The fillvector function takes three or four arguments; the first argument is a vector, or a wide vector; the third argument is a character (an ASCII code if the first argument is a vector, an extended code otherwise). Other arguments are integers; the function fills the vector str, starting at n1 with the character c; if n2 is given this is the maximum number is characters to insert. The function can be defined as follows
(defun fillvector (str n1 cn . n2) (if n2 (setq n2 (car n2)) (setq n2 (lsh 2 30))) (unless (vector str) (error 'fillvector errnsa str)) (unless (integerp n1) (error 'fillvector errnia n1)) (when (< n1 0) (error 'fillvector erroob n1)) (unless (integerp n2)( error 'fillvector errnia n2)) (when (< n2 0) (error 'fillvector erroob n2)) (setq n2 (+ n1 n2)) (if (> n2 (vlength str)) (setq n2 (vlength str))) (for (i i1 1 (- n2 1)) (vsert str i c)) str)
Example
[Endymion] (fillvector #[f o o b a r] 1 'x 2) #[f x x b a r] [Endymion] (fillvector #[f o o b a r] 0 'y 3) #[y y y b a r] [Endymion] (fillvector #[f o o b a r] 2 'x) #[f o x x x x] [Endymion] (fillvector #[f o o b a r] 2 'x 10) #[f o x x x x] [Endymion] (fillvector "foo" 2 'x 10) fillvector : not a vector : foo [Endymion] (fillvector #[f o o b a r] 1/2 'x 10) fillvector : not a fixnum : 1/2 [Endymion] (fillvector #[f o o b a r] -2 'x 10) fillvector : argument out of bounds : -2 [Endymion] (fillvector #[f o o b a r] 2 'x 1/2) fillvector : not a fixnum : 1/2 [Endymion] (fillvector #[f o o b a r] 2 'x -1) fillvector : argument out of bounds : -1
The firstn function takes two arguments. It returns the list formed of the first n elements of the list L. The first argument can be negative (result is the empty list) but it must be a small integer. If the argument is too big, the whole list is returned. The function could be defined as
(defun firstn (n l) (cond ((null l) ()) ((<= n 0) ()) (true (cons (car l) (firstn (1- n) (cdr l)))))) ;; alternate version, with all the tests (defun firstn (n l) (if (neq (type-of n) 'fix) (error 'firstn errnia n)) (let ((res ())) (while (and (> n 0) (consp l)) (setq n (- n 1) res (cons (car l) res) l (cdr l))) (nreverse res)))
Example
[Endymion] (firstn 1/3 '(1 2 3)) firstn : not a fixnum : 1/3 [Endymion] (firstn 4 '(1 2 3)) (1 2 3) [Endymion] (firstn 2 '(1 2 3)) (1 2) [Endymion] (firstn 0 '(1 2 3)) () [Endymion] (firstn -10 '(1 2 3)) () [Endymion] (setq l '(1 2 3)) (1 2 3) [Endymion] (eq l (firstn 10 l)) () [Endymion] (equal l (firstn 10 l)) true
The fix function converts its argument into an integer; it is identical to truncate.
The float function converts its argument into a floating point number.
[Endymion] (float 1.5L0) 1.5 [Endymion] (float 1.5d0) 1.5 [Endymion] (float 3/2) 1.5 [Endymion] (float (fact 100)) 9.33262154439442e+157 [Endymion] (float "12") float : not a real number : 12 [Endymion] (float #C(1 2)) float : not a real number : [2i+1]
All three functions floor, ceiling and truncate take a real number as argument. They return the integer part of it. If the argument is a BigFloat, the result is a BigFloat of the same kind, otherwise it is an integer. Rounding is towards 0 for truncate, minus infinity for floor and plus infinity for ceiling
[Endymion] (floor 1.2E0) 1 [Endymion] (floor 1.2L0) 1.L0 [Endymion] (floor 1.2d0) 1.D0 [Endymion] (ceiling 1.2E0) 2 [Endymion] (ceiling 1.2L0) 2.L0 [Endymion] (ceiling 1.2D0) 2.D0 [Endymion] (truncate 1.2e0) 1 [Endymion] (truncate 1.2l0) 1.L0 [Endymion] (truncate 1.2d0) 1.D0 [Endymion] (truncate 12/10) 1 [Endymion] (truncate -12/10) -1 [Endymion] (floor 12/10) 1 [Endymion] (ceiling 12/10) 2 [Endymion] (floor -12/10) -2 [Endymion] (ceiling -12/10) -1 [Endymion] (ceiling 100) 100 [Endymion] (floor 100) 100 [Endymion] (truncate 100) 100 [Endymion] (floor 'x) truncate : not a real number : x [Endymion] (ceiling 'x) truncate : not a real number : x [Endymion] (truncate 'x) truncate : not a real number : x
See eol.
This function is the flush ITsoft used by the symbolic printer. See description of #:display:eol.
In symbolic mode, when an unknown symbol like foo is seen for the first time, a new fsymbol (a formal symbol) is created, with the name foo, it is remembered in some list; the value of this symbol as used by the compiler is the fsymbol. If the symbol is set, it will be added to another list; the value is put on the CVAL of the symbol;
(1) foo:= foo(foo,bar); (1) foo(foo, bar) (2) endymion_names; (2) [Infinity, %e, %i, t, apply, foo, bar] (3) endymion_values; (3) [foo]
In Lisp mode, you cannot use an undefined symbol. After the commands above are executed, foo is defined as a variable, but not as a function, and bar is undefined. Thus you will see the following
[Endymion] foo #:fexpression:#[foo (foo . bar)] [Endymion] (foo) eval : undefined function : foo [Endymion] bar eval : undefined variable : bar
There is a symbolic macro of the same name described under do.
The for macro takes at least two arguments. The first argument is a list of length four. This list should contain a variable, and three quantities that evaluate to a real number. The remaining of the body (the quantities x1 x2 ... xn) is evaluated in a context where var is init plus k times incr, for k equals to 0, 1, 2, etc. It is an error if incr is zero. If incr is positive, evaluation is done as long as var is less or equal than last; otherwise the greater or equal predicate is used.
The expansion of for depends on the arguments. The easy case is when the increment is an integer or a floating point number. In this case, the expansion is of the form (let ((var init))(while (<= var ...) ...)); the predicate could also be >=. Otherwise, signum is used to find the sign, and selectq to switch. Quantities init, incr and last are evaluated only once, unless they are constant; this means that their values may be put in temporary variables.
[Endymion] (for (i 1 2 6) (print i)) 1 3 5 () [Endymion] (for (i 6 -2 1) (print i)) 6 4 2 () [Endymion] (setq A '(for (i 6 -2 10) (print i))) (for (i 6 -2 10) (print i)) [Endymion] (eval A) () [Endymion] A ((#:system:lambda 1 (i) (while (>= i 10) (print i) (setq i (+ i -2)))) 6) [Endymion] (setq x '(for (i (foo) (bar) (gee)) etc etc)) (for (i (foo) (bar) (gee)) etc etc) [Endymion] (eval x) eval : undefined function : foo [Endymion] x ((#:system:lambda 3 (i g16 g15) (selectq (signum g15) (1 (while (<= i g16) etc etc (setq i (+ i g15)))) (-1 (while (>= i g16) etc etc (setq i (+ i g15)) )) (true (error 'for bad increment g15)))) (foo) (gee) (bar)) [Endymion] (defun foo() "Foo") foo [Endymion] (defun gee() "gee") gee [Endymion] (defun bar()"bar") bar [Endymion] (eval x) signum : not a number : bar [Endymion] x ((#:system:lambda 3 (i g16 g15) ((#:system:lambda 1 (g17) (cond ((eq g17 '1) (while (<= i g16) etc etc (setq i (+ i g15)))) ((eq g17 '-1) (while (>= i g16 ) etc etc (setq i (+ i g15)))) (true (error 'for bad increment g15)))) ( signum g15))) (foo) (gee) (bar)) [Endymion] (for) for : wrong number of arguments : 0 this should be at least 2 [Endymion] (for (1 2 3) 4) for : bad argument list : (1 2 3) [Endymion] (for (1 2 3 5) 6) eval : not a variable : 1
The format function takes some arguments; the first argument is converted to a string, and special characters in this string are replaced by the value of other arguments. Inside the mforma function, that is called implicitly by the symbolic printer, the function is called on every list, that starts with format, and text is added in front. Example:
[Endymion] (setq x '(foo (format 'a~~b) bar)) (foo (format 'a~~b) bar) [Endymion] (mforma x) (foo (text 'a ~ b) bar)
In the example above, the argument list of format contains a single element, a list whose CAR is quote. After conversion to a string, we get a string with 5 characters. At a given moment we have some values: CS (the control string, initialised to the first argument), AL (the argument list, contains initially remaining arguments), and PR (partial result, initially empty). The format function uses the tilde character as prefix character for splitting the CS. When the end of the string is reached, the PR is returned. If the CS does not start with a tilde, all characters up to the tilde (or end of string) are concatenated into a string that is added to PR.
In the case of ~~ a tilde is added to the PR. In the case ~., nothing is inserted. In the case of ~A the next element of AL is added. If the list becomes empty, nil is used instead. Superfluous elements in the list are silentlty discarded. Variants of ~A include ~p, ~q, ~Z, ~Q. These are currently not implemented. Variants ~f, ~F, ~g, and ~G call use defined functions, for instance #:mforma:formatf, see example below. Variants ~r, ~t, ~b, and ~s produce a list, containing the symbol font, the argument and a string, that can be \rm, \tt, \bf, or \sl. Note that ~[ behaves like ~A, but, if the argument is a list, it adds an open bracket in front.
You can say ~:[A, ~:vA, ~:mA, or ~:A, whre `A' can be replaced by one if its variants. Currently, ~:mA, is equivalent to ~:A (this will change in the future), and ~:A is the same as ~A. In the case of ~:[A, ~:vA, the argument should be a list or vector respectively, and each element is formatted using the given specification. The bracket operator is prepended to the result. As a result, if you call display on the list (format "~:vA" #[1 2 3]), you will see [1, 2, 3].
In the case of ~E the value of errexp is inserted in PR, in the case of ~E the value of errexp1 is inserted; in the case of ~T the first element of AL is inserted; in these cases the value of AL is unchanged. In the case of ~S, nothing is added, but the head of AL is discarded. In the case of ~D, the head of AL is added to AL, and PR is left unchanged. In the case of ~@ the head of PR is removed and added to AL; thus it can be used again. In the case of ~+ or ~- the next element of AL is converted into a string, and added to CS; in the case of a minus sign, the new string is added to the end of the old one; in the case of a plus sign, the new string is added to CS before the unread part.
In the case of ~P, the value of the next argument is considered. If this is an integer greater than one, an `s' is added to PR (if the last element of PR is a string, say 'foo', it will be replaced by `foos'; perhaps, one day, the program will replace `foot' by `feet'). In the case of ~B, three values are taken from AL. If the first-argument is non-nil, then the second, otherwise the third, is pushed to PR. In the case ~C, three values are read, say a, b, c; the second should be an association. If a is associated to X, then X is added to PR, otherwise c is added to PR.
[Endymion] (format "x~~~~y~A~Az" 1 2) (x ~ ~ y 1 2 z) [Endymion] (format "~A~A" 1 2 3) (1 2) [Endymion] (format "~A~.~.~.~.~A" 1 2 3) (1 2) [Endymion] (format "x~.y") (x y) [Endymion] (format "~A~A~A~A" 1 2 3) (1 2 3 ()) [Endymion] (format "~p~q~Q~Z" 1 2 3 4) ((unimplemented p 1) (unimplemented q 2) (unimplemented Q 3) (unimplemented Z 4)) [Endymion] (defun #:mforma:formatf(x) (list x 'f)) #:mforma:formatf [Endymion] (defun #:mforma:formatF(x) (list x 'F)) #:mforma:formatF [Endymion] (defun #:mforma:formatg(x) (list x 'g)) #:mforma:formatg [Endymion] (defun #:mforma:formatG(x) (list x 'G)) #:mforma:formatG [Endymion] (format "~f~F~g~G" 1 2 3 4) ((1 f) (2 F) (3 g) (4 G)) [Endymion] (format "~[~[" 1 '(2 3)) (1 ([ 2 3)) [Endymion] (format "~r~t~b~s" 1 2 3 4) ((font 1 \rm) (font 2 \tt) (font 3 \bf) (font 4 \sl)) [Endymion] (setq errexp "A" errexp1 "B") B [Endymion] (format "~E~e" ) (A B) [Endymion] (format "~T~T~T~T~A~A" 1 2) (1 1 1 1 1 2) [Endymion] (format "~A~S~S~S~A" 1 2 3 4 5) (1 5) [Endymion] (format "~D~D~D~D~A~A~A~A~A~A~A~" 1 2 3 4 5) (1 1 1 1 1 2 3) [Endymion] (format "~B~@~-~Ab" true "FOO~ABAR" 0 12) (12 bFOO () BAR) [Endymion] (format "~B~@~+~Ab" true "FOO~ABAR" 0 12) (FOO 12 BAR) [Endymion] (format "++~:[f++" '(1 2 3)) (++ ([ (1 f) (2 f) (3 f)) ++) [Endymion] (format "++~:vf++" '#[1 2 3]) (++ ([ (1 f) (2 f) (3 f)) ++) [Endymion] (format "++~:f++" '#[1 2 3]) (++ (#[1 2 3] f) ++) [Endymion] (format "++~:mf++" '#[1 2 3]) (++ (#[1 2 3] f) ++) [Endymion] (format "1~P2~P and ~A~P~A~P" 2 0 "X" 2 "Y") (1s 2 and Xs Y) [Endymion] (format "1~P2~P and ~A~P~A~P" 2 13/7 'X 2 'Y) (1s 2 and X s Y) [Endymion] (format "~B~B" 1 2 3 () 5 6) (2 6) [Endymion] (format "~C~B" 1 '((1 a) (2 b) (3 c)) 3 () 5 6) ((a) 6) [Endymion] (format "~C~B" 17 '((1 a) (2 b) (3 c)) 3 () 5 6) (3 6)
Assume that f=sum a_k z^k is a sequence of Fourier coefficients. This command takes the tilde of f (replaces z by 1/z, takes complex conjugate, divides by z). Then, it replaces z by 1/z and and ignores negative coefficients. Said otherwise, the result is \bar a1 +\bar a2 z+\bar a3z^2+.... The function returns the argument unchanged if it is not a Fourier series.
(1) x:=#PFC -3 5 1.3 4.3 1.2 4.2 1.1 4.1 1.0 4.0 2.1 5.1 2.2 5.2 2.3 (1) 5.3 2.4 5.4 2.5 5.5; -3 -2 -1 (1) (1.3 + 4.3 %i) z + (1.2 + 4.2 %i) z + (1.1 + 4.1 %i) z + 1 + 4 %i 2 3 + (2.1 + 5.1 %i) z + (2.2 + 5.2 %i) z + (2.3 + 5.3 %i) z + (2.4 + 5.4 %i) 4 5 *z + (2.5 + 5.5 %i) z (3) fourier_truncate(x,0); 2 (3) 1.1 + 4.1 %i + (1.2 + 4.2 %i) z + (1.3 + 4.3 %i) z (4) fourier_truncate(x,1); 2 3 (4) 1 + 4 %i + (2.1 + 5.1 %i) z + (2.2 + 5.2 %i) z + (2.3 + 5.3 %i) z 4 5 + (2.4 + 5.4 %i) z + (2.5 + 5.5 %i) z (5) fourier_truncate(x,-1); 2 3 (5) 1 + 4 %i + (1.1 + 4.1 %i) z + (1.2 + 4.2 %i) z + (1.3 + 4.3 %i) z (7) fourier_outside(x); 2 3 (7) 2.1 - 5.1 %i + (2.2 - 5.2 %i) z + (2.3 - 5.3 %i) z + (2.4 - 5.4 %i) z 4 + (2.5 - 5.5 %i) z (9) #tilde(x); -5 -4 -3 (9) (2.5 - 5.5 %i) z + (2.4 - 5.4 %i) z + (2.3 - 5.3 %i) z -2 -1 + (2.2 - 5.2 %i) z + (2.1 - 5.1 %i) z + 1 - 4 %i + (1.1 - 4.1 %i) z 2 3 + (1.2 - 4.2 %i) z + (1.3 - 4.3 %i) z (10) fourier_truncate(#tilde(x),0); 2 3 (10) 2.1 - 5.1 %i + (2.2 - 5.2 %i) z + (2.3 - 5.3 %i) z + (2.4 - 5.4 %i) z 4 + (2.5 - 5.5 %i) z
This function returns the first argument unless it is a Fourier series. Let's assume f=\sum a_k z^k. If s is a positive (small) integer, it returns the part with non-negative exponents (a0+a1z+a2z^2+...). If s is a negative, returns the other part, in the form a0+a-1z+a-2z^2+... In all other cases, returns a-1+a-2z+a-3z^2+... Note that fourier_truncate(#tilde(x),0); is the same as fourier_outside(x), see fourier_outside .
The funcall function takes at least one argument. This argument should be a function. It will be applied to the remaining arguments. An expression like (funcall 'foo bar) is equivalent to (foo bar), except that special forms and macros are not allowed. In the case (foo bar), the bar argument is evaluated if foo is found to be a function of one argument. In the case of funcall, all arguments are evaluated, before testing that the first argument can be applied.
[Endymion] (funcall) funcall : wrong number of arguments : 0 this should be at least 1 [Endymion] (funcall car) eval : undefined variable : car [Endymion] (funcall 'car) car : wrong number of arguments : 0 this should be 1 [Endymion] (funcall 'if) funcall : undefined function : if [Endymion] (funcall 'ifn) funcall : undefined function : ifn [Endymion] (funcall 'cons 1 2) (1 . 2) [Endymion] (funcall 'version) 0.03 [Endymion] (funcall 'ibase) 10 [Endymion] (funcall (if (<= 12 13) 'car 'cdr) '(1 . 2)) 1 [Endymion] (let ((ibase 10)) (funcall 'ibase 7)) 7 [Endymion] (funcall (lambda (x) (list x x)) 1) (1 1) [Endymion] (funcall (lambda (x y) (list y x)) 1 2) (2 1)
back to home page © INRIA 2005, 2006 Last modified $Date: 2009/01/08 17:43:30 $