最后活跃于 2 weeks ago

A language to surpass Io

yumaikas's Avatar yumaikas 修订了这个 Gist 2 weeks ago. 转到此修订

1 file changed, 28 insertions

StackTalkDesign.txt

@@ -65,9 +65,37 @@ Objects: note[
65 65 Quotations: note[
66 66 Quotations are a swiss-army-knife of a code structure
67 67
68 + You can call `string` on them to get their contents.
69 + [ [ a thing ] .string NB[ stack is " a thing " ] ]
68 70
71 + `interpolate` will copy values from the containing scope based on $names
72 + [ 1 >a 2 >b interpolate[ $a $b + ] NB[ stack is [ 1 2 + ] ]
69 73
74 + Objects copied this way are copied by reference, rather than deep cloned.
70 75
76 + You can get the list of symbols from a quotation
77 + code[
78 +
79 + [ @ @ -- @ ] symbols each[ println ]
80 + NB[ print output:
81 + "@"
82 + "@"
83 + "--"
84 + "@"
85 + ]
86 + ]
87 +
88 + You can supply an interpretation ruleset, on the left side, you have patterns, on the right, consequent actions
89 + The patterns match against one or more symbols (as fetched by `symbols`).
90 +
91 + [ @ @ -- @ ] obj[ 0 >numInputValues 0 >numOutputValues input: >mode ]
92 + interperet[
93 + @ [ input: mode ] -> [ numInputValues: inc ]
94 + -- [ input: mode ] -> [ output: >mode ]
95 + @ [ output: mode ] -> [ numOutputValues: inc ]
96 + * -> [ [ "Unrecogized symbol" _ ] fmt error ]
97 + ] >effect
98 + NB[ effect do[ numInputValues numOutputValues mode ] stack is [ 2 1 output ] ]
71 99 ]
72 100
73 101 Scope: note[

yumaikas's Avatar yumaikas 修订了这个 Gist 2 weeks ago. 转到此修订

1 file changed, 63 insertions, 2 deletions

StackTalkDesign.txt

@@ -39,6 +39,8 @@ title[ StackTalk ]
39 39 [ 1 [ me> 1 + >me ] do ] can be written as [ 1 do[ me> 1 + >me ] ]
40 40
41 41 This is how `note` has been working.
42 +
43 + This doesn't generalize to arbitrary word movement, just for quotations.
42 44 ]
43 45
44 46
@@ -46,17 +48,42 @@ Objects: note[
46 48
47 49 The current Object/scope is the top of the `me:` stack.
48 50
49 -
50 51 `do` executes the quotation inside the scope of object below
51 52 it in the stack.
52 53
53 54 `$subject $quotation do`
54 55
55 - Shorthand
56 + do single command Shorthand:
57 +
56 58 [ AnObject [ aThing ] do ] can be written as [ AnObject .aThing ]
57 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 +
65 + Quotations: note[
66 + Quotations are a swiss-army-knife of a code structure
67 +
68 +
69 +
70 +
71 + ]
72 +
73 + Scope: 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
58 84 ]
59 85
86 +
60 87 Experimental: note[
61 88 Some code snippets that I'm noodling on.
62 89
@@ -65,3 +92,37 @@ Experimental: note[
65 92 [ x: y: z: ] from-stacks
66 93 ]
67 94 ]
95 +
96 + io: module[
97 + load-by-default
98 + println: js: [ @ -- ] ffi[ (x) => console.log(x); ]
99 + readln: js: [ -- @ ] ffi[ () => ; ]
100 + ]
101 +
102 + math: 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 +
115 + Point: 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 + ]

yumaikas's Avatar yumaikas 修订了这个 Gist 2 weeks ago. 转到此修订

1 file changed, 0 insertions, 0 deletions

StackTalkDesign.st 重命名为 StackTalkDesign.txt

文件已重命名,但内容与之前没有差异

yumaikas's Avatar yumaikas 修订了这个 Gist 2 weeks ago. 转到此修订

1 file changed, 67 insertions

StackTalkDesign.st(文件已创建)

@@ -0,0 +1,67 @@
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 + ]
上一页 下一页