To go a step further it may be less intrusive to define, normally, all
your verbs in a special locale. Then you can write a verb that will
redefine all the verbs in a given locale to set INVERB properly while
being careful not to create any recursion.

On Wed, Jan 26, 2011 at 10:42 AM, Thomas Costigliola <[email protected]> wrote:
> On Tue, Jan 25, 2011 at 10:49 PM, Henry Rich <[email protected]> wrote:
>> I don't know of any way to find the caller without turning on debug.
>>
>> If you need a third operand to a verb, you can make the verb an adverb:
>
> Alternatively, if you want to get wacky, you can have a verb know its
> name by redefining (=:) along these lines:
>
>   define=. 2 : 0
> (m)=: v @: (][ do @: (('INVERB=:(''',m,''')')"_))
> )
>
>   verbx=. 3 : 0
> INVERB , ')' ,~ '(' , ":y
> )
>
>   'verb' define verbx
> verbx@:(] [ do@:('INVERB=:(''verb'')'"_))
> ┌─────┬──┬────────────────────────────────────┐
> │verbx│@:│┌─┬─┬──────────────────────────────┐│
> │     │  ││]│[│┌──┬──┬──────────────────────┐││
> │     │  ││ │ ││do│@:│┌────────────────┬─┬─┐│││
> │     │  ││ │ ││  │  ││INVERB=:('verb')│"│_││││
> │     │  ││ │ ││  │  │└────────────────┴─┴─┘│││
> │     │  ││ │ │└──┴──┴──────────────────────┘││
> │     │  │└─┴─┴──────────────────────────────┘│
> └─────┴──┴────────────────────────────────────┘
>   verb 10
> verb(10)
>
>   'brev' define verbx
> verbx@:(] [ do@:('INVERB=:(''brev'')'"_))
> ┌─────┬──┬────────────────────────────────────┐
> │verbx│@:│┌─┬─┬──────────────────────────────┐│
> │     │  ││]│[│┌──┬──┬──────────────────────┐││
> │     │  ││ │ ││do│@:│┌────────────────┬─┬─┐│││
> │     │  ││ │ ││  │  ││INVERB=:('brev')│"│_││││
> │     │  ││ │ ││  │  │└────────────────┴─┴─┘│││
> │     │  ││ │ │└──┴──┴──────────────────────┘││
> │     │  │└─┴─┴──────────────────────────────┘│
> └─────┴──┴────────────────────────────────────┘
>   brev 13
> brev(13)
>
> This can be improved further to properly handle dyadic calls and
> nested calls and to allow for direct input of an explicit function as
> in:
>
> 'verb' define
> INVERB , ')' ,~ '(' , ":y
> )
>
> Of course that will only work if you can define everything with
> 'define' instead of (=:).
>
>>
>> vb =: adverb define
>>
>> and then you could call it with
>>
>> x ('caller' vb) y
>>
>> (where the parens are optional).
>>
>> In the old days, turning on debug made my big apps crash.  I think it's
>> been fixed now, but I'm still like Mark Twain's cat.
>>
>> Henry Rich
>>
>> PS Oops. I see you don't want to change the caller.  I have no help then.
>>
>> hhr
>>
>> On 1/25/2011 10:06 PM, Ian Clark wrote:
>>>> The question is why you are doing this.
>>>
>>> I'd rather not go into that. You have to study the middleware I'm
>>> porting from APL to relate to why I need a function which knows the
>>> name of its caller. And without the caller having to go to the trouble
>>> of telling it. The tool makes heavy use of two utility functions:
>>> "myname" and "mycaller", whose function should be obvious, even if
>>> their application isn't. And please don't ask why a function might
>>> conceivably need to discover its own name: the requirement has been
>>> known to arise.
>>>
>>> In APL the solution is easy: the stack is always available for a
>>> function to inspect while it's running. In J you have to switch the
>>> suspension stack on. Is this because the facility is quirky and
>>> inefficient, or simply because a lot of people don't need it or want
>>> it -- as I don't, as a rule?
>>>
>>> "mycaller", implemented the APL way, is working fine (touch-wood). But
>>> if there's a slick J technique without enabling the suspension stack
>>> then it would simplify the code considerably and I can lose a few
>>> heavily-looping saddle-functions.
>>>
>>>
>>>
>>> 2011/1/25 Björn Helgason<[email protected]>:
>>>> The question is why you are doing this.
>>>>
>>>> If it is because of development or something you want for when the system 
>>>> is
>>>> running.
>>>>
>>>> You can of course make sure the caller sends its name in as part of
>>>> arguments passed.
>>>>
>>>> During development I usually pepper smoutput all over the code.
>>>>
>>>> For a running application I usually write out stuff in logfiles and/or use
>>>> wdstatus to see if everything is running ok.
>>>>
>>>>
>>>> 2011/1/25 Ian Clark<[email protected]>
>>>>
>>>>> If I define two or more verbs tacitly like this:
>>>>>
>>>>> act1 =: action
>>>>> act2 =: action
>>>>> ...
>>>>>
>>>>> how, inside the verb: action, can I identify the calling verb --
>>>>> ideally as the literal name, eg 'act1'?
>>>>>
>>>>> I can solve the problem ...
>>>>>
>>>>> (a) by having the caller pass its own name as an argument in a rather
>>>>> more complex tacit expression, eg
>>>>>
>>>>> act1 =: action bind 'act1'
>>>>> act2 =: action bind 'act2'
>>>>> ...
>>>>>
>>>>> (b) by enabling suspension with: (13!:0)1 (in the caller of act1,
>>>>> act2) and then inspecting the stack within action by means of  0{"1
>>>>> (13!:13 '')
>>>>> ...which is what I'm using at present.
>>>>>
>>>>> (a) is not out of the question, but complicates the code, especially
>>>>> generated code.
>>>>> And I don't like (b) -- besides being clumsy I anticipate gotchas in
>>>>> the long term.
>>>>>
>>>>> Am I right to feel edgy about (b), for general application?
>>>>>
>>>>> Is there a neater way?
>>>>> ----------------------------------------------------------------------
>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Björn Helgason, Verkfræðingur
>>>> Fornustekkum II
>>>> 781 Hornafirði,
>>>> t-póst: [email protected]
>>>> gsm: +3546985532
>>>> sími: +3544781286
>>>> http://groups.google.com/group/J-Programming
>>>>
>>>>
>>>> Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans
>>>>
>>>> góður kennari getur stigið á tær án þess að glansinn fari af skónum
>>>>           /|_      .-----------------------------------.
>>>>          ,'  .\  /  | Með léttri lund verður        |
>>>>      ,--'    _,'   | Dagurinn í dag                     |
>>>>     /       /       | Enn betri en gærdagurinn  |
>>>>    (   -.  |        `-----------------------------------'
>>>>    |     ) |         (\_ _/)
>>>>   (`-.  '--.)       (='.'=)   ♖♘♗♕♔♙
>>>>    `. )----'        (")_(") ☃☠
>>>> ----------------------------------------------------------------------
>>>> 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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to