with

with — traverses an array or list performing a statement.

Syntax

with symbol in|on s_exp do statement

with symbol1 in|on s_exp symbol2 = collect|tcollect statement

		

Arguments

symbol

Any Gamma or Lisp symbol.

s_exp

Any Gamma or Lisp expression.

statement

Any statement.

Returns

nil when using the do option, and the result of the statement when using the collect or tcollect option.

Description

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.

Examples

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
nil

Gamma> 

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
nil
Gamma> 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>  
		

See Also

for, if, Statements