Here's my rephrasing of Oleg's code.

Note that I've discarded COCREATOR.  I think COCREATOR 
can be useful for debugging purposes, but 13!:13 in 
create would be better.

Note that I've ignored the "locked script" problems.
They can be addressed using 
 create=: 3 :0 @:(][create_parent_ f.@:selectargs)
where parent and selectargs are replaced by something
appropriate.  I've not used that here because I
think unlocked scripts are simpler to work with,
and should not be burdened with the complexities
of locked scripts.



class_z_=:3 :0
 coinsert y
 18!:4 coname''
)
new_z_=:3 :0
 o=. cocreate''
 ((,copath)coname'') copath o
 create__o y
 o
)
create_z_=: ]
destroy_z_=: [EMAIL PROTECTED]

NB. Example use:

class_pshape_''
 TYPE=: 'SHAPE'
 create=:3 :0
  NAME=: y
 )

class_ppoint_ 'pshape'
 TYPE=: 'POINT'
 create=:3 :0
  create_pshape_ f. 0{::y
  'X Y'=: 1{::y
 )
 sub=:3 :0
  new_ppoint_ '';(X-X__y),(Y-Y__y)
 )
 norm=:3 :'X +&.*: Y'

class_prect_ 'pshape j'
 TYPE=: 'RECT'
 create=:3 :0
  create_pshape_ f. 0{::y
  p1=: new_ppoint_ 'p1';1{::y
  p2=: new_ppoint_ 'p2';2{::y
 )
 destroy=:3 :0
  destroy_pshape_ f.''
  destroy__p1''
  destroy__p2''
 )
 diag=:3 :0
  p=. sub__p2 p1
  d=. norm__p ''
  destroy__p ''
  d
 )


NB.____________________________________________________________

cocurrent 'base'
require 'coutil'
nv_z_=: [: ; (LF <@,~ >, '=:', 5!:5)"[EMAIL PROTECTED]

0!:101 (0 : 0)
 sA=: new_pshape_ 'A'
 pB=: new_ppoint_ 'B';10 20
 rC=: new_prect_  'C';10 20;13 24

 TYPE__sA
 copath sA
 nv__sA''

 TYPE__rC
 copath rC
 nv__rC''
 nv__p1__rC''
 diag__rC''
 PATHSEP__rC

 costate''
 destroy__sA''
 destroy__pB''
 destroy__rC''
 costate''
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to