Hello,

when there is a variable whose name ends with an asterisk
I get the following behaviour:

var* := “a”
; [var*]
; (var*)
; <debug [var*, “b”]
; (var*, “b”)

results in:
a
a
Conc(“a”, [“b”])
(“a”, “b”)

I would like to know if these results are correct or if they represent an error.

I came across this behaviour using Spoofax.

Submitted on 19 February 2011 at 19:15

On 19 February 2011 at 19:34 Stephan Ortner commented:

ok, this became pretty unreadable.

What i meant is:
packing var* into square brackets and debugging it results in writing a, same with packing it into parenthesis.
When you pack var* together with “b” into square brackets it writes Conc(“a”, [“b”]). And when you pack the two into parenthesis we get (“a”, “b”)


On 19 February 2011 at 21:01 Eelco Visser commented:

A variable with an asterisk represents a list variable; this is only relevant when used in the context of a list literal, however. In the construction of lists they can be used freely, i.e. [a*,b,c*,d,e*] corresponds to Conc(a*, Cons(b, Conc(c*, Cons(d, e*)))).

[x*,y*] evaluates to (x*,y*) when x* and y* are lists, but results in Conc(x*,y*) when either is not a list.

So in your example, you’d expect to bind a list to var*.

Note: List variables can also be used in pattern matches, but only in tail position, i.e. [a,b,c*] is equivalent to [a,b|c*], which is equivalent to Cons(a, Cons(b, c*)).

Log in to post comments