Newsgroups: comp.lang.apl
Path: watmath!watserv1!torn!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uunet.ca!geac!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Linear Representation
Message-ID: <1992Jul8.183312.27464@yrloc.ipsa.reuter.COM>
Organization: Iverson Software Inc.
Date: Wed, 8 Jul 92 18:33:12 GMT
Lines: 127

The linear representation LR (5!:5, not yet implemented) of an object is
a string which, when interpreted, produces that object.  For example:
 
   lr =. 5!:5
   nub =. (i.@# = i.~) # ]
   lr <'nub'
(i.@# = i.~) # ]
   $lr<'nub'
16
   lr <'lr'
5!:5
 
LR can be modelled as follows.  It may be instructive to apply the model
to itself.
 
ar     =. 5!:1
type   =. 3!:0
boxed  =. 32&= @ type
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&.>)
vkey1  =. ('<!.'&,@paren@lnoun)`('<'"_)@.(0&-:)@(>!._) , lnoun@>
vboxk  =. }. @ ; @: (<@(','&,)@paren@vkey1"0)
value  =. vchar`vbox`vboxk`(":!.18@,) @. (2 32 64&i.@(type * *@(*/)@$))
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.@{.@>@[)
 
lx     =. {. insert lr&.>@oarg
ltie   =. lr`(}.@;@:('`'&,@cp@lr&.>)@oarg) @. ((<,'0')&=@{.)
lgl    =. {. insert (ltie&.>@{. , lr  &.>@}.)@oarg
lgr    =. {. insert (lr  &.>@{. , ltie&.>@}.)@oarg
lg     =. lgr`lgl`lx @. (i.&(<,'`')@oarg)
ltil   =. lx`(oarg@>@{.@oarg) @. ((<,'0')&=@{.@>@{.@oarg)
lcase  =. (cp@lnoun@oarg)`lgl`lgl`lg`ltil`lx @. ((;:'0@.`:4~')&i.@{.)
lr     =. symb`lcase@.boxed
 
lrep   =. lr @ > @ ar
____________________________
 
The model is divided into groups of defns (verbs unless otherwise noted).
The first group are utilities:
 
ar       atomic representation
type     "internal" type: 1 boolean, 2 literal, 4 integer, etc.
boxed    1 if boxed
oarg     open the second element of the list argument
mtv      the empty vector as a constant function
paren    parenthesize the string argument
symb     ' ',x if x is '.' or ':'; x itself otherwise
quote    (noun) the single quote
alp      (noun) the letters of the alphabet, majuscules and minuscules
dig      (noun) the digits
 
The next group computes the LR of a noun.  "lnoun" applies to an array,
and produces a string which, when executed, produces that array.  Thus:
 
   lnoun i.3 4
3 4$0 1 2 3 4 5 6 7 8 9 10 11
   lnoun o.1 2
3.14159265358979328 6.28318530717958656
   lnoun ;:'Cogito, ergo sum.'
(<'Cogito'),(<,','),(<'ergo'),(<'sum.')
   lnoun 'Don''t tread on me. 183164'
'Don''t tread on me. 183164'
 
A LR is more readily readable if redundant parentheses are omitted.
The "cp" group concerns with conditional parenthesization.  Parentheses are
not required if a phrase is a one- or two-letter word (two-letter words
end in a period or colon), or a name, or a single number or a numeric list,
or a quoted string, or already parenthesized.  (Other conditions exist.)
For example:
 
   cp '_1.2e_34j_5.6e_7 8 9'          cp '_1.2e_34j_5.6e_7&+'
_1.2e_34j_5.6e_7 8 9               (_1.2e_34j_5.6e_7&+)
 
"insert" applies to the boxed "root" and the list of boxed LRs of the
argument(s), and produces a LR.  For example, in computing the LR of i.@# ,
"insert" would be applied to (<,'@') and 'i.';,'#' .  The root comes from
the atomic representation; it is the symbol for an adverb or conjunction
(/ in +/ or @ in i.@#), or a digit for the symbolless operations:
 
   2 hook
   3 fork
   4 bonded conjunction
   5 two-element a-train or c-train
   6 three-element a-train or c-train
 
"lr" applies to the opened atomic representation of an object and produces
its LR.  The verbs in the group embody logic to produce "nice" effects for
various special cases.  The agenda items in "lcase" are:
 
   0       cp@lnoun@oarg  noun
   @.      lgl            gerundial left argument
   `:      lgl            gerundial left argument
   4       lg             bonded conj.; possible gerund left or right argument
   ~       ltil           possible instance of evoke
   other   lx             none of the above
 
"lrep" is a model of 5!:5.

------------------------------------
Roger Hui, Iverson Software Inc., 33 Major Street, Toronto, Ontario  M5S 2K9
Phone: (416) 925 6096;  Fax: (416) 488 7559
