catala/tests/test_name_resolution/good/let_in.catala_en
2022-11-21 17:11:53 +01:00

53 lines
1.0 KiB
Plaintext

## Article
```catala
declaration scope S:
context output a content A
context output b content B
declaration structure A:
data x content decimal
data y content B
declaration structure B:
data y content boolean
data z content decimal
scope S:
definition b equals let b equals 42 in B { -- y: true -- z: integer_to_decimal of b}
definition a equals
let b equals
if b.B.y
then B { -- y: false -- z: -1. }
else B { -- y: true -- z: -2. }
in
let a equals 2. *. b.z in
A { -- x: a -- y : b }
```
```catala-test-inline
$ catala Interpret -s S
[RESULT] Computation successful! Results:
[RESULT] a = A { "x"= -2.; "y"= B { "y"= false; "z"= -1. } }
[RESULT] b = B { "y"= true; "z"= 42. }
```
## Check scope of let-in vs scope variable
```catala
declaration scope S2:
x scope S
output y content integer
scope S2:
definition y equals
let x equals 0 in
x + 1
```
```catala-test-inline
$ catala Interpret -s S2
[RESULT] Computation successful! Results:
[RESULT] y = 1
```