2021-03-30 13:58:25 +02:00
|
|
|
## Sigils as a Language Element
|
2020-01-07 15:09:08 +01:00
|
|
|
|
|
|
|
A big change in RETRO 12 was the elimination of the traditional
|
|
|
|
parser from the language. This was a sacrifice due to the lack
|
|
|
|
of an I/O model. RETRO has no way to know *how* input is given
|
|
|
|
to the `interpret` word, or whether anything else will ever be
|
|
|
|
passed into it.
|
|
|
|
|
|
|
|
And so `interpret` operates only on the current token. The core
|
|
|
|
language does not track what came before or attempt to guess at
|
|
|
|
what might come in the future.
|
|
|
|
|
2021-03-30 13:58:25 +02:00
|
|
|
This leads into the sigils. RETRO 11 had a complicated system
|
|
|
|
for sigils, with different types of sigilss for words that
|
2020-01-07 15:09:08 +01:00
|
|
|
parsed ahead (e.g., strings) and words that operated on the
|
|
|
|
current token (e.g., `@`). RETRO 12 eliminates all of these in
|
2021-03-30 13:58:25 +02:00
|
|
|
favor of just having a single sigil model.
|
2020-01-07 15:09:08 +01:00
|
|
|
|
|
|
|
The first thing `interpret` does is look to see if the first
|
2021-03-30 13:58:25 +02:00
|
|
|
character in a token matches a `sigil:` word. If it does, it
|
|
|
|
passes the rest of the token as a string pointer to the sigil
|
|
|
|
specific handler to deal with. If there is no valid sigil
|
2020-01-07 15:09:08 +01:00
|
|
|
found, it tries to find it in the dictionary. Assuming that it
|
|
|
|
finds the words, it passes the `d:xt` field to the handler that
|
|
|
|
`d:class` points to. Otherwise it calls `err:notfound`.
|
|
|
|
|
|
|
|
This has an important implication: *words can not reliably
|
2021-03-30 13:58:25 +02:00
|
|
|
have names that start with a sigil character.*
|
2020-01-07 15:09:08 +01:00
|
|
|
|
|
|
|
It also simplifies things. Anything that would normally parse
|
2021-03-30 13:58:25 +02:00
|
|
|
becomes a sigil handler. So creating a new word? Use the `:`
|
|
|
|
sigil. Strings? Use `'`. Pointers? Try `&`. And so on. E.g.,
|
2020-01-07 15:09:08 +01:00
|
|
|
|
|
|
|
In ANS | In RETRO
|
|
|
|
: foo ... ; | :foo ... ;
|
|
|
|
' foo | &foo
|
|
|
|
: bar ... ['] foo ; | :bar ... &foo ;
|
|
|
|
s" hello world!" | 'hello_world!
|
|
|
|
|
2021-03-30 13:58:25 +02:00
|
|
|
If you are familiar with ColorForth, sigils are a similar
|
2020-01-07 15:09:08 +01:00
|
|
|
idea to colors, but can be defined by the user as normal words.
|
|
|
|
|
|
|
|
After doing this for quite a while I rather like it. I can see
|
|
|
|
why Chuck Moore eventually went towards ColorForth as using
|
2021-03-30 13:58:25 +02:00
|
|
|
color (or sigils in my case) does simplify the implementation
|
2020-01-07 15:09:08 +01:00
|
|
|
in many ways.
|