
hey folks - I’m trying to model a language in redex where I need to specify a tuple…how do I do that? it’s complaining about ,
being unquote

how about just using (item1 item2 item3)
without the ,
(or (tuple a b c)
?

if you really want the comma symbol, it can be written by (a \|,\| b \|,\| c)

oh cool…thanks, @shu—hung

yeah. model the AST, not the actual grammar… go through beautifulracket to learn how to hook up brag + lexer for the actual implementation

@zenspider thanks - I’m trying to model the AST…I have one in ML with discriminated unions and so on…trying to port that over to redex and get redex to help me reason about its completeness

@shu—hung/@zenspider/@mflatt I have the following DU in my AST: type ValueType =
\| Int
\| Float
\| Operation of OperationSignature
\| Tuple of TupleType
\| Reference of TypeName
\| Array of ValueType

I am trying to figure out how to convert that to a category in redex - I got the first two choices trivially implemented (t ::= integer float)

I added tuple
by saying (t ::= integer float tuple)
and (tuple::= (t ...))

is that a reasonable approach?

@johnazariah Beware that integer
is a built-in Redex pattern; I think you want a literal word, in this case, instead of some integer. To avoid any conflicts, I’d use a capital letter for a constructor: (value-type ::= Int
Float
(Operation operation-signature)
(Tuple tuple-type)
(Reference type-name)
(Array value-type))
(tuple-type ::= (value-type ...))
(operation-signature ::= ......)
....
but t
instead of value-type
and tuple
instead of tuple-type
is certainly fine.

Or maybe (Tuple values-type ...)
instead of having the tuple-type
production and adding a layer of parentheses, but I’d be reluctant to drop the Tuple
constructor in this case.

AWESOME - thank you! :slightly_smiling_face:

so @mflatt - is there something I can do to specify named tuples in the AST, instead of anonymous tuples?

like type UserDefinedType =
{
TypeName : TypeName
TypeDefinition : TupleType
}

@johnazariah You could add an identifier to your Tuple
-tagged form, something like (Tuple name type-type)
where name
is variable-not-otherwise-mentioned
. Is that what you had in mind?

so I have a construct like a for-loop range, which is comprised of three integer expressions - “from”, “to” and “step” - it’ll be nice to be able to know and refer to the property “from” instead of the positional 0…

so more like records (named tuples) instead of anonymous tuples :slightly_smiling_face:

(Tuple (name value-type) ...)
, so that each element of the tuple is named? But I would call that a “record” instead of a “tuple”, and I think I probably misunderstand because UserDefinedType
above seems to pair a single name with a collection of types (if I understand TupleType
)