# with

## Syntax

with ( id := expression id := expression ... )

## Parameters

- id (identifier)

Unique identifier for the local variable. - expression (float, string, bool, float[], string[], bool[])

Value to be stored.

## Description

The with keyword successively defines a set of local variables for a definition. Within the scope of a definition local variables can be referenced using their identider id. They are not accessible outside the scope of the definition.

Local variables can be defined for functions, const functions, attributes and rules. The expression may reference functions, const functions and attributes which are defined outside the scope of the current definition as well as parameters and local variables which are defined prior in the list of local variables.

attr a with ( x := "example" ) = x const b with ( x := [0,1,2] y := 0 ) = x[y] f(a) with ( x := a y := x ) = y Lot with ( x := f(1) ) --> extrude(x)

The expression of a local variable is evaluated and its value is stored as soon as the definition is called. The expression is not beeing re-evaluated when a local variable is referenced.

In the following simple example a function computes and stores intermediate results in local variables d1 and d2 at the time the function is called. Each local variable is then referenced twice in order to compute the distance between 2 points.

dist2d(x1, y1, x2, y2) with ( d1 := x2-x1 d2 := y2-y1 ) = sqrt(d1*d1 + d2*d2) Lot --> print("distance: " + dist2d(1,1,2,2)) // 1.414

The following rule computes the area of the current shape and stores it in a local variable. The value does not change despite the area of the shape is altered.

Lot with ( area := geometry.area() ) --> s('2,0,'2) print("initial area: " + area) print("altered area: " + geometry.area())

## Related

Copyright ©2008-2024 Esri R&D Center Zurich. All rights reserved.