Logiweb(TM)

7.12.10 Let constructs and patterns

Prev Up Next Page 240 of 800 Search internet


The value of

let x = 2 in x + 3

is x + 3 where x is 2. In other words, the value of the term above is 5.

The value of

let x :: y = floor ( 27 , 10 ) in A

is the value of A where x is floor ( 27 , 10 ) head and y is floor ( 27 , 10 ) tail. We have

floor ( 27 , 10 ) = ( 27 div 10 ) :: ( 27 mod 10 ) = 2 :: 7

so the value of

let x :: y = floor ( 27 , 10 ) in A

is the value of A where x is 2 and y is 7. In this case, the let-construct provides an easy way to destructure the pair returned by the floor function.

The value of

let x :: true = floor ( 27 , 10 ) in A

is the value of A where x is 2. The assignment of a value to the constant true is ignored.

The value of

let << r :: i :: d ,, u ,, v >> = quote 2 + 3 end quote in A

is the value of A where r, i, d, u, and v are the reference, index, debugging information, first subtree, and second subtree, respectively, of quote 2 + 3 end quote. Before macro expansion of the let construct itself, the pattern

<< r :: i :: d ,, u ,, v >>

is macro expanded to

( r :: i :: d ) :: u :: v :: true

The value of

let x :: y = 7 in A

is the value of A where both x and y are 7.

The destructuring properties of the pair construct is defined as a list with two elements, one for each of the two arguments of the pair. The first element of the list reads

if asterisk atom then asterisk else asterisk head

When a pair is destructured, the pair is inserted in place of the asterisk. The second element of the list reads

if asterisk atom then asterisk else asterisk tail

The base page essentially defines the destructuring properties of pairs thus:

destructure define u :: v as << ( if asterisk atom then asterisk else asterisk head ) ,, ( if asterisk atom then asterisk else asterisk tail ) >> end define

The definition on the base page looks a bit more clumsy, but that is because the definition must work before e.g. tuples are in place.

The base page only defines destructuring properties for pairs. Authors are free to define arbitrary destructuring properties for their constructs.

Prev Up Next Page 240 of 800 Search logiweb.eu

Copyright © 2010 Klaus Grue, GRD-2010-01-05