diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-01-11 19:49:48 -0800 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-01-11 19:49:48 -0800 |
| commit | d1f378b7ed770f1ad78eb3e748f6ebc6c7024ef3 (patch) | |
| tree | a4471ee93b9e94e3f01a3386e0afd7e74b79d6e1 /match.csc | |
| parent | Write the linker. (diff) | |
| download | chromatopelma-d1f378b7ed770f1ad78eb3e748f6ebc6c7024ef3.tar.zst | |
Add guards to the match syntax.
I'm not sure the syntax is great, but it's very helpful to have.
Diffstat (limited to 'match.csc')
| -rw-r--r-- | match.csc | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -40,10 +40,19 @@ (define-syntax match - (syntax-rules () + (syntax-rules (when) + ((match x (pattern (when condition) result result* ...)) + (if (and (matches? x pattern) + condition) + (bind-pattern x pattern result result* ...))) ((match x (pattern result1 result2 ...)) (if (matches? x pattern) (bind-pattern x pattern result1 result2 ...))) + ((match x (pattern (when condition) result result* ...) clause clause* ...) + (if (and (matches? x pattern) + condition) + (bind-pattern x pattern result result* ...) + (match x clause clause* ...))) ((match x (pattern result1 result2 ...) clause1 clause2 ...) (if (matches? x pattern) (bind-pattern x pattern result1 result2 ...) |
