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. ***

If You have downloaded Seventh.jar separately You need to call the 7th IDE in the following way:
java -Xms300m -Xmx300m -jar Seventh.jar
Java runs with increased heap- and stack-space when launched with seventh.bat from Sevjre.zip.

turtle graphics

forget xy
degrees

(0,0i) value xy
5 value ϱ
true value 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 parallel  ( length depth --  )
//COLORS depth 30 + @ setcolor
  red setcolor
  variable length
  variable depth
  1- depth  !
  2/ length !
  length @ depth @
  dup 0 > if
    sierpinski
    3 0 do
      length @ 0.75 * mvfwd
      60 right
      length @ depth @
      sierpinski
    loop
  else
    over 2/ triangle
    60 left
    over 2/ mvfwd
    120 right
    drop triangle
  then
;

clear
500 100 move
0 ϱ !

now$ type cr
2000 7 sierpinski
now$ type cr
repaint

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:

We respect Your privacy and we neither track You nor use cookies…
7th and the 7th logo are trademarks of 7th Stone Software GmbH. All other product or service names are the property of their respective owners.