( modules day 11.04.2001 )

needs vocabulary vocs

: module: ( "name" -- old-current )
  >in @ ['] ' catch
  if >in ! vocabulary get-current
     also latest l>name name> execute definitions
  else 
     nip get-current swap also execute definitions
  then
;

: export
     ( old-current -- old-current )
   dup set-current
;

: ;module ( old-current -- )
   set-current previous
;

: {{ ( "name" -- )
        depth >r
        also ' execute
        depth r> <>             if
             context !          then
; immediate

: }}
   previous
; immediate

: WordVocDoes
	also dup @ execute
	cell+ @ state @ if compile,
		else execute then
	NextWord sfind ?dup if
		state @ = if compile,
		else execute then
	else 1 abort" not found" then
	previous ;
: WordVoc ( "word" "voc" -- )
	create smudge
	' , ['] noop ,
	smudge immediate
does> WordVocDoes ;

: AssignVoc
( "word" "oldword" "voc" -- )
	create smudge
	' ' , ,
	smudge immediate
does> WordVocDoes ;

\ \eof
\ example:
\ : cr cr flush-type-buf ;

module: point
module: _
0
cell -- x
cell -- y
constant structsize
;module
WordVoc _ _
_ structsize constant structsize
: ! ( x y p -- )
	>r
	r@ _ y !
	r@ _ x ! rdrop ;
: @ ( p -- x y )
	>r
	r@ _ x @
	r@ _ y @ rdrop ;
: . ( p -- )
	@ swap ." (" . ." ," . ." )" ;
: + ( p1 p2 p3 -- )
	>r
	@ rot @ rot + -rot + swap
	r> ! ;
: init ( x y p -- )
	structsize allocate throw dup>r
	! r> ;
: done ( p -- )
	free throw ;
;module
cr .( Working with points:)
cr
cr .( 1st way)
cr
12 34 {{ Point Init }} constant a1
1 3 {{ Point Init }} constant b1
cr .( a=) a1 {{ Point . }}
cr .( b=) b1 {{ Point . }}
0 0 {{ Point Init }} constant c1
cr .( a+b=)
a1 b1 c1 {{ Point + c1 . }} 
cr
cr .( 2nd way)
cr

WordVoc Point:: Point

12 34 Point:: Init constant a2
1 3 Point:: Init constant b2
cr .( a=) a2 Point:: .
cr .( b=) b2 Point:: .
0 0 Point:: Init constant c2
cr .( a+b=)
a2 b2 c2 Point:: + c2 Point:: . 
cr
cr .( 3rd way)
cr
12 34 {{ Point Init }} constant a3
1 3 {{ Point Init }} constant b3

AssignVoc a3:: a3 Point
AssignVoc b3:: b3 Point

:noname
cr ." a=" a3:: .
cr ." b=" b3:: . ; execute
0 0 {{ Point Init }} constant c3

AssignVoc c3:: c3 Point

:noname
cr ." a+b="
a3 b3 c3:: + c3:: . ; execute
