View Ticket
07:23 Closed ticket [49d490f836]: Alpha 2: Syntax changes plus 3 other changes artifact: ba54291630 user: robin.hansen
Make syntax changes based on language proposal [49d490f836]. Fixes tickets [05dc3c652b], [2ed5dbbb6d... check-in: 5de766c3d5 user: robin.hansen tags: trunk
12:21 New ticket [49d490f836] Alpha 2: Syntax changes. artifact: cf1e2f9f6a user: robin.hansen

Ticket UUID: 49d490f836f98643d32f8ca6f6070051a0c540ad
Title: Alpha 2: Syntax changes
Status: Closed Type: Language_Proposal
Severity: Important System: Compiler
Resolution: Fixed Modified: 2021-01-24 07:23:29
User Comments:
robin.hansen added on 2021-01-01 12:21:34:

Please read the following document on how to work with language proposals: Language proposals.

Alpha 2: Syntax change

After the release of Alpha 1, I had time to play a lot more with the language than I had during development, and there are several language changes I would like to make for the release of Alpha 2.

Here are the proposed syntax changes, in no specific order:

Change deftype: to defstruct

The deftype: keyword starts the definition of a compound type, or a data structure. I believe this should be renamed to defstruct: for two reasons:

1. defunion: also defines a type, so having something called deftype: seems confusing. destruct: makes it more obvious what the keyword does. 2. deftype: might be better used for defining type aliases, if that feature is implemented in the future.

Drop > from constructors for structs with no members

It won't be uncommon to define "empty" structs in Play, especially when combined with unions. Take this example.

defunion: Maybe a
: a
: Nothing

defstruct: Nothing

In this example, Play will auto-generate a constructor for Nothing, named >Nothing.

> is meant to be read as 'into'. In this case it would be read as "into Nothing", which implies that values are read from the stack and inserted into the Nothing structure. However, Nothing has no members, and so this just becomes confusing.

The type name should suffice as a constructor name for structures without members.

Use : instead of when: to define branches in a multi word

The default keyword (:) is meant to imply the default action for a definition. For words it defines the implementation:

def: square
: dup *

For structs it defines the members of the struct:

defstruct: Item
: qty Int
: price Int

For unions it defines the members of the union:

defunion: Maybe a
: a
: Nothing

For multi-words, however, it defines the default/else branch, wheras 'when:' defines a branch.

defmulti: maybe-inc
when: Int
  1 +
: drop Nothing

Arguably, the default thing to do when defining a multi-word is to define branches. Defining an else branch is the more uncommon action, especially when dealing with larger unions. As such I propose that the above examples should instead be written as:

defmulti: maybe-inc
: Int
  1 +
else: drop Nothing