2022-02-12 19:11:22 +01:00
|
|
|
# PROGRAM
|
|
|
|
|
|
|
|
`default del`
|
|
|
|
|
|
|
|
## program
|
|
|
|
|
|
|
|
`<< 'one' >>`
|
|
|
|
|
|
|
|
-> stack size should be 1
|
|
|
|
|
2022-02-19 16:32:05 +01:00
|
|
|
-> stack should be «'one'»
|
2022-02-12 19:11:22 +01:00
|
|
|
|
|
|
|
`del`
|
|
|
|
|
|
|
|
## program (2)
|
|
|
|
|
|
|
|
`<< 'one' 2`
|
|
|
|
|
|
|
|
-> stack size should be 1
|
|
|
|
|
2022-02-19 16:32:05 +01:00
|
|
|
-> stack should be «'one' 2»
|
2022-02-12 19:11:22 +01:00
|
|
|
|
|
|
|
`del`
|
|
|
|
|
|
|
|
## program (3)
|
|
|
|
|
|
|
|
`<<`
|
|
|
|
|
|
|
|
-> stack size should be 1
|
|
|
|
|
2022-02-19 16:32:05 +01:00
|
|
|
-> stack should be «»
|
2022-02-12 19:11:22 +01:00
|
|
|
|
|
|
|
`del`
|
|
|
|
|
|
|
|
## program (4)
|
|
|
|
|
|
|
|
`<< << << <<`
|
|
|
|
|
|
|
|
-> stack size should be 1
|
|
|
|
|
2022-02-19 16:32:05 +01:00
|
|
|
-> stack should be «<< << <<»
|
2022-02-12 19:11:22 +01:00
|
|
|
|
|
|
|
`del`
|
|
|
|
|
|
|
|
## program (5)
|
|
|
|
|
|
|
|
`<< -> n << n 2 * >> >>`
|
|
|
|
|
|
|
|
-> stack size should be 1
|
|
|
|
|
2022-02-19 16:32:05 +01:00
|
|
|
-> stack should be «-> n << n 2 * >>»
|
2022-02-12 19:11:22 +01:00
|
|
|
|
|
|
|
`del`
|
|
|
|
|
|
|
|
## program imbrication
|
|
|
|
|
|
|
|
`<< 1 << 2 >> >>`
|
|
|
|
|
2022-02-19 16:32:05 +01:00
|
|
|
-> stack should be «1 << 2 >>»
|
2022-02-12 19:11:22 +01:00
|
|
|
|
|
|
|
`del`
|
|
|
|
|
|
|
|
## program evaluation
|
|
|
|
|
|
|
|
`<< 1 << 2 >> >> dup eval`
|
|
|
|
|
2022-02-19 16:32:05 +01:00
|
|
|
-> stack should be «1 << 2 >>», 1, «2»
|
2022-02-12 19:11:22 +01:00
|
|
|
|
|
|
|
`del`
|
|
|
|
|
|
|
|
## program 1 arg
|
|
|
|
|
|
|
|
`default`
|
|
|
|
|
|
|
|
`10`
|
|
|
|
|
|
|
|
`<< -> n << 0 1 n for i i 2 * inv + next >> >>`
|
|
|
|
|
|
|
|
`eval`
|
|
|
|
|
|
|
|
-> stack should be 1.4644841269841269841269841269841269841
|
|
|
|
|
|
|
|
`del`
|
|
|
|
|
2022-02-19 16:32:05 +01:00
|
|
|
## nested programs
|
2022-02-12 19:11:22 +01:00
|
|
|
|
|
|
|
`0 1 10 << -> u0 u1 n << u0 u1 1 n start dup2 + rot drop next swap drop >> >> eval`
|
|
|
|
|
|
|
|
`eval`
|
|
|
|
|
|
|
|
-> stack should be 89
|
|
|
|
|
|
|
|
`del`
|
2022-02-19 16:32:05 +01:00
|
|
|
|
|
|
|
## fibo
|
|
|
|
|
|
|
|
```
|
|
|
|
«dup 1 > if then dup 1 - fibo swap 2 - fibo + else 1 == if then 1 else 0 end end» 'fibo' sto
|
2022-02-24 19:10:02 +01:00
|
|
|
«dup 1 > if then dup 1 - fibo swap 2 - fibo + else 1 == 1 0 ifte end» 'fibo' sto
|
2022-02-19 16:32:05 +01:00
|
|
|
7 fibo
|
|
|
|
13 == if then 'ok!' end
|
|
|
|
```
|
|
|
|
|
|
|
|
-> stack should be 'ok!'
|
|
|
|
|
|
|
|
`del`
|
|
|
|
|
|
|
|
## nested programs with local variables
|
|
|
|
|
|
|
|
```
|
|
|
|
100
|
|
|
|
10
|
|
|
|
«dup2 * -> a b c << a b + c / -> d << << -> sym << sym ->str " is " + sym rcl ->str + >> >> 'stringify' sto 'a' stringify 'b' stringify 'c' stringify 'd' stringify >> >>»
|
|
|
|
eval
|
|
|
|
```
|
|
|
|
|
|
|
|
-> stack should be "'a' is 100", "'b' is 10", "'c' is 1000", "'d' is 0.11"
|
|
|
|
|
|
|
|
`del`
|
|
|
|
|
|
|
|
## local variables multiple entries
|
|
|
|
|
|
|
|
`1 2 3 << -> a b c << "a is " a ->str + "b is " b ->str + "c is " c ->str + >> >> eval`
|
|
|
|
|
|
|
|
-> stack should be "a is 1", "b is 2", "c is 3"
|
|
|
|
|
|
|
|
`del`
|
|
|
|
|
|
|
|
## local variables separation (1)
|
|
|
|
|
|
|
|
`123 'n' sto 1 << -> n << "n is " n ->str + >> >> eval`
|
|
|
|
|
|
|
|
-> stack should be "n is 1"
|
|
|
|
|
|
|
|
`del`
|
|
|
|
|
|
|
|
## local variables separation (2)
|
|
|
|
|
|
|
|
`123 'n' sto 2 << -> n << n sq << -> n << "n is " n ->str + >> >> >> eval >> eval`
|
|
|
|
|
|
|
|
-> stack should be "n is 4"
|
|
|
|
|
|
|
|
`del`
|