Logostack (Huh?)

“It's turtles all the way down!”
Output

			
Controls

Quick Box Type a command here and press your “Enter” key.
Editor Type longer programs here and then click:
Examples More to come eventually!
Selecting one of these will clear the editor with no warning or undo!
  • square

    ; square
    ; 
    ; Here's a classic Logo example program,
    ; modified to demonstrate the postfix notation 
    ; required by Logostack.
    
    [ 100 fd
      90 rt
    ] 4 repeat
    
  • star

    ; star
    [ 150 fd
      144 rt
    ] 5 repeat
    
  • primitive data types

    ; primitive data types
    
    ; Strings are enclosed in double-quotes
    ; and can contain white space.
    "Hello World" print
    
    ; Words - an alternate notation for strings -
    ; are begun with a single-quote and
    ; are terminated by whitespace.
    'Good-bye! print
    
    ; Booleans and null
    true print
    false print
    null print
    
    ; Numbers must follow JSON format
    0.5 print
    7e+4 print
    
    "And now for an intentional error:" print
    
    ; This is an error because a number can't
    ; begin with a decimal.
    .5 print 
    
  • variables

    ; variables
    
    ; Setting a variable with MAKE
    5 'myNumber make
    
    ; Using that variable with "dots"
    ; (the colon character :)
    :myNumber print
    
  • lists

    ; lists
    
    ; Lists begin with [ and end with ].
    ; There must be space before and after each of those.
    ; The result is the literal string tokens that fall between.
    
    ; This list contains the strings "one", "two", and "three":
    [ one two three ]
    print
    
    ; To make the list contain the result of evaluating 
    ; those tokens, use the LIST operator:
    1 'one make
    2 'two make
    3 'three make
    [ :one :two :three ] list
    print
    
    ; Define a variable to contain a list:
    [ :one :two :three :four ] 'myList make
    
    ; It contains those literal tokens
    :myList print
    
    "And now for an intentional error:" print
    
    ; This causes an error because "four" hasn't been defined:
    :myList list
    
  • functions

    ; functions
    ;
    ; Functions are just lists, treated as lists of 
    ; instructions.
    
    ; To define a function, just assign it to a variable:
    [ [ 100 fd
        90 rt
      ] 4 repeat
    ] 'square make
    
    ; To call it, just use its name without dots:
    square
    
    ; Let's change the pen color and rotate
    ; for the next example.  SETPC takes a string that 
    ; contains any valid CSS color.
    'red setpc
    30 rt
    
    ; Functions don't take arguments per se,
    ; but they can pull things off the stack and assign
    ; them to local variables using LOCALMAKE:
    [ 'side localmake
      [ :side fd
        90 rt
      ] 4 repeat
    ] 'square make
    
    ; To pass it a number, push that number
    ; onto the stack before calling the function.
    50 square
    
    "And now for an intentional error:" print
    
    ; This is an error, because "side" was only 
    ; defined locally inside the function.
    :side print
    
  • star pinwheel kaleidoscope

    ; star pinwheel kaleidoscope
    
    ht pu
    'red 'orange 'yellow 'green 'blue 'purple
    [ dup setfillcolor
      6 -1 roll
      [ [ 200 fd
          144 rt
        ] 5 repeat
      ] filled
      repcount 0.005 mul rt
    ] forever
    
Speed Settings Adjust how often the screen gets refreshed.
Refresh at least once every:
turtle changes.
milliseconds.
After each refresh, pause for:
milliseconds.
© 2009 Thomas Peri