Zuletzt aktiv 2 weeks ago

A language to surpass Io

Änderung 79f64ce12e9af023482703309d92708c4fae65c1

StackTalkDesign.txt Originalformat Playground
1title[ 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 This doesn't generalize to arbitrary word movement, just for quotations.
44]
45
46
47Objects: note[
48
49 The current Object/scope is the top of the `me:` stack.
50
51 `do` executes the quotation inside the scope of object below
52 it in the stack.
53
54 `$subject $quotation do`
55
56 do single command Shorthand:
57
58 [ AnObject [ aThing ] do ] can be written as [ AnObject .aThing ]
59
60 You can use an existing object as a starting point for one of your own via `clone`
61
62 [ 0 0 Object clone do[ >y >x ] >my2dPoint ]
63]
64
65Quotations: note[
66 Quotations are a swiss-army-knife of a code structure
67
68
69
70
71]
72
73Scope: note[
74
75 Stack name resolution order:
76 - Own set of stacks, where state and method definitions live
77 - Ordered list of modules. Symbol list is what is available at import time, need to explicitly refresh for updates
78 - A reference to `Lobby`, where iterpreter-level state lives.
79
80 Notably, -not- strictly lexical. `interpolate` provides a way to place values in from an outer scope.
81 Also, unless you `freeze` a quotation, a new one is allocated each time you run.
82
83 If a stack is resolved, then that should probably be cached on the current instance
84]
85
86
87Experimental: note[
88 Some code snippets that I'm noodling on.
89
90 experimental[
91 1 >x 2 >y 3 >z
92 [ x: y: z: ] from-stacks
93 ]
94]
95
96io: module[
97 load-by-default
98 println: js: [ @ -- ] ffi[ (x) => console.log(x); ]
99 readln: js: [ -- @ ] ffi[ () => ; ]
100]
101
102math: module[
103 load-by-default
104
105 +: js: [ @ @ -- @ ] ffi[ (x, y) => x+y; ]
106 +: lua: [ @ @ -- @ ] ffi[ function(x, y) return x+y end ]
107 -: js: [ @ @ -- @ ] ffi[ (x, y) => x-y; ]
108 *: js: [ @ @ -- @ ] ffi[ (x, y) => x*y; ]
109 gt: js: [ @ @ -- @] ffi[ (a, b) => a > b; ]
110 lt: js: [ @ @ -- @] ffi[ (a, b) => a < b; ]
111 div: js: [ @ @ -- @ ] ffi[ (x, y) => x/y; ]
112 [ >n n. pop + n> push ] >+=
113]
114
115Point: class[
116 usage[
117 1 2 Point .fromPair >location
118 1 1 location .move
119 location .pos NB[ stack is [ 2 3 ] ]
120 location: drop
121 ]
122
123 fromPair: [ @ @ -- @ ] fn[ clone do[ >y >x ] ]
124 init: [ -- ] method[ clone do[ 0 >x 0 >y ] ]
125 pos: [ -- @ @ ] method[ x> y> ]
126 moveByPair: [ @ @ -- ] method[ y: += x: += ]
127 move: [ x y -- ] method[ your[ x> y> ] moveByPair ]
128]
129