diff options
| author | Taylan Kammer <taylan.kammer@gmail.com> | 2026-01-06 09:06:32 +0100 |
|---|---|---|
| committer | Taylan Kammer <taylan.kammer@gmail.com> | 2026-01-06 09:06:32 +0100 |
| commit | 910b1697e16bfb77a46dd39914116c5102519c41 (patch) | |
| tree | cb2361fbba5d30e1dc02096ec9f49502090eea46 | |
| parent | 71f4b9a52fc98390139330f15b632df3fdfed2ea (diff) | |
Add & update notes on new grammar.
| -rw-r--r-- | notes/250210-cons.md | 31 | ||||
| -rw-r--r-- | notes/260106-simpler-grammar.md | 33 | ||||
| -rw-r--r-- | notes/index.md | 1 |
3 files changed, 65 insertions, 0 deletions
diff --git a/notes/250210-cons.md b/notes/250210-cons.md index 3146957..1ce97b9 100644 --- a/notes/250210-cons.md +++ b/notes/250210-cons.md @@ -178,3 +178,34 @@ multiple values! (The phrase "argument list" is probably going to stick around forever though, even if it's technically wrong in Zisp.) + +## Grammar switch-up! + +_2026 January_ + +For [reasons](260106-grammar.html) I've decided to actually use the +ampersand in place of the dot in Zisp s-expressions. Not like in the +paper linked above; the ampersand simply replaces the dot in the +representation of improper lists. + +Here's how some snippets from above would look with the new grammar: + +```scheme + +(define (map* proc & args) + (map proc (list & args))) + +(define combine* + (case-lambda + ((x) x) + ((x y & rest) (combine* (combine x y) & rest)))) + +(define (foobar & rest) + (let-values (((x y z) rest)) + ;; This is a meaningless example for demonstration, since we + ;; could have just made the function accept three parameters. + ;; The `let-values` here is the one from SRFI 11. + )) + +(apply display-if-found (lookup '((x & y)) 'x)) ;; displays x +``` diff --git a/notes/260106-simpler-grammar.md b/notes/260106-simpler-grammar.md new file mode 100644 index 0000000..ddfe619 --- /dev/null +++ b/notes/260106-simpler-grammar.md @@ -0,0 +1,33 @@ +# Simplifying S-Expression Grammar + +Supporting dots as part of identifiers and number literals, especially +at the beginning like in `...` or `.5`, but then special-casing a lone +dot for improper list syntax, is a bit annoying. + +It makes my otherwise crystal clear and simple BNF grammar, as well as +my parser implementation, a bit less simple, which is bothersome. + +Since I've already broken off heavily from traditional s-expressions, +I've decided to retire the dot as the improper list marker. Instead +I'll be using the ampersand. + +``` +;; The good old +(foo bar . baz) + +;; The new kid +(foo bar & baz) +``` + +This is way more annoying to type, and I've not yet gotten used to the +way it looks. But you don't type improper lists frequently in code, +and I think the looks are just a matter of familiarity. + +By the way, the ampersand is now illegal in identifiers. It's totally +reserved for this singular purpose in the grammar. + +The only common use I know of is exception types in R6RS, which I've +never liked anyway. Using the question or exclamation marks would be +more intuitive, to express a questionable situation or a surprise! + +I might walk back on this eventually, but so far it seems OK. diff --git a/notes/index.md b/notes/index.md index 63ef532..dd5a946 100644 --- a/notes/index.md +++ b/notes/index.md @@ -22,3 +22,4 @@ * [Using libgccjit?](250920-libgccjit.html) * [Goals](250920-goals.html) * [A full-stack programming language](260102-full-stack.html) +* [Simplifying S-Expression Grammar](260106-simpler-grammar.html) |
