This page contains the description of the following commands bezout, block, block-with-llink, bltstring, bltvector, bol, boundp, break, BREAK, buildq, bye,
This finds u v such that ua+vb=p, where p is the gcd of a and b; u is less than b/p and v is less than a/p (in magnitude). Return value is the list (p, u, v).
[Endymion] (bezout (fib 20) (fib 21)) (1 4181 -2584) [Endymion] (fib 19) 4181 [Endymion] (fib 18) 2584 [Endymion] (bezout 11 -13) (1 6 5) [Endymion] (bezout 10 200) (10 1 0)
The block special form takes at least two arguments, a tag name and some expressions x1, x2, etc. The block-with-llink command takes an additional argument, the llink-reference. These two special forms establish a lexical scope, associated to a name; their first argument must be a symbol, the name of ther scope. This scope has also a unique identifier, the value of which will be put in the second argument of block-with-llink, which must be a symbol. The special form return-from takes as first argument a symbol, the name of a valid lexical block. The special form return-from-llink takes as second argument, the unique identifier mentioned above. Example of what can go wrong:
[Endymion] (return-from) return-from : wrong number of arguments : 0 this should be at least 2 [Endymion] (return-from 1 2 3) return-from : not a symbol : 1 [Endymion] (return-from-llink) return-from-llink : wrong number of arguments : 0 this should be at least 3 [Endymion] (return-from-llink 1 2 3 4) return-from-llink : not a symbol : 1 [Endymion] (block) block : wrong number of arguments : 0 this should be at least 2 [Endymion] (block 1 2 3) block : not a symbol : 1 [Endymion] (block-with-llink) block-with-llink : wrong number of arguments : 0 this should be at least 3 [Endymion] (block-with-llink 1 2 3 4) block-with-llink : not a symbol : 1 [Endymion] (block-with-llink foo 2 3 4) block-with-llink : not a variable : 2 [Endymion] (return-from foo bar) return-from : no lexical scope : foo [Endymion] (return-from-llink foo 0 bar) return-from-llink : no lexical scope : foo
In the case of (block a x1 ... xn) or (block-with-llink a b x1 ... xn), the quantities xi are evaluated in order, and the result of the last evaluation is the value of the block. Evaluation can be interrupted by return-from. The first argument of return-from or return-from-llink is tested. If this is not the name of a valid block, an error is signalled. Otherwise, remaining arguments are evaluated, and the result of this evaluation becomes the result of the block.
[Endymion] (defun foo (x) (if (eq x 1) (return-from foo (print x) 2)) [Endymion] (if (eq x 2) (return-from foo (print x) 4)) [Endymion] (print x)) foo [Endymion] (block foo (block bar (foo 1) 17) 18) 1 2 [Endymion] (block foo (block bar (foo 2) 17) 18) 2 4 [Endymion] (block foo (block bar (foo 3) 17) 18) 3 18
Examples from LeLisp. These examples use lambda, because the lexical link was associated to functions. The interesting function is cexl. It takes three arguments, the first two arguments are functions, and return from some tag named here. More than one such tags is active, the llink is used to select one. You can look at this page for a full trace of this example.
[Endymion] (block a (let ((f (lambda (u) (return-from a (+ u 10))))) [Endymion] (funcall f 2) 3)) 12 [Endymion] (block true (let ((f (lambda (u) (return-from true (+ u 10))))) [Endymion] (funcall f 2) 3)) 12 [Endymion] (block-with-llink foo bar [Endymion] (let ((f (lambda (u) (return-from-llink foo bar (+ u 10))))) [Endymion] (funcall f 2) 4)) 12 [Endymion] (defun cexl (f g x) [Endymion] (if (= x 0) [Endymion] (funcall f) [Endymion] (let ((v ())) [Endymion] (block-with-llink here v [Endymion] (+ 5 (cexl g `(lambda () (return-from-llink here ',v 4)) [Endymion] (- x 1))))))) cexl [Endymion] (cexl () () 2) 4 [Endymion] (cexl () () 3) 9
See block above.
The bltstring function takes three, four or five arguments. The first one must be a string, the third one will be coerced to a string (a wide string if the first argument is a wide string). Other arguments are non-negative integers. The function copies character at position n2+i of the second string into position ni+i in the first string. As many characters as possible are copied. If five argument are given, the last one is the maximum number of characters that can be copied. If only three arguments are give, the default value of n2 is zero. The first argument is returned. The function can be defined in Lisp as follows:
(defun bltstring (str1 n1 str2 . rest) (let ((n2) (n3)) (if rest (setq n2 (car rest) n3 (cdr res)) (setq n2 0 n3 ())) (unless (integerp n1) (error 'bltstring errnia n1)) (when (< n1 0) (error 'bltstring erroob n1)) (unless (integerp n2) (error 'bltstring errnia n2)) (when (< n2 0) (error 'bltstring erroob n2)) (if n3 (setq n3 (car n3)) (setq n3 (lsh 2 30))) (unless (integerp n3) (error 'bltstring errnia n3)) (when (< n3 0) (error 'bltstring erroob n3)) (if (eq (type-of str1) 'wstring) (setq str2 (catenate #"" str2)) (if (eq (type-of str2) 'string) (setq str2 (catenate str2)) (error 'bltstring 'errnsa str2))) (setq imax n3) (if (> imax (- (strlen str1) n1)) (setq imax (- (strlen str1) n1))) (if (> imax (- (strlen str2) n2)) (setq imax (- (strlen str2) n2))) (for (i 0 1 (- imax 1)) (sset str1 (+ n1 i) (sref str2 (+ n2 i)))) str1))
Examples
[Endymion] (bltstring "foo" 0 "bar" 0 0) foo [Endymion] (bltstring "foo" 0 "bar" 0 0 1) bltstring : wrong number of arguments : 6 this should be at most 5 [Endymion] (bltstring "foo" 0) bltstring : wrong number of arguments : 2 this should be at least 3 [Endymion] (bltstring 'foo 0 "bar" 0 1) bltstring : non string argument : foo [Endymion] (bltstring "foo" 1/2 "bar") bltstring : not a fixnum : 1/2 [Endymion] (bltstring "foo" -3 "bar") bltstring : argument out of bounds : -3 [Endymion] (bltstring "foo" 0 1/2) bltstring : non string argument : 1/2 [Endymion] (bltstring "foo" 0 '(100 101)) deo [Endymion] (bltstring "foo" 0 '(-100 101)) bltstring : syntax error : bad list of ASCII codes [Endymion] (bltstring "foo" 0 '(233 1010)) bltstring : syntax error : bad list of ASCII codes [Endymion] (bltstring #"foo" 0 '(233 1010)) éϲo [Endymion] (bltstring "foo" 0 "bar" 1/2) bltstring : not a fixnum : 1/2 [Endymion] (bltstring "foo" 0 "bar" -1) bltstring : argument out of bounds : -1 [Endymion] (bltstring "foo" 0 #"bar" ) bar [Endymion] (bltstring "foo" 1 #"bar" ) fba [Endymion] (bltstring "foo" 1 #"abcéϲo" ) bltstring : argument out of bounds : 1010 [Endymion] (bltstring #"foo" 1 #"abcéϲo" ) fab [Endymion] (bltstring "foo" 1 #"bar" 0 1/2) bltstring : not a fixnum : 1/2 [Endymion] (bltstring #"foo" 0 '(233 #.(lsh 2 30))) bltstring : syntax error : bad list of Unicode codes [Endymion] errexp 2147483648 [Endymion] (bltstring x 0 "A") Aoobar [Endymion] x Aoobar [Endymion] (bltstring "foobar" 1 "xyz") fxyzar [Endymion] (bltstring "foobar" 1 "xyz" 1) fyzbar [Endymion] (bltstring "foobar" 2 "xyz" 1) foyzar [Endymion] (bltstring "foobar" 5 "xyz" 1) foobay [Endymion] (bltstring "foobar" 25 "xyz" 1) foobar [Endymion] (bltstring "foobar" 2 "xyz" 1) foyzar [Endymion] (bltstring "foobar" 2 "xyz" 1 4) foyzar [Endymion] (bltstring "foobar" 2 "xyz" 1 0) foobar
The bltvector function takes three, four or five arguments. The first and third ones must be vectors. Other arguments are non-negative integers. The function copies element at position n2+i of the second vector into position ni+i in the first vector. As many elements as possible are copied. If five arguments are given, the last one is the maximum number of elements that can be copied. If only three arguments are give, the default value of n2 is zero. The first argument is returned. The function can be defined in Lisp as follows:
(defun bltvector (vec1 n1 vec2 . rest) (let ((n2) (n3)) (if rest (setq n2 (car rest) n3 (cdr res)) (setq n2 0 n3 ())) (unless (integerp n1) (error 'bltvector errnia n1)) (when (< n1 0) (error 'bltvector erroob n1)) (unless (integerp n2) (error 'bltvector errnia n2)) (when (< n2 0) (error 'bltvector erroob n2)) (if n3 (setq n3 (car n3)) (setq n3 (lsh 2 30))) (unless (integerp n3) (error 'bltvector errnia n3)) (when (< n3 0) (error 'bltvector erroob n3)) (unless (vectorp vec1) (error 'bltvector errvec vec1)) (unless (vectorp vec2) (error 'bltvector errvec vec1)) (setq imax n3) (if (> imax (- (vlength vec1) n1)) (setq imax (- (vlength vec1) n1))) (if (> imax (- (vlength vec2) n2)) (setq imax (- (vlength vec2) n2))) (for (i 0 1 (- imax 1)) (vset vec1 (+ n1 i) (vref vec2 (+ n2 i)))) vec1))
Examples
[Endymion] (bltvector #[f o o b a r] 1 #[x y z] 2 1) #[f z o b a r] [Endymion] (bltvector #[f o o b a r] 1 #[t o t o] 0 6) #[f t o t o r] [Endymion] (bltvector #[f o o b a r] 1 #[t o t o t a] 0 8) #[f t o t o t] [Endymion] (bltvector #[f o o b a r] 2 #[t o]) #[f o t o a r] [Endymion] (bltvector 0 2 #[t o]) bltvector : not a vector : 0 [Endymion] (bltvector #[] 1/2 #[t o]) bltvector : not a fixnum : 1/2 [Endymion] (bltvector #[] 2 3) bltvector : not a vector : 3 [Endymion] (bltvector #[] 2 #[] -1) bltvector : argument out of bounds : -1 [Endymion] (bltvector #[] 2 #[] 0 -1) bltvector : argument out of bounds : -1
The bol function read a line from the device associated to the current channel and returns nil. An end-of-file is signalled in the case of end-of-file (or if the current channel is implode or friends). In such a case, the file is closed and (itsoft 'eof N) is executed, where N is the current channel number. Otherwise, if M characters are read, the quantity inpos is set to zero, and inmax to M. Normally, a whole line (terminated by carriage-return and line feed is read). But in the case of very long lines, as many characters as possible are read.
The function is called via (itsoft 'bol). If foo is part of #:sys-package:itsoft, then the following functions are called whenever a new line is read, or at the end of file. If nb_lines is from time to time copied into old_nb_lines, then you will see the value of the last copy at the end of the file.
(defun #:foo:bol () (setq nb_lines (+ nb_lines 1)) (super-itsoft 'foo 'bol ())) (defun #:foo:eof (l) (print "EOF reached after line " old_nb_lines) (super-itsoft 'foo 'eof (ncons l)))
The boundp function takes one argument. It returns true if this argument is a symbol that has a value.
[Endymion] (boundp 'foo) () [Endymion] (setq foo 'bar) bar [Endymion] (boundp 'foo) true [Endymion] (boundp foo) () [Endymion] (boundp 123) () [Endymion] (boundp 'ibase) true
These two macros are identical, they evaluate the arguments, and jump to a block named outer-do (see return for details about transfer of control). Note that, if no argument is given, nothing_done is returned. This macro is useful inside loops, since a block outer-do ois created. See do for details. The code of the macro is given here.
BREAK([x])::= if nbargs() =0 then buildq(return("outer-do",done)) else buildq(return("outer-do",<<splice(x)>>)); break([x])::= if nbargs() =0 then buildq(return("outer-do",done)) else buildq(return("outer-do",<<splice(x)>>));
This keyword is required in non-trivial symbolic macros; see the compiler.
If you say bye(); in symbolic mode, this aborts all computations and switches to Lisp mode.
back to home page © INRIA 2005, 2006 Last modified $Date: 2009/01/08 17:43:30 $