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
  • ERIShell
  • ETAC
  • F
  • Factor
  • Fiveth
  • Forth
  • Fourth
  • Freelang
  • Gershwin
  • hex
  • iNet
  • Joy
  • Joy of Postfix App
  • kcats
  • Kitten
  • lang5
  • Lamplight
  • Listack
  • LSE64
  • Lviv
  • Meow5
  • min
  • Mirth
  • mjoy
  • Mlatu
  • Ode
  • OForth
  • Om
  • Onion
  • Onyx
  • Plorth
  • Popr
  • Porth
  • PostScript
  • Prowl
  • Quackery
  • Quadrate
  • Quest32
  • 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
  • Events

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.

9
8 inc
1 2 + 3 *
1 .+ 2 .* 3
+: 1 2 3 *
*(+(1 2) 3)

Computing the summation of 0..number

def: "summ" [Int]
  {dup	#<=>  # That was a single-word comment.  It's quite handy.
    {dup {inc dup 0 <} {dup raise + swap} while}   # do if negative
    {dup}                                          # do if zero
    {dup {dec dup 0 >} {dup raise + swap} while}   # do if 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 #<=>
    {dup dec * -2 //}
    {nop}
    {dup inc * 2 //}
   <=> }

timer_start 100_000 fast_summ timer_check 
"fast_summ(100,000) time: " print 1_000 // print " us" println 
println

The following are the actual definitions of 'while' and 'until'.

# while helpers
create_global: "_while_cond"
create_global: "_while_body"
alias: "_while_"
  {@!_while_cond   # eval condition
  {@!_while_body   # eval loop body
    _begin_loop_   # prep for cont
    _while_ }      # recurse
  when}            # 'when' is an 'if' with no 'else' clause

# {condition to continue} {body to execute} while
# Executes body zero or more times.
	# {true} {println:"infinite loop"} while

def: "while" [Executable, Executable]
	{@>_while_body @>_while_cond 		# set up variables
  	_while_                                 # call helper
        _end_loop_			        # prep for break
  	@<_while_body drop @<_while_cond drop}	# tear down variables

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

# {body} {condition} until
# Always executes body at least once.
	# {println:"infinite loop"} false until

def: "until" [Executable, Executable]
  { {not} concat @>_while_cond @>_while_body
  @!_while_body _begin_loop_ _while_ _end_loop_}

def: "until" [Executable, Bool]
  { {not} concat @>_while_cond @>_while_body
  @!_while_body _begin_loop_ _while_ _end_loop_}

This revision created on Fri, 20 Nov 2026 20:38:48 by CFout ( Updated for Listack v0.4.1)

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.