Front Page All Articles Recent Changes Random Article

Contents

Concatenative language

  • ACL
  • Ait
  • Aocla
  • Breeze
  • Callisto
  • Cat
  • Cognate
  • colorForth
  • Concata
  • CoSy
  • Deque
  • DSSP
  • dt
  • Elymas
  • Enchilada
  • ETAC
  • F
  • Factor
  • Fiveth
  • Forth
  • Fourth
  • Freelang
  • Gershwin
  • hex
  • iNet
  • Joy
  • Joy of Postfix App
  • kcats
  • Kitten
  • lang5
  • Listack
  • LSE64
  • Lviv
  • Meow5
  • min
  • Mirth
  • mjoy
  • Mlatu
  • Ode
  • OForth
  • Om
  • Onyx
  • Plorth
  • Popr
  • Porth
  • PostScript
  • Prowl
  • Quest32
  • Quackery
  • r3
  • Raven
  • Retro
  • RPL
  • SPL
  • Staapl
  • Stabel
  • Tal
  • Titan
  • Trith
  • Uiua
  • Worst
  • xs
  • XY
  • 5th
  • 8th

Concatenative topics

  • Compilers
  • Interpreters
  • Type systems
  • Object systems
  • Quotations
  • Variables
  • Garbage collection
  • Example programs

Concatenative meta

  • People
  • Communities

Other languages

  • APL
  • C++
  • Erlang
  • FP trivia
  • Haskell
  • Io
  • Java
  • JavaScript
  • Lisp
  • ML
  • Oberon
  • RPL
  • Self
  • Slate
  • Smalltalk

Meta

  • Search
  • Farkup wiki format
  • Etiquette
  • Sandbox

Listack program examples

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  }
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:36:35 by CFout

Latest Revisions Edit

All content is © 2008-2024 by its respective authors. By adding content to this wiki, you agree to release it under the BSD license.