Sorry Thomas, your posting crossed with mine...

Just when I was declaring that it was _not_ the way I wanted to do it.

I must apologise: I was dismissing your idea too hastily. That's me
all over: defining a problem in terms of one of its solutions.

But not the only one.

Interpreting you liberally, I hear you telling me to insert probes
throughout my target locale. I wrongly assumed because it was someone
else's code I wasn't free to do that. And instinctively I shy away
from string-processing the contents of definitions -- that really does
go to wonderland.

I shall carry on using my timer-plagued "trigger" technique (thank
you, Stefano) in the app development phase. But ship a script that
runs without timers, by tooling it up as you suggest (...kinda).

Years ago, I saw an APL diagnostic workspace that took your code,
renamed all the functions and generated covers for them with your
original names. It was then able to offer all the facilities I was
calling for.

The J language makes this process even easier, thanks to adverbs
(again something you suggested). And in a reversible way, so you can
reliably take all the swabs out the patient. It's so easy I've just
tried it out. Like so...


cutely=: adverb define  NB. diagnostic tool
z=. u y
:
z=. x u y
)

doSomethingX=: -        NB. ...sample target verb

doSomething=:   doSomethingX cutely

smoutput doSomething 2
smoutput 3 doSomething 2


You can now instrument "cutely" how you like, to gain everything I've
been asking for (including leveraging 4!:5). And plug-replace it at
will. Like so...

cr=: [: 5!:5 boxopen
log=:   [: ": ;: ,: [: ".&.> ;:

cutely=: adverb define  NB. diagnostic tool/ INSTRUMENTED
Y=: y
U=: u
T=: >type 'U'
CRU=: cr 'U'
Z=: u y
Z [smoutput log 'Z : CRU T Y'
:
Y=: y [ X=: x
U=: u
T=: >type 'U'
CRU=: cr 'U'
Z=: x u y
Z [smoutput log 'Z : X CRU T Y'
)

...

   load '/Users/ianclark/j602-user/explicit_adverb_example3.ijs'
┌──┬─┬────────────┬────┬─┐
│Z │:│CRU         │T   │Y│
├──┼─┼────────────┼────┼─┤
│_2│ │doSomethingX│verb│2│
└──┴─┴────────────┴────┴─┘
_2
┌─┬─┬─┬────────────┬────┬─┐
│Z│:│X│CRU         │T   │Y│
├─┼─┼─┼────────────┼────┼─┤
│1│ │3│doSomethingX│verb│2│
└─┴─┴─┴────────────┴────┴─┘
1


Nice.



On Wed, Jan 26, 2011 at 3:46 PM, Thomas Costigliola <[email protected]> wrote:
> 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to