with
with — traverses an array or list performing a statement.
with symbol in|on s_exp do statement
with symbol1 in|on s_exp symbol2 = collect|tcollect statement
symbolAny Gamma or Lisp symbol.
s_expAny Gamma or Lisp expression.
statementAny statement.
nil when using the
do option, and the result of the
statement when using the collect
or tcollect option.
with
symbol in|on
s_exp do
statement
A with loop using the iteration style
in traverses an array or list as defined by an
expression (s-exp), performing the
statement with the iteration
symbol assigned to each element of the
array or list in turn.
A with loop using the iteration style
on traverses a list defined by an expression
(s-exp), performing the
statement with the iteration
symbol assigned to the car and then
successive cdrs of the list.
The iteration symbol is local in scope to
the with statement.
with
symbol1
in|on s_exp
symbol2 =
collect|tcollect statement
A with loop using the
collect directive will collect the results of
the statement for each iteration, and produce
an array or list (depending on the type of the original array or
list), whose elements correspond on a one-to-one basis with the
elements of the original array or list.
A with loop using the
tcollect directive will collect the results of
the statement at each iteration, ignoring
nil results in the body. The resulting
array or list will not have a one-to-one correspondence with the
original array or list.
The result of a with loop using
collect or tcollect will be
assigned to symbol2,
which is not local in scope to the with
statement. The iteration
symbol1 is local
in scope to the with statement.
Gamma>A = array(1,2,3,4);[1 2 3 4]Gamma>with x in A do{x = x + 1;princ(x, "\n");}2 3 4 5 nilGamma>Gamma>L = list (1, 2, 3, 4, 5, 6);(1 2 3 4 5 6)Gamma>with x on L do (princ(x,"\n"));(1 2 3 4 5 6) (2 3 4 5 6) (3 4 5 6) (4 5 6) (5 6) (6) nil nilGamma>with x in L y = collect x + 2;(3 4 5 6 7 8)Gamma>y;(3 4 5 6 7 8)Gamma>with x in L y = tcollect x < 4 ? x : nil;(1 2 3)Gamma>y;(1 2 3)Gamma>
for, if, Statements