johnazariah
2017-7-20 18:30:36

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


shu--hung
2017-7-20 18:32:02

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


shu--hung
2017-7-20 18:32:44

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


johnazariah
2017-7-20 18:33:37

oh cool…thanks, @shu—hung


zenspider
2017-7-20 19:39:05

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


johnazariah
2017-7-20 19:45:39

@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


johnazariah
2017-7-20 19:48:51

@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


johnazariah
2017-7-20 19:50:13

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)


johnazariah
2017-7-20 19:51:21

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


johnazariah
2017-7-20 19:51:41

is that a reasonable approach?


mflatt
2017-7-20 20:01:04

@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.


mflatt
2017-7-20 20:02:29

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.


johnazariah
2017-7-20 20:41:42

AWESOME - thank you! :slightly_smiling_face:


johnazariah
2017-7-20 22:10:23

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


johnazariah
2017-7-20 22:10:52

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


mflatt
2017-7-20 22:12:33

@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?


johnazariah
2017-7-20 22:14:20

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…


johnazariah
2017-7-20 22:14:53

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


mflatt
2017-7-20 22:31:10

(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)