Concatenative topics
Concatenative meta
Other languages
Meta
Examples of different ways to do the same thing in Listack.
10 @>n # set local variable n to 10
# The following all set the variable a to (n+1)2 → 22.
n 1 .+ 2 . @>a
n + 1 2 @>a
(n + 1 2) @>a
(n + 1) 2 @>a
n.inc 2 @>a
set(‘a’, (n + 1 2))
set: `a (n + 1 2)
“a” set (+: n 1 2)
a (n 1 .+ 2 .) .set
set(a, (+(n, 1), 2))
set(a (+(n 1) 2))
a set (+: @<n 1 2 .)
n.get 1 .+ 2 . @>a
{n + 1 2} eval @>a
+: @n 1 2 a swap .set
# And many more, with increasing levels of obfuscation.
Computing the summation of 0..number
def: "summ" [Int]
{dup <=> # would be a bit faster if this were postfix
{dup {1 .+ dup 0 .<} {dup roll .+ swap} .while} # negative
{dup} # zero
{dup {1 .- dup 0 .>} {dup roll .+ swap} .while} # positive
drop }
timerstart 100000 summ timercheck # timer works in nanoseconds
"summ(100,000) time: " print 1000000 .// print " ms" println
println cr
def: "fastsumm" [Int]
{ dup # <=> This is a good way to indicate what’s going on with postfix words.
{dup 1 .- . -2 .//}
{nop}
{dup 1 .+ . 2 .//}
.<=> }
timerstart 100000 fastsumm timercheck
"fastsumm(100,000) time: " print 1000 .// print " us" println
println
This revision created on Sat, 17 Jun 2023 20:31:29 by CFout