NB. class/object utilities

NB. cofind         find objects containing name in object
NB. coinfo         return info on co classes
NB. conouns        nouns referencing object
NB. conounsx       object references with locales
NB. copathnl       path name list
NB. copathnlx      formatted path name list with defining classes
NB. coselect       select current locale
NB. costate        state of class objects

cocurrent 'z'

NB. =========================================================
NB.*cofind v find locales containing global name y.
cofind=: 3 : 0
(<,>y.) (4 : 'x. e. nl__c 0$c=.y.'"0 # ]) 18!:1]0 1
)

NB. =========================================================
NB.*coinfo v return info on co classes
NB. returns noun refs;object;creator;path
coinfo=: 3 : 0
ref=. boxxopen y.
if. 0 e. $ref do. i.0 4 return. end.
if. 0=4!:0 <'COCREATOR__ref'
do. c=. COCREATOR__ref else. c=. a: end.
(conouns ref),ref,c,< ;:inverse copath ref
)

NB. =========================================================
NB.*conouns v nouns referencing object
conouns=: 3 : 0 "0
n=. nl 0
t=. n#~ (<y.)-:&> ".each n
< ;: inverse t
)

NB. =========================================================
NB.*conounsx v object references with locales
NB. returns: object;references;locales
conounsx=: 3 : 0
r=. ''
if. #y. do.
  s=. #y=. boxxopen y.
  loc=. conl 0
  for_i. loc do. r=. r,conouns__i y end.
  r=. (r~:a:) # (y$~#r),.r,.s#loc
end.
/:~~.r
)

NB. =========================================================
NB.*copathnl v path name list
NB. path name list
copathnl=: 3 : 0
'' copathnl y.
:
r=. ''
t=. (coname''),copath coname''
for_i. t -. <,'z' do.
  r=. r,x. nl__i y.
end.
/:~~.r
)

NB. =========================================================
NB.*copathnlx v formatted path name list with defining classes
copathnlx=: 3 : 0
'' copathnlx y.
:
r=. ''
t=. (coname''),copath coname''
for_i. t=. t -. <,'z' do.
  r=. r,<x. nl__i y.
end.
n=. ~.;r
n,.|:( n&e. &> r) #each t
)

NB. =========================================================
NB.*coselect v select current locale
NB.
NB. requires wdselect
coselect=: 3 : 0
NB. c=. (18!:1 [ 1),'base';(18!:1 [ 0)-.<'base'
c=. 'base';(18!:1 [ 1),(18!:1 [ 0)-.<'base'
'r x'=. wdselect 'Locales';<c
if. r=1 do. 18!:4 x{c else. empty'' end.
)

NB. =========================================================
NB.*costate v state of class objects
costate=: 3 : 0
r=. ,: ;:'refs id creator path'
if. #n=. conl 1 do. r,coinfo &> n /: 0 ".&> n end.
)
