Thanks, that is a clear explanation. I had forgotten about the
mechanism for adverbs. One way I can do it is to define A as a
conjunction, using the right input for the locale (as below). In order
to use conjunctions like this though, one would have to pack the
arguments (as below).
NB. here is one way
f_N1_ =: 3 : 0
2*y
)
A =: 2 : 0
u f__n y
)
loc =. <'N1'
*: A loc 5
NB. here is another way
B_N1_ =: 2 : 0
u f__n y
)
loc =. <'N1'
*: B__loc loc 5
NB. Way to do conjunctions
C_N1_ =: 2 : 0
'loc arg' =. n
arg + u f__loc y
)
loc =. <'N1'
*: C__loc (loc;5) 5
2009/9/16 Oleg Kobchenko <[email protected]>:
> You need to understand that J behavior is as expected:
> when you say in 'base':
>
> *: A_N1_ 5
>
> This means: evaluate A in N1, return the resulting verb
> back into 'base' and apply that verb to 5 in 'base'.
>
> The resulting verb is:
>
> 3 : 0
> *: fun y
> )
>
> Which is applied in 'base'.
>
> So you need to design your code around this behavior.
>
> The way how you described your problem earlier is how
> to alter J natural behavior. Instead, maybe you
> could formulate your underlying goals in broader terms,
> such as polymorphism of functions, or clusters, hierarchies etc.
> and people here may offer an alternative possibly simpler approach.
>
>
>
>
>
>> From: Matthew Brand <[email protected]>
>>
>> This was a simplified version of my problem.
>>
>> I reality I am calling the adverb as:
>>
>> A__f
>>
>> where f =. <'N1'
>>
>> So I cannot write fun__f explicitly.
>>
>> I thought about Bill's solution some more and it does not help because
>> in reality my "fun" references nouns and verbs in the N1 locale, I
>> cannot put them all in _z_ because there are several other locales N1,
>> N2 etc... that are like N1 but have slightly different noun contents.
>>
>>
>>
>>
>> 2009/9/15 Sherlock, Ric :
>> > I have come across this before and solved it by explicitly referencing the
>> verb fun in the adverb:
>> >
>> > cocurrent 'N1'
>> >
>> > fun =: 3 : 0
>> > 2*y
>> > )
>> >
>> > A =: 1 : 0
>> > u fun_N1_ y
>> > )
>> > cocurrent 'base'
>> > *: A_N1_ 5
>> > 100
>> >
>> >> From: Matthew Brand
>> >>
>> >> Thanks, will try it.
>> >>
>> >> Does anybody know a better solution though because this could lead to
>> >> name clashes in a polluted z locale.
>> >>
>> >> 2009/9/15 bill lam:
>> >> > On Tue, 15 Sep 2009, Matthew Brand wrote:
>> >> >> Does anybody know how to make this work? I have an adverb A defined
>> >> in
>> >> >> a locale N1 which references the function "fun" which is also in
>> >> that
>> >> >> locale, but it is called from 'base' as A_N1_ ... How come it cannot
>> >> >> find the verb "fun"? I expected the result to be 100, i.e. *: 2 * 5.
>> >> I
>> >> >> thought that J switched to the locale _N1_ and then executes the
>> >> >> adverb?
>> >> >>
>> >> >> Thanks,
>> >> >> Matthew.
>> >> >>
>> >> >> cocurrent 'N1'
>> >> >>
>> >> >> fun =: 3 : 0
>> >> >> 2*y
>> >> >> )
>> >> >>
>> >> >> A =: 1 : 0
>> >> >> u fun y
>> >> >> )
>> >> >>
>> >> >> cocurrent 'base'
>> >> >> *: A_N1_ 5
>> >> >> |value error: fun
>> >> >> | u fun y
>> >> >
>> >> > I guess it is a design feature that automatic locale switching only
>> >> > works for verb. You may try
>> >> >
>> >> > cocurrent 'base'
>> >> > coinsert 'N1'
>> >> > *: A 5
>> >> >
>> >> > or write the 'fun' in z locale
>> >
>> > ----------------------------------------------------------------------
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>>
>>
>>
>> --
>> The risk is socialized, the profit is privatized.
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
The risk is socialized, the profit is privatized.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm