All commands, alphabetic order; letter O

This page contains the description of the following commands obase, oblist, ocase, oddp, or, op, open, opena, openab, openi, openib, openo, openob, openfiles, operator, opn, outbuf, outpos, outchan, outchan,

obase (Lisp variable/function)

This is the current output base. It must be a number between 2 and 36. If the base is greater than ten, then A represents ten, B represents eleven, etc.

(oblist) (Lisp function)

The oblist function takes no argument; it returns the list of all symbols. Note that all symbols with one character between 1 and 127 are the list, so that printing the list can produce strange effects. In the example that follows, we use a function that replaces that symbols by a question mark. Note that (mapoblist 'foo) is the same as (mapc 'foo (reverse (oblist)). The symbols are listed in increasing order of hash codes (() has hash code zero, and é# has hash code 999).

[Endymion] (defun foo (x) (prin (if (eq (strlen x) 1) "?" x) " "))
foo
[Endymion] (mapoblist 'foo)
é# vector sort1 <date cddaar Phi ocase upsilon compare csend add-to-it-list 
defconstant cdddr append2 append1 gamma send-super expr fsubr cddar plist 
...
[Endymion] (mapc 'foo (oblist))
() cddadr ? ? ? ? ? zeta ? ? #:display:fortran ? ? super-itsoft ? traceval 
incr natural ? nsubr cbindn return ? ? ? ? btvar ? ? bfnil ? ? info tagbody ?
...
[Endymion] (hashsize 999)
vector
é#
(2 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 2 1 2 1 1 0 0 3 0 0 1 0 0 0 1 0 
0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 3 0 0 0 0 1 0 0 2 0 0 0 1 1 0 1 2 1 1 0 0 0
...
[Endymion] (show-functions)
vector é# sort1 <date cddaar compare csend add-to-it-list defconstant cdddr 
append2 append1 send-super cddar plist outpos #:llcp:exit exit ncons vset 
...
()

ocase x in a then b, in c then d ... else z (Symbolic macro)

The case and ocase macros are the symbolic equivalent of selectq, with a strange syntax (see examples). We have shown the Lisp code in one example. The only difference between case and ocase is the `declare' which is currenlty ignored anyway. Example (4) shows that you can use a or b instead of [a,b], example (5) that you can use and and not, example (6) shows that lists can be constructed at runtime. Examples (9) and (10) show that any predicate can be evaluated. Example (11) shows how to use a predicate with an argument: here x is a dummy variable.

(1) case a in [b,c] then d, in e then f, in g then h else i ;
Macro expansion -> case(a, [b, c], d, e, f, g, h, else, i)
Macro expansion <- let([g11 = a], if member(g11, [b, c]) then d

 else (if g11 == e then f else (if g11 == g then h else i)))

(1)                                   i

(2) ocase a in [b,c] then d, in e then f, in g then h else i ;
Macro expansion -> ocase(a, [b, c], d, e, f, g, h, else, i)
Macro expansion <- let([g10 = a], declare([register, g10]), 

If member(g10, [b, c]) then d else (If g10 == e then f else (If g10 == g

 then h else i)))

(let ((#:gensym:g9 'a))
     (declare (register #:gensym:g9))
     (cond ((:member #:gensym:g9 (:[ 'b 'c)) 'd)
           ((:equal #:gensym:g9 'e) 'f)
           ((:equal #:gensym:g9 'g) 'h)
           (true 'i)
)    )

(2)                                   i

(3) L:=[1,2,3];

(3)                               [1, 2, 3]

(4) ocase a in U or V then d, in cons(1,L) then x else y;
Macro expansion -> ocase(a, U or V, d, cons(1, L), x, else, y)
Macro expansion <- let([g14 = a], declare([register, g14]), 

If g14 == U or g14 == V then d else (If g14 == cons(1, L) then x else y))

(5)                                   y

(6) case a in [a,b] and not [u,v] then x else y;
Macro expansion -> case(a, [a, b] and  not [u, v], x, else, y)
Macro expansion <- let([g18 = a], if member(g18, [a, b])

 and  not member(g18, [u, v]) then x else y)

(6)                                  x

(7) ocase a in list(cons(1,L)) then x else y;
Macro expansion -> ocase(a, list(cons(1, L)), x, else, y)
Macro expansion <- let([g15 = a], declare([register, g15]), 

If member(g15, cons(1, L)) then x else y)


(7)                                   y

(8) L:=[17,18,19]?;

(9) let(x=17, case x in list(L) and predicate(#isprime(x))  then 1 else 2) ;

(9)                                   1

(10) let(x=18, case x in list(L) and predicate(#isprime(x))  then 1 else 2) ;

Macro expansion -> case(x, list(L) and predicate(#isprime(x)), 1, else, 2)
Macro expansion <- let([g24 = x], if member(g24, L) and (#isprime(x)) then 1 else 2)

(10)                                  2

(11) ocase (4+3) in predicate(#isprime(x),x) then 0 else 1;

(11)                                   0

(oddp n) (Lisp function)

This function takes an integer as argument; it returns it if it is odd, and false otherwise. For an example, see evenp.

(or e1 ... en) (Lisp special form)

e1 or ... or en (Symbolic macro)

The symbolic macro is decribed under and. The or special form evaluates its arguments one after the other. If one evaluation gives a non-nil result, evaluation stops, and this is the return value. Otherwise, the return value is nil.

[Endymion] (or)
()
[Endymion] (or 1)
1
[Endymion] (or 1 2 3)
1
[Endymion] (or ()()())
()
[Endymion] (or (read) (read) (read)) () () ()
()
[Endymion] (or (read) (read) (read)) 1 2
1
2

op(expr, n) (Symbolic function with 1 or 2 arguments)

opn(expr, n1, ..., nk) (Symbolic function)

The op function takes one or two arguments E, and N (default value is -1). It converts argument E to a list, for instance f(x,y) becomes [x,y]. If N is positive, the Nth element of the list is returned (N=1 is the first element). If N=0, the operator is returned. If N is negative, the list is returned. The result of (opn e) is e, and opn(e,n1, n2,...) is evaluated as opn(op(e,n1), n2,...)

(1) L:=1=[3,4, <<**y,f(5,6),7>>];

                                       y
(1)                      1 = [3, 4, <<x , f(5, 6), 7>>]

(2) op(L,1);

(2)                                   1

(3) op(L,0);

(3)                                   =

(4) op(L,2);
                                     y
(4)                        [3, 4, <<x , f(5, 6), 7>>]


(5) op(L);
                                      y
(5)                     [1, [3, 4, <<x , f(5, 6), 7>>]]

(6) opn(L,25);
opn : argument out of bounds : 25
(7) opn(L,2,3,2);

(7)                                f(5, 6)

(8) opn(L,2,3,2,-1);

(8)                                 [5, 6]

(9) opn(L,2,3,2,a);
opn : not a fixnum : a
(10) opn(L,2,3,2,0);

(10)                                  f

(11) opn(L,2,3,1,0)(10,4);

(11)                                10000

(#:display:open f m) (Lisp function)

This function opens the file f in mode m for the symbolic printer. Nothing happens if the file is already opened; note that you cannot open the same name with this function and a construct like (display-to-list "foo" "open") If m is true, then openo is used, otherwise opena. Said otherwise, if m is true, and a file of name f exists on the disk it will be destroyed. In any case, the function returns true. See also display-to-list. Note that the console is represented by (), it is always open.

[Endymion] (#:display:open "foo" true)
true
[Endymion] (#:display:open "foo" false)
true
[Endymion] (display-to-list "foo" "open")
display-to-list : I/O error : foo
[Endymion] (display-to-list "bar" "open")
bar
[Endymion] (display-to-list "bar" "open")
display-to-list : I/O error : bar
[Endymion] (display-to-list "foo" "open")
display-to-list : I/O error : foo
[Endymion] (#:display:open "bar" true)
#:display:open : I/O error : bar
[Endymion] (#:display:openfiles)
[console foo bar]
[Endymion] (#:display:close "bar")
#:display:close : I/O error : bar
[Endymion] (display-to-list "foo" "close")
display-to-list : I/O error : foo
[Endymion] (display-to-list "bar" "close")
true
[Endymion] (#:display:close "foo")
true
[Endymion] (#:display:openfiles)
[console]

(opena f) (Lisp function)

(openab f) (Lisp function)

(openi f) (Lisp function)

(openib f) (Lisp function)

(openo f) (Lisp function)

(openob f) (Lisp function)

These six functions open a file in a given mode. As the example below shows, the argument must be a string or a symbol; in case of success a channel number is returned. If no free channel is available, an error of type out of IO channels is signaled. As the example shows, the same file can be opened more than once. What happens if you write on the file using both channels is unclear. In the same way, it is not clear what happens if you read and write on the same file. You can open a file in text or binary mode (commands terminated with `b'). This makes little difference. You can open a file for input openi or openib; the result of the command is then a valid argument to inchan. The file must exists and must be readable. You can open a file for output via openo or openob. If the file exists, it will be removed; in the example below, the directory `foo' does not exist, if you create it, and have permissions to add files, then you can open the file bar in the directory foo. You can open a file for output opena or openab. In this case, if the file exists, its content is not lost. The result of these command is a valid argument to outchan.

[Endymion] (openo 123)
openo : non string argument : 123
[Endymion] (openo 'ABC)
19
[Endymion] (openo "ABC")
18
[Endymion] (openo "foo/bar")
openo : I/O error : foo/bar
[Endymion] (channel)
#[() () () () () () () () () () () () () () () () () () #[ABC 3] #[ABC 3]]
[Endymion] (test-re-open "ABC")
18
[Endymion] (test-re-open "ABCD")
()

(#:display:openfiles) (Lisp function)

This function returns the list of all files opened for writing with display. See an example at display-to-list or #:display:open.

operator (Keyword)

Inside the conditional part of a macro, you can use operator(x), see the compiler.

(outbuf p c) (Lisp function)

The (outbuf) function acts on the current output buffer (there is one buffer per output channel, and the current channel is selected). The function takes 0, 1 or 2 arguments. The call (outbuf) returns a copy of the output buffer. This is a string of size 4K (since there is a final null character, its effective size is 4095. The command (outbuf 10) returns the character at position 10 in the buffer (the buffer contains initially space characters only). The command (outbuf 10 48) puts a zero (ASCII code 48) in the buffer at position 10. Whenever a line is printed, all characters up to (outpos) are printed, then replaced by a space. In the example below, the ouput position is 2 after printing the result of (outbuf 10 48). When we later on set the output position to 12, the zero character is still in the buffer.

[Endymion] (outbuf 'foo)
outbuf : not a fixnum : foo
[Endymion] (outbuf -2)
outbuf : argument out of bounds : -2
[Endymion] (outbuf 123456)
outbuf : argument out of bounds : 123456
[Endymion] (outbuf 'foo)
outbuf : not a fixnum : foo
[Endymion] (outbuf 123456)
outbuf : argument out of bounds : 123456
[Endymion] (outbuf 10)
32
[Endymion] (outbuf 10 'foo)
outbuf : not a fixnum : foo
[Endymion]  (outbuf 10 48)
48
[Endymion]  (outbuf 10)
48
[Endymion] (outpos 12)
          0 12
[Endymion] (outbuf 10)
32

(outpos p) (Lisp function)

The function (outpos) returns the current position in the output buffer. This is the value of the left margin before printing anything; commands like (prin) can change the position. The current position can be set to 20 via (outpos 20).

[Endymion] (outpos 5000)
outpos : argument out of bounds : 5000
[Endymion] (outpos 3)
   3
[Endymion] (outpos)
0
[Endymion] (progn (prin 299) (outpos))
2993
[Endymion] (progn (prin '1234567890123456789) (outpos 3)
[Endymion] (prin 'foo) (outpos 25)(print 'ok))
123foo7890123456789      ok
ok

(#:display:outchan c v) (Lisp function)

The #:display:outchan function takes one or two arguments. In the case of one argument it shows the value of the channel c, in the case of two arguments, it modifies it. See description of display-to-list for how to create, open, close, list channels. The example below assumes that `foo' and `xbar' are open list channels, `bar' is an open file channel, and `gee' is unknown. The return value is a priori the list of channels, but the channel if the list contains a single element. The channel itself is represented by a name, or a list containg the name and an attribute.

[Endymion] (#:display:outchan 'default)
[foo list]
[Endymion] (#:display:outchan 'default '(foo xbar))
[substchannel [xbar list] [foo list]]
[Endymion] (display-to-list 'foo "close")
true
[Endymion] (#:display:outchan 'default)
[substchannel [xbar list] [foo closed]]
[Endymion] (#:display:outchan 'default '(foo))
[foo closed]
[Endymion] (#:display:outchan 'default '(gee))
[gee closed]
[Endymion] (#:display:outchan 'default '(bar))
bar

The second argument of the command is a list, starting with a marker, followed by channels. The marker can be omitted: `substchannel' is used instead, other two possibilities are `addchannel' and `delchannel'. If the list contains a single element, you can give this element. The output of #:display:outchan is a valid argument; as a consequence, if the second argument is [foo list] or [foo closed], it is converted into to [substchannel foo closed] unless the `closed' is the same string as that returned by the function, case where it is interpreted as [substchannel [foo closed]], and behaves as [substchannel foo]. In the case of `addchannel' each element of the list is added to the channel, in the case of `delchannel', it is removed, in the case of `substchannel', the argument list replaces the old list The first argument should be one of 'default', `console', `trace', `error', or `input'. Otherwise, the second argument is ignored, and the function returns nil.

[Endymion] (setq x (#:display:outchan 'default 'bar))
[bar closed]
[Endymion] (setq closed (#:feval:car (#:feval:cdr x)))
closed
[Endymion] (#:display:outchan 'trace ())
console
[Endymion] (#:display:outchan 'trace (#:feval:|[| "xbar" closed))
[xbar closed]
[Endymion] (#:display:outchan 'trace (#:feval:|[| "xbar" "closed"))
[substchannel [closed closed] [xbar closed]]
[Endymion] (#:display:outchan 'default '(addchannel gee)) 
[substchannel [gee closed] [closed closed] [xbar closed]]
[Endymion] (#:display:outchan 'default '(delchannel xbar)) 
[substchannel [gee closed] [closed closed]]
[Endymion] (#:display:outchan 'foo 'bar)
()

outchan (Lisp variable/function)

This variable holds the current output channel, either nil for the terminal, or an integer corresponding to a channel opened by openo or similar functions. The explode (and friends) function uses a special channel that prints as nil, it is unwise to change the value in this case. The example that follows shows some error messages in case of bad argument. The effect of the last line if to print ok on the file foo.

[Endymion]  outchan
()
[Endymion]  (setq outchan 10)
outchan : stream not open for writing : 10
[Endymion]  (outchan 10)
outchan : stream not open for writing : 10
[Endymion]  (outchan "foo")
outchan : not a fixnum : foo
[Endymion]  (openo "foo")
17
[Endymion]  (let ((outchan 17)) (print 'ok))
ok

Valid XHTML 1.0 Strict back to home page © INRIA 2005, 2006 Last modified $Date: 2009/01/08 17:43:30 $