-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
langdefs: use
case
expression for function bodies (#113)
## 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: ``` function f, x -> x: f(z) = 1 f(1) = 2 ``` is now written as: ``` function f, x -> x: case _ of z: 1 of 1: 2 ``` The two reasons for this change are: 1. 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 2. 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 does is likely easier to understand Using a `case` expression also makes `else` available to be used for representing the fallthrough case (the new parser already supports this). Two things that might be slightly confusing are that: 1. contrary to the NimSkull semantics, the `of` branches in the DSL are ordered 2. in the DSL, the body of the `of` branches also affects whether the branch 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.
- Loading branch information
Showing
2 changed files
with
112 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters