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 local variable a to (n+1)*2
n 1 .+ 2 .* @>a
n + 1 * 2 @>a
(n + 1 * 2) @>a
(n + 1) * 2 @>a
n.inc * 2 @>a
+: n 1 2 .* @>a
+(n 1) * 2 @>a
+(n,1)*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

The following is the actual definition of 'while'.

# while
create_global: "_while_cond"
create_global: "_while_body"

# internal use only
def: "_while_" [] 
  {@!_while_cond 
  {@!_while_body _begin_loop_ 
   _while_}
  .iff}

# {condition to continue} while {body to execute}
# {true} while {println:"infinite loop"}

def: "while" [Blocky, Blocky] 
  {@>_while_body @>_while_cond 
  _while_ _end_loop_
  @<_while_body drop @<_while_cond drop}

def: "while" [Bool, Blocky] 
  {@>_while_body @>_while_cond 
  _while_ _end_loop_
  @<_while_body drop @<_while_cond drop}

def: "while" [Bool, Word] {>block .while}
def: "while" [Blocky, Word] {>block .while}
[3 5 7] {dup .+} {dup .*} bi_map
# produces: [6 10 14] [9 25 49]

[3 5 7] {dup .+} {dup .*} bi_each
# produces: 6 10 14 9 25 49

3 4 \sqr both .+ sqrt
# produces 5.0

This revision created on Fri, 13 Oct 2023 17:03: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.