Concatenative topics
Concatenative meta
Other languages
Meta
Examples of different ways to do the same thing in Listack.
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 } timer_start 100_000 summ timer_check # timer works in nanoseconds "summ(100,000) time: " print 1_000_000 .// print " ms" println println cr def: "fast_summ" [Int] { dup # <=> This is a good way to indicate what’s going on with postfix words. {dup 1 .- .* -2 .//} {nop} {dup 1 .+ .* 2 .//} .<=> } timer_start 100_000 fast_summ timer_check "fast_summ(100,000) time: " print 1_000 .// print " us" println println ]
This revision created on Sat, 17 Jun 2023 20:34:53 by CFout