Skip to main content

Constructor

rascal-0.34.0

Synopsis

Assignment to a constructor shape is a destructuring bind.

Syntax

_Name_(_V_₁, _V_₂, ..., _V_ₙ) = _Exp_;

Description

First the value Exp is determined and should be a data value of the form _Name_(_V_₁, _V_₂, ..., _V_ₙ). Next the assignments Assignableᵢ = Vᵢ` are performed for 1 \<= i \<= n.

Examples

rascal>data FREQ = wf(str word, int freq);
ok
rascal>W = wf("rascal", 1000);
FREQ: wf("rascal",1000)
rascal>wf(S, I) = W;
FREQ: wf("rascal",1000)
rascal>S;
str: "rascal"
---
rascal
---
rascal>I;
int: 1000

Benefits

  • Easy destructuring bind

Pitfalls

  • If the expression does not match the constructor an exception is thrown