new example: naming quotes
FossilOrigin-Name: b7cb708ed7e5c798fddf0c30e9ac2eaf7f2951a958b17599e62e81c20987d9d5
This commit is contained in:
parent
26eeaa6dfb
commit
f26f5d54d9
2 changed files with 45 additions and 0 deletions
|
@ -1,5 +1,9 @@
|
|||
# RETRO 12.2019.6
|
||||
|
||||
This is the changelog for the development builds of Retro.
|
||||
I am currently planning to have the next release occur in
|
||||
June 2019.
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
## Build
|
||||
|
@ -70,11 +74,13 @@
|
|||
- retro-extend: allow multiple files
|
||||
- retro-extend: reduce memory usage
|
||||
- retro-extend: fix potential buffer overrun
|
||||
- muri: remove the unused `c` directive
|
||||
|
||||
## Other
|
||||
|
||||
## Documentation
|
||||
|
||||
- add a collection of papers
|
||||
- refactor glossary tool
|
||||
- add HTML version of the Glossary
|
||||
- add more concise text copies of the Glossary
|
||||
|
@ -88,6 +94,7 @@
|
|||
- add HTML.forth
|
||||
- add KeyValueStore.forth
|
||||
- add Marker.forth
|
||||
- add Naming_Quotes.forth
|
||||
- add net_fetch.forth
|
||||
- add paste.forth
|
||||
- add Paste_to_Sprunge.forth
|
||||
|
|
38
example/Naming_Quotes.forth
Normal file
38
example/Naming_Quotes.forth
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Naming Quotes
|
||||
|
||||
Anonymous functions called quotes are used heavily by Retro.
|
||||
This shows a way to attach names to them.
|
||||
|
||||
In a classic Forth, words are created using `:`, which is
|
||||
one of numerous parsing words. So a named function looks
|
||||
like:
|
||||
|
||||
: foo ... ;
|
||||
|
||||
In Retro, there are no parsing words. There is a prefix
|
||||
handler `:`, yielding:
|
||||
|
||||
:foo ... ;
|
||||
|
||||
Quotes start with `[` and end with `]`. So they look like:
|
||||
|
||||
[ ... ]
|
||||
|
||||
If we want to name a quote, we need to:
|
||||
|
||||
- create a header
|
||||
- assign the xt field to the quote address
|
||||
- set the class handler
|
||||
|
||||
This word, `def`, does these.
|
||||
|
||||
~~~
|
||||
:def (as-) d:create d:last d:xt store &class:word reclass ;
|
||||
~~~
|
||||
|
||||
An example of using this:
|
||||
|
||||
```
|
||||
[ 'Hello_%s!\n s:format s:put ] 'hello def
|
||||
'#forth hello
|
||||
```
|
Loading…
Reference in a new issue