You are here:

7th words

To see all words (that are functions and operators) in 7th enter words after the ok> prompt in the command window. For information on a word or a specific topic use help.

7th examples

*** In heavy recursive programms like the Sierpinski triangle in the turtle graphics example below – the JVM will run out of heap- / stack-space. ***

Therefore You need to call the 7th IDE in the following way:
java -Xms300m -Xmx300m -jar Seventh.jar

turtle graphics

forget xy
degrees

variable xy    (0,0i) xy !
variable µ     5 µ !
variable pen?  true pen? !

: fwd    ( n --  )
  g fn
  xy @ >re,im

  xy @
  6 roll µ @
  >re,im >complex
  +
  dup xy !
  >re,im
  pen? @ if
    drawLine
  else
    3drop
    3drop
  then
;

: bkw    ( n --  )
  negate
  fwd
;

: mvfwd    ( n --  )
  pen? off
  fwd  
  pen? on
;

: mvbkw    ( n --  )
  pen? off
  negate
  fwd  
  pen? on
;

: left  ( n --  )
  negate µ +!
;

: right  ( n --  )
  µ +!
;

: move    ( x y --  )
  >complex xy !
;

: triangle  ( n --  )
  3 0 do
    dup fwd
    120 right
  loop
  drop
;

: star
  350 330 move
  pen? on
 
  500 0 do
    i isodd? if
      i fwd
      98 left
    then
  loop
;

: sierpinski  ( length depth --  )
  over 2/ Y !
  1-
  dup 0 > if
    sierpinski
    3 0 do
      over 0.75 * mvfwd
      60 right
      2dup
      sierpinski
    loop
  else
    over 2/ triangle
    60 left
    over 2/ mvfwd
    120 right
    drop triangle
  then
;


0 µ !
(500,50i) xy !

clear

2000 7 sierpinski

8 queens puzzle

forget row

8 char-array row
0 array rows

row 8 '_' fill

: block  (  --  )
  variable r
  0 r !
  rows for
    r @ 1+ r !
    8 0 do
      forobj i @ 'x' == if
        i r @ +
        dup 8 < if
          dup ':' row rot !
        then
        drop
        i r @ -
        dup 0 >= if
          dup ':' row rot !
        then
        drop
        '.' row i !
      then
    loop
  each
;

: forward
  8 0 do
    block
    row i @ '_' == if
      'x' row i !
      leave
    then
  loop

  row
  dup println
  8 0 do
    row i @ ':' == if
      '_' row i !
    then
  loop
  rows |<!
  rows size 8 < if
    forward
  then
;

clear
cr
forward

Turtle graphics – Sierpinski triangle:

8 queens puzzle: