XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

prog


Type:   -   special form (fsubr)
Source:   -   xlcont.c

Syntax

(prog ([binding ... ]) [expr ... ])
binding - a variable binding which is can take one of
symbol
(symbol init-expr)
symbol - a symbol
init-expr - an initialization expression for symbol
expr - expressions comprising the body of the loop which may contain returns, gos or tags for go
returns - NIL or the argument passed to the return function

Description

The 'prog' special form is basically a 'block' construct that contains symbols with optional initializations and a block of code [expressions] to evaluate. The 'prog' special form evaluates its initializations in no specified order, as opposed to prog* which does it sequential order. The first form after the 'prog' is the 'binding' form. It contains a series of 'symbols' or 'bindings'. The 'binding' is a 'symbol' followed by an initialization expression 'init-expr'. If there is no 'init-expr', the 'symbol' will be initialized to NIL. There is no specification as to the order of execution of the bindings or the step expressions, except that they happen all together. If a return form is evaluated, its value will be returned. Otherwise, NIL is returned. When 'prog' is finished execution, the 'symbols' that were defined will no longer exist or retain their values.

Examples

(prog () (print "hello"))   ; prints "hello"  returns NIL

(prog (i j)                 ; PROG with vars I and J
      (print i) (print j))  ; prints NIL NIL  returns NIL

(prog ((i 1) (j 2))         ; PROG with vars I and J
      (print i) (print j)
      (return (+ i j)))     ; prints 1 2  returns 3

See the prog special form in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next