StackTalkDesign.st
· 1.7 KiB · Smalltalk
Originalformat
Playground
title[ StackTalk ]
"Stack Basics" note[
An object is a collection of named stacks
A quotation is a malleable list of code symbols, delimited by [ and ]
Strings can be written two ways:
"This is a conventional string"
this-is-a-symbol-string:
There are 4 baseline stack operations:
`$value $stack push`
`$stack pop`
`$stack peek`
`$stack run`
These let you manipulate arbitrarily named stacks.
`run` is a bit special. It'll run top of $stack, if it is a
quotation, otherwise it acts like peek
There are shortcuts for these operations:
[ 1 x: push ] can be writtn as [ 1 >x ]
[ x: peek ] can be written as [ x. ] when you need no ambiguity
[ x: pop ] can be written as [ x> ]
[ x: run ] can be written as [ x ]
]
"Quotation suffix autoswap" note[
This one is a little inspired by https://knucklecracker.com/wiki/doku.php?id=crpl:overview#warp_notation,
but is ultimately a bit less generalized.
I anticipate that quotations will be modified by a lot of words. Because of this, and because
I think it reads better in a lot of cases, there's another rewrite
[ 1 [ me> 1 + >me ] do ] can be written as [ 1 do[ me> 1 + >me ] ]
This is how `note` has been working.
]
Objects: note[
The current Object/scope is the top of the `me:` stack.
`do` executes the quotation inside the scope of object below
it in the stack.
`$subject $quotation do`
Shorthand
[ AnObject [ aThing ] do ] can be written as [ AnObject .aThing ]
]
Experimental: note[
Some code snippets that I'm noodling on.
experimental[
1 >x 2 >y 3 >z
[ x: y: z: ] from-stacks
]
]
| 1 | title[ StackTalk ] |
| 2 | |
| 3 | "Stack Basics" note[ |
| 4 | |
| 5 | An object is a collection of named stacks |
| 6 | A quotation is a malleable list of code symbols, delimited by [ and ] |
| 7 | Strings can be written two ways: |
| 8 | |
| 9 | "This is a conventional string" |
| 10 | this-is-a-symbol-string: |
| 11 | |
| 12 | There are 4 baseline stack operations: |
| 13 | |
| 14 | `$value $stack push` |
| 15 | `$stack pop` |
| 16 | `$stack peek` |
| 17 | `$stack run` |
| 18 | |
| 19 | These let you manipulate arbitrarily named stacks. |
| 20 | `run` is a bit special. It'll run top of $stack, if it is a |
| 21 | quotation, otherwise it acts like peek |
| 22 | |
| 23 | There are shortcuts for these operations: |
| 24 | |
| 25 | [ 1 x: push ] can be writtn as [ 1 >x ] |
| 26 | [ x: peek ] can be written as [ x. ] when you need no ambiguity |
| 27 | [ x: pop ] can be written as [ x> ] |
| 28 | [ x: run ] can be written as [ x ] |
| 29 | |
| 30 | ] |
| 31 | |
| 32 | "Quotation suffix autoswap" note[ |
| 33 | This one is a little inspired by https://knucklecracker.com/wiki/doku.php?id=crpl:overview#warp_notation, |
| 34 | but is ultimately a bit less generalized. |
| 35 | |
| 36 | I anticipate that quotations will be modified by a lot of words. Because of this, and because |
| 37 | I think it reads better in a lot of cases, there's another rewrite |
| 38 | |
| 39 | [ 1 [ me> 1 + >me ] do ] can be written as [ 1 do[ me> 1 + >me ] ] |
| 40 | |
| 41 | This is how `note` has been working. |
| 42 | ] |
| 43 | |
| 44 | |
| 45 | Objects: note[ |
| 46 | |
| 47 | The current Object/scope is the top of the `me:` stack. |
| 48 | |
| 49 | |
| 50 | `do` executes the quotation inside the scope of object below |
| 51 | it in the stack. |
| 52 | |
| 53 | `$subject $quotation do` |
| 54 | |
| 55 | Shorthand |
| 56 | [ AnObject [ aThing ] do ] can be written as [ AnObject .aThing ] |
| 57 | |
| 58 | ] |
| 59 | |
| 60 | Experimental: note[ |
| 61 | Some code snippets that I'm noodling on. |
| 62 | |
| 63 | experimental[ |
| 64 | 1 >x 2 >y 3 >z |
| 65 | [ x: y: z: ] from-stacks |
| 66 | ] |
| 67 | ] |
| 68 |