Second draft of model. And I retract my claim that the code is
obsolete -- the problem there is that I didn't test it adequately. (I
still haven't, but that gets into other things I have not tackled yet.
Anyways, this seems to work.)

ar     =: 5!:1
boxed  =: 32&= @ (3!:0)
oarg   =: >@(1&{)
mtv    =: i.@0:
paren  =: ('('&,)@(,&')')
symb   =: $&' '@(e.&'.:')@{. , ]
quote  =: ''''
alp    =: (,65 97+/i.26){a.
dig    =: '0123456789'

slist  =: $&','@(1&=)
shape  =: mtv`slist`(,&'$'@":)@.(2&<.@#)`('i.'&,@":) @. (0&e.) @ $
vchar  =: >:@(quote&=)@, quote&,@(,&quote)@# ,
vbox   =: }. @ ; @: (','&,@paren@('<'&,)@lnoun&.>)
value  =: vchar`vbox`(":!.18@,) @. (2 32&i.@(3!:0 * *@(*/)@$))
lnoun  =: shape , value

dotco  =: 2&=@# *. e.&'.:'@{:
name   =: e.&alp@{. *. *./@(e.&(alp,dig,'_'))@}: *. e.&(alp,dig,'_.:')@{:
num    =: e.&(dig,'_')@{. *. *./@(e.&(dig,'_ .ejdr'))
qstr   =: mtv -: -.@(~:/\)@e.&quote -.&quote@# ]
pstr   =: -.@(0&e.)@}:@(+/\)@({&1 _1 0)@('()'&i.)
nopar  =: 1&=@# +. dotco +. name +. num +. qstr +. pstr
cp     =: paren`] @. nopar

bp     =: ]`cp@.(' '&e.)
hfork  =: }.@;@:(' '&,@bp&.>)@]
left   =: bp@>@{.
right  =: mtv`(cp@>@{:)@.(1&<@#)
ins    =: left@] , symb@>@[ , right@]
act    =: ;@:(cp&.>)@]
insert =: hfork`hfork`act`act`act`ins @. ('23456'&i.@{.@>@[)

dx     =: {. insert dr&.>@oarg
dtie   =: lr`(}.@;@:('`'&,@cp@dr&.>)@oarg) @. ((<,'0')&=@{.)
dgl    =: {. insert (dtie&.>@{. , dr  &.>@}.)@oarg
dgr    =: {. insert (dr  &.>@{. , dtie&.>@}.)@oarg
dg     =: dgr`dgl`dx @. (i.&(<,'`')@oarg)
dtil   =: dx`(oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg)
dcase  =: fixdd@oarg`(cp@lnoun@oarg)`dgl`dgl`dg`dtil`dx @.
((;:':0@.`:4~')&i.@{.)
dr     =: symb`[email protected]

fixdd=:{{
  if.(,~;:'0')-:{.&> y do.
    if.4 2-:3!:0@oarg&>y do.
      'typ bod'=. oarg each y
      if.5>typ do.
        if.1=#bod do.
          '{{',(symb,bod),'}}' return.
        else.
          ('{{)',typ{'nacvd'),}:;<@,&LF@dtb"1 bod,'}}' return.
        end.
      end.
    end.
  end.
  dx y
}}

drep   =: dr @ > @ ar

Conceptually, I might rephrase fixdd to be tacit (and perhaps breaking
out three additional verbs -- one verb for each if. statement), but
this is good enough for now.  And, of course, fixdd could be expressed
as a 3 : 0 verb if this needed to run on an older version of J.

Thanks,

-- 
Raul

On Fri, Oct 30, 2020 at 6:59 PM Raul Miller <[email protected]> wrote:
>
> In this context, it doesn't matter that {{ }} may be nested. You have
> already contained any inner direct definitions:
>
>    {{{{+/y}}y}}
> 3 : '{{ +/y }}y'
>
> Thanks,
>
> --
> Raul
>
> On Fri, Oct 30, 2020 at 2:39 PM Henry Rich <[email protected]> wrote:
> >
> > You might want to look at unDD() in r.c.  It's what I use for converting
> > internal DDs inside an explicit definition back to {{ }} form.
> >
> > I use it for the display of error messages and in the linear rep of an
> > explicit definition - just not for the outermost m : 0.
> >
> > Remember, {{ }} may be nested.
> >
> > Henry Rich
> >
> >
> > On 10/30/2020 12:58 PM, Raul Miller wrote:
> > > Oh, this is interesting -- jsource/test/g5x5.ijt contains an almost
> > > working implementation of tree -- which should probably be used to
> > > update https://www.jsoftware.com/ioj/iojRep.htm
> > >
> > > (This code is used to test the 5!:5 implementation.)
> > >
> > > (I say "almost working" because the verb 'type' needs to be replaced
> > > with (3!:0) or it throws a domain error.)
> > >
> > > FYI,
> > >
> >
> >
> > --
> > This email has been checked for viruses by AVG.
> > https://www.avg.com
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to