langdefs: use case
expression for function bodies
#113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Instead of a list of assignments of the form
<f> <pattern>* = <body>
,the body of a meta-function must now be a
case
expression.Details
A function such as:
is now written as:
The two reasons for this change are:
there's no point in repeatedly specifying the name of a function:
it's the only valid identifier that may appear in before the
parenthesis. It's presence only introduces visual noise and makes
it harder to rename functions
the assignment based syntax is a bit trickier to parse, and it's
arguably not very intuitive. For people already familiar with
NimSkull and its syntax, what the new
case
expression syntax doesis likely easier to understand
Using a
case
expression also makeselse
available to be used forrepresenting the fallthrough case (the new parser already supports
this).
Two things that might be slightly confusing are that:
of
branches in theDSL are ordered
of
branches also affects whether thebranch is actually "picked"
The macro's parsing logic is updated to handle the new syntax, and the
source language specification is changed to make use of it.
Notes For Reviewers
Personally, I think the new syntax is better and more intuitive (despite the differences in semantics compared to NimSkull), but I'm also okay with keeping the previous syntax (and thus not merging this PR).