Ok... i do not know how to approach this without reviewing basics,
so... bear with me.

The question is how does a3 work. And, a3 is:

   a3=: (@: (aw f.)) av

aw extracts the left tine of the gerund of a train or analogous sequence:

   9!:3]1 5   NB. show both atomic and linear representations

   1:a4    NB. raw example verb
┌──────────────┐
│┌─┬──────────┐│
││"│┌──┬─────┐││
││ ││1:│┌─┬─┐│││
││ ││  ││0│_││││
││ ││  │└─┴─┘│││
││ │└──┴─────┘││
│└─┴──────────┘│
└──────────────┘
1:"_
   aw 1:a4 bGerund    NB. using aw to extract left tine from our example
┌──┐
│1:│
└──┘

And, remember, av derives and adverb from a monadic verb (such that
the adverb result on the adverb argument is what the verb argument
would have been from the verb argument).

The trick seems to be that a3 seemingly produces a gerund result but
it passes that result to @: (and the verb which is derived by @: is
then transformed to an adverb by av).

If I understand right, the only way this can work is if a3 is not
really operating on gerunds but is actually operating on J's internal
structure for tacit functions (they are structured like gerunds but
don't need `:6 to turn them into verbs because they already are verbs
- and this would also apply for adverbs and conjunctions - basically
it's a tree structure with each element of that tree having a type, so
whatever you extract from it has the type of that element).

This ... feels like the sort of obscurity that people talk at length
about (and skirt around) when discussing type theory and higher level
functions. I'm still waffling about what I think about it myself. Jose
really likes it though.

##################

Meanwhile, a6 is something of a wrapper for this aw based mechanic.
It's building up a template verb to build a gerund, using av to make
that an adverb, then using `:6 on the result of executing that
template against the adverb argument.

   a6=: ((( ar'a4') ; ] ; ( ar'a3')"_) av) (`:6)

Conceptually, it's sort of like 1 :'a4 u a3' but that rephrasing loses
track of the type and tree structure issues.

Thanks,

-- 
Raul



On Sat, Oct 21, 2017 at 4:43 PM, Erling Hellenäs
<[email protected]> wrote:
> Hi all !
>
> I do my best to understand this. Like Raul I name things. I created some
> explanations. However, I didn't manage to understand how a3 and a6 works.
> Maybe someone can help?
>
> My project:
>
> 9!:14''
>
> o=: @:
>
> ar=: 5!:1 @:<
>
> ar 'o'
>
> emptyGerund=: `''
>
> emptyGerund
>
> DoOnLeftArgAdverb=: (@:[) ((<'&')`) (`:6)
>
> +/ DoOnLeftArgAdverb
>
> InfinityAdverb=: (`(<(":0);_)) (`:6)
>
> %InfinityAdverb
>
> ExecuteDoOnLeftArgAdverbWithLeftArg=: ((ar'emptyGerund')`)
> (`(ar'DoOnLeftArgAdverb')) (`(ar'InfinityAdverb') ) (`:6)
>
> 1 2 3 *: ExecuteDoOnLeftArgAdverbWithLeftArg
>
> FetchAtomicRepr=: < o ((0;1;0)&{::) NB. Fetching the atomic representation
>
> br=: 5!:2@:<
>
> f=: -@:-@-
>
> br 'f'
>
> FetchAtomicRepr br 'f'
>
> a3=: (@: (FetchAtomicRepr f.)) ('ExecuteDoOnLeftArgAdverbWithLeftArg' f.)
>
> RankInfinity=: "_
>
> +RankInfinity
>
> EvokeGerundTrain=: `:6
>
> (+/)`%`# EvokeGerundTrain 1 2 3
>
> a6=: ((( ar'RankInfinity') ; ] ; ( ar'a3')"_)
> ('ExecuteDoOnLeftArgAdverbWithLeftArg'f.)) (`:6)
>
> hg=: `((ar'a6')`(ar'EvokeGerundTrain')) (`:6)
>
> 1 2 3 ((<'*:') ; ]) hg
>
> an=: <@:((,'0') (,&<) ]) NB. Atomizing words (monadic verb)
>
> an +`-`*`%
>
> AdverbToPackvuGerundWithAt=:< o ((('@:') ; < o |.)) o (('';1)&{::) hg
>
> (-`<) AdverbToPackvuGerundWithAt
>
> 3 (-`<) AdverbToPackvuGerundWithAt 2
>
> AdverbToPackReverseOrderGerundWithAt=: ([ , (<'@:') , ])/o |. o
> (('';1)&{::)hg
>
> *:`-`%`+: AdverbToPackReverseOrderGerundWithAt
>
> *:`-`%`+: AdverbToPackReverseOrderGerundWithAt 5
>
> ConjunctionToExecuteVWithArgumentU=: ((an f.hg) (` (|. o ((('';1)&{::))hg))
> (an f.hg))
>
> 1 2 3 ConjunctionToExecuteVWithArgumentU (+/)
>
>
> The printout:
>
>
>    9!:14''
> j806/j64/windows/beta/BEST/Jx-patches/2017-10-06T14:44:47
>    o=: @:
>    ar=: 5!:1 @:<
>    ar 'o'
> ┌──┐
> │@:│
> └──┘
>    emptyGerund=: `''
>    emptyGerund
> `''
>    DoOnLeftArgAdverb=: (@:[) ((<'&')`) (`:6)
>    +/ DoOnLeftArgAdverb
> &(+/@:[)
>    InfinityAdverb=: (`(<(":0);_)) (`:6)
>    %InfinityAdverb
> 0
>    ExecuteDoOnLeftArgAdverbWithLeftArg=: ((ar'emptyGerund')`)
> (`(ar'DoOnLeftArgAdverb')) (`(ar'InfinityAdverb') ) (`:6)
>    1 2 3 *: ExecuteDoOnLeftArgAdverbWithLeftArg
> 1 4 9
>    FetchAtomicRepr=: < o ((0;1;0)&{::)  NB. Fetching the atomic
> representation
>    br=: 5!:2@:<
>    f=: -@:-@-
>    br 'f'
> ┌────────┬─┬─┐
> │┌─┬──┬─┐│@│-│
> ││-│@:│-││ │ │
> │└─┴──┴─┘│ │ │
> └────────┴─┴─┘
>    FetchAtomicRepr br 'f'
> ┌─┐
> │@│
> └─┘
>    a3=: (@: (FetchAtomicRepr f.)) ('ExecuteDoOnLeftArgAdverbWithLeftArg' f.)
>    RankInfinity=: "_
>     +RankInfinity
> +"_
>    EvokeGerundTrain=: `:6
>    (+/)`%`# EvokeGerundTrain 1 2 3
> 2
>    a6=: ((( ar'RankInfinity') ; ] ; ( ar'a3')"_)
> ('ExecuteDoOnLeftArgAdverbWithLeftArg'f.)) (`:6)
>    hg=: `((ar'a6')`(ar'EvokeGerundTrain')) (`:6)
>    1 2 3 ((<'*:') ; ]) hg
> 1 4 9
>    an=:  <@:((,'0') (,&<) ])  NB. Atomizing words (monadic verb)
>    an +`-`*`%
> ┌─────────────┐
> │┌─┬─────────┐│
> ││0│┌─┬─┬─┬─┐││
> ││ ││+│-│*│%│││
> ││ │└─┴─┴─┴─┘││
> │└─┴─────────┘│
> └─────────────┘
>    AdverbToPackvuGerundWithAt=:< o ((('@:') ; < o |.)) o (('';1)&{::) hg
>    (-`<) AdverbToPackvuGerundWithAt
> <@:-
>    3 (-`<) AdverbToPackvuGerundWithAt 2
> ┌─┐
> │1│
> └─┘
>    AdverbToPackReverseOrderGerundWithAt=: ([ , (<'@:') , ])/o |. o
> (('';1)&{::)hg
>    *:`-`%`+: AdverbToPackReverseOrderGerundWithAt
> +:@:%@:-@:*:
>    *:`-`%`+: AdverbToPackReverseOrderGerundWithAt 5
> _0.08
>    ConjunctionToExecuteVWithArgumentU=: ((an f.hg) (` (|. o
> ((('';1)&{::))hg)) (an f.hg))
>    1 2 3 ConjunctionToExecuteVWithArgumentU (+/)
> 6
>
>
> Cheers,
>
>
> Erling Hellenäs
>
>
>
> On 2017-10-21 21:52, Erling Hellenäs wrote:
>>
>> My a2 name :)
>>
>>     InfinityAdverb=: (`(<(":0);_)) (`:6)
>>
>> %InfinityAdverb
>>
>> 0
>>
>> /Erling
>>
>>
>> On 2017-10-21 20:45, Raul Miller wrote:
>>>
>>> Here's one issue:
>>>
>>>     1 2 3 *: av
>>> 1 4 9
>>>     load'debug/dissect'
>>>     dissect '1 2 3 *: av'
>>> Syntax error: invalid sequence Noun Verb
>>> Error snippet: 1 2 3 *: av
>>>
>>> But that's not a syntax error.
>>>
>>> And, for reference, here are two distinct implementations of av. First
>>> an explicit approximation:
>>>
>>> LR=: 5!:5@<
>>> LRA=:1 :0
>>>    (LR 'u'),' m'
>>> )
>>> AV=:1 :0
>>>    1 :(u LRA)
>>> )
>>>
>>> Second, a restatement of Jose's code (but with a few different names):
>>>
>>>     ar=: 5!:1@:<
>>>     bGerund=: `''
>>>     Compose=: (@:[) ((<'&')`) (`:6)
>>>     a2=: (`(<(":0);_)) (`:6)
>>>     av=: ((ar'bGerund')`)  (`(ar'Compose')) (`(ar'a2') ) (`:6)
>>>
>>> I am still trying to think up a good name for a2 - roughly speaking
>>> it's a placeholder which winds up being ignored in the result of the
>>> Compose verb. I was interested in what dissect had to show me about
>>> the evaluation process here, but that's not relevant to this problem,
>>> which you can see by replacing av with AV.
>>>
>>> #################################################
>>>
>>> That said, it's perhaps also interesting that trace is also buggy:
>>>
>>>      trace '1 2 3 *: AV'
>>>   --------------- 5 Fork -------
>>>   1 2 3
>>>   *:
>>>   AV
>>>   1 2 3 *: AV
>>>   ==============================
>>>
>>> The problem seems to be an incomplete handling of locales. While trace
>>> executes in the jtrace locale, the sentence it is executing comes from
>>> a different locale (typically the base locale). This means that 4!:0
>>> in movet treats AV as an undefined name (and, thus, a verb).
>>>
>>> A quick and dirty fix would be to add
>>> coinsert 'base'
>>> to the top of addons/general/misc/trace.ijs (right under
>>> cocurrent'jtrace').
>>>
>>> This has two flaws but it's still better than nothing:
>>>
>>> (1) it won't work when trying to trace in another locale,
>>> (2) it will still shadow base names with jtrace names.
>>>
>>> Problem 2 could be avoided by replacing uses of 4!:0 and ". with names
>>> which are defined in the z locale (nc and do), and suffixing them with
>>> locale references. Still not perfect (because relies on z), but
>>> implementations which shadow z are already dubious.
>>>
>>> I have no idea about problem 1 - maybe documentation would be the best
>>> solution there. (Another possibility would be to add feature to the
>>> locale support, to detect locale of the caller - but I can't think of
>>> any non-obfuscation uses of that feature. And, yes, ... I guess I
>>> might have to include "making jtrace automatically work regardless of
>>> the current locale of the global session" as obfuscation. I am not
>>> sure about that...)
>>>
>>> #################################################
>>>
>>> Anyways, since this is getting long, I have reported two problems here:
>>>
>>> (1) An invalid "syntax error" in dissect
>>> (2) A serious name resolution problem in trace
>>>
>>> Thanks,
>>>
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
>
> ----------------------------------------------------------------------
> 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