Yes and no. And no and yes.

The other trick (besides using an event handler) involves using memory
mapped files. http://www.jsoftware.com/papers/mmf.htm

And, the obvious implementation there does not get you any
synchronization between J and the data source.

But, in any good-sized real application, you're not going to know if
something else is calling your "niladic function", so you should
expect some "de-synchronization" in actual use.

Still, down near the leaves of your call trees, you should expect
things to stay synchronized (at least until someone does a maintenance
"fix" on your code), so to really do this right you would need to
invoke OS support to find when the mmaped file is being read so that
it can be updated. And, that's actually doable if you get into the
right levels of the OS,  if you are willing to tie it into J's
interpreter.

Why you would want to go to that level of effort, though, when there's
much more obvious, and efficient, ways of accomplishing the same
thing, is beyond me.

-- 
Raul

On Sun, Apr 24, 2016 at 11:13 AM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> Are you saying that you can create a noun in J such that could result in the 
> following outputs?
>
>  count
> 0
>
>  count
>
> 1
>
>
>
> how?
>
> The traditional way to understand nilad (still prefer nonad) is a void 
> function.  The design makes sense if you want to optimize around returning a 
> function.  Calling with '' is not any harder than calling with ().  And 
> though it creates a learning cliff, optimizing the language around the exit 
> command intuitiveness seems like a dubious idea.
>
>
> V =: 1 : 'u i.0'
> TOGGLE =: 1
> toggle =: 3 : 'TOGGLE =: -. TOGGLE'
>
> 6!:0 V
> 2016 4 24 10 56 41.806
>
>
> toggle i.5
> 0
> toggle"0 i.5
> 1 0 1 0 1
>
> toggle V"0 i.5
> 0 0 0 0 0
>
>
> V (stands for void) doesn't seem obviously useful, but it turns a verb into a 
> noun by calling it, and it behaves like N"0 (called once and applied many 
> times) instead of v"0 (called for each scalar)
>
>
> ----- Original Message -----
> From: Raul Miller <[email protected]>
> To: Programming forum <[email protected]>
> Sent: Saturday, April 23, 2016 12:20 PM
> Subject: Re: [Jprogramming] Foreigns
>
> Well....  actually... it *is* possible to achieve the effect of an APL
> niladic function.
>
> Specifically, it is possible, in J, to create a noun which
> auto-updates its value. It's even possible to do this without the
> atomic update constraint that comes with using an event handler to
> achieve the updating (you can use a memory mapped file and arrange for
> that file to be updated outside of J).
>
> See... this whole "noun/verb/..." thing is about the grammatical
> properties of the words - the required surrounding sentence structure.
> You need to understand the grammar to understand how the sentence fits
> together. (Also, as with APL, the requirements are mechanical and
> narrow and have a bit more to do with the valence concept borrowed
> from chemistry than the sheer volume of life experiences one is
> expected to master when dealing with something like English.)
>
> In other words, the sentence structure in J is about how the words get
> used, what they achieve depends on how they were defined.
>
> That said, what I think you were getting at was that defining what an
> APL programmer would have called a niladic function requires some
> indirection (or extra work), in J.
>
> And, personally, I think that extra work on the part of the programmer
> is appropriate - since understanding that kind of construct also
> requires extra work on the part of the reader. (It's also one of those
> "why would anyone want this?" kind of things.)
>
> My dad used to grumble a lot about how all too often we have solutions
> looking for problems, rather than actually trying to fix real
> problems. I tend to agree. And I am certainly happy to classify the
> whole "niladic function" issue in that bucket.
>
> Thanks,
>
> --
> Raul
>
>
> --
> Raul
>
>
> On Sat, Apr 23, 2016 at 7:49 AM, Louis de Forcrand <[email protected]> wrote:
>> I believe your original question was wether it was possible to remove the '' 
>> after a verb. This is called a niladic (like monadic/dyadic) verb in APL, 
>> but is not possible in J.
>>
>> If you wish to "fix" an argument to a verb, you can do so by creating a 
>> constant verb that returns the argument in question, so as to discard the 
>> actual argument you call the verb with:
>>
>> f=: u@(m"_)
>> "f y" would execute monadic u with argument m regardless of y.
>> There is a stdlib conjunction called "bind" that does exactly this.
>>
>> Best regards,
>> Louis
>>
>> Sent from my iPhone
>>
>>> On 21 Apr 2016, at 16:20, Martin Kreuzer <[email protected]> wrote:
>>>
>>> Don -
>>> As (exit=: 2!:55) in stdlib.ijs showed it being simply a synonym, I now 
>>> understand
>>> Bill -
>>> your suggestion to handle these (sdt=: 6!:0), (ppchk=: 9!:10) ... in a 
>>> similar manner.
>>> -M
>>>
>>> At 2016-04-17 13:32, you wrote:
>>>> "exit" is defined in 'system/main/stdlib.ijs' at line 226 in J804. J 
>>>> provides tools for timer events (see QT Demos/timer) but these timer 
>>>> events won't run until J is ready for input. So a noun like a current 
>>>> minute will not update while a long running script is running. If it is 
>>>> that you want a noun that is updated by an external event like the time of 
>>>> day it may be overkill, but you could share a name with another instance 
>>>> of J which only runs a timer and updates the name when something like the 
>>>> current minute changes. On Sun, Apr 17, 2016 at 2:59 AM, Martin Kreuzer 
>>>> <[email protected]> wrote: > Don - > Thanks for reminding me of the 
>>>> shortcut to minutes via (4{sdt). > > Don, Bill - > Thanks for your 
>>>> suggestion defining the stuff as a verb (I did some > experimenting along 
>>>> that road), but that doesn't put away the need to call > it with an empty 
>>>> string as a parameter (sdt '') (mins ''). And I think that > anwers my 
>>>> original question: it is always needed ... > btw, (exit y) being a 
>>>> "wrapper" for (2!:55 y), could you point me to its > (exit) definition..? 
>>>> > > Raul - > Thanks for pointing me to the (wd) command reference (I 
>>>> wasn't aware of > that). > I successfully tried your timer example (having 
>>>> first experienced the need > for cleanup :), but only while calling the 
>>>> verbs with parameter (sdt '') > resp (mins'') -- different to what you 
>>>> cited in your mail where you seem to > have used (sdt) solely ... > > -M > 
>>>> > At 2016-04-16 18:18, you wrote: > >> In addition to bill lam's excellent 
>>>> advice, there's also >> 
>>>> http://code.jsoftware.com/wiki/Guides/Window_Driver/Command_Reference  >> 
>>>> which may interest you. Consider, for example:    wd 'timer 30000' |value 
>>>> >> error: sys_timer_z_ |   (i.0 0)"_     sys_timer_z_$0 |value error: >> 
>>>> sys_timer_z_ |   (i.0 0)"_     sys_timer_z_$0 |value error: sys_timer_z_ | 
>>>> >>  (i.0 0)"_     sys_timer_z_$0 Now, if I define:    sys_timer_z_=: verb 
>>>> def >> 'sdt=: 6!:0 y' and wait for the timer event to go off, I have a 
>>>> value for >> sdt And, now that I see that it's working (so I do not have 
>>>> to shut down my >> J session to regain control), I can make the timer 
>>>> event run more often: >> sdt 2016 4 16 14 11 27.4896    wd 'timer 1'    
>>>> sdt 2016 4 16 14 12 30.5991 >>   sdt 2016 4 16 14 12 31.4788 Here, I have 
>>>> asked jqt to keep executing that >> command line ((i.0 0)"_    
>>>> sys_timer_z_$0) once every millisecond whenever >> I'm not doing anything 
>>>> else. (The way it works, if something long running >> is happening, that 
>>>> command line can't be run, so those events get skipped.) >> But maybe keep 
>>>> in mind mickey mouse's experience in fantasia (the >> sorcerer's 
>>>> apprentice): if this gets out of control, you'll have quite a >> mess to 
>>>> clean up. I hope this helps, -- Raul On Sat, Apr 16, 2016 at 9:24 >> AM, 
>>>> bill lam <[email protected]> wrote: > std is a noun, (or a value >> in 
>>>> other programming languages). It is usually > immutable.  Just curious, >> 
>>>> why didn't you write > sdt=: 6!:0 > ppchk=: 9!:10 > or > sdt=: 3 : '6!:0 
>>>> y' >> > > min=: 3 :0 > {: 5 {. sdt y > ) > > For the other question, IEEE 
>>>> double >> precision is limited to 15 or 16 > significant digits, so that 
>>>> print >> precision cannot improve accuracy. > On Apr 16, 2016 6:48 PM, 
>>>> "Martin >> Kreuzer" <[email protected]> wrote: > >> One of my teachers 
>>>> once told >> me "It's even sillier to not ask a silly >> question" ... so 
>>>> here I go: >> >> >> Extracting SystemDateTime I do get a vector like this 
>>>> >>    ] sdt=. 6!:0 >> '' >> 2016 4 16 9 12 59.257 >> which -from now on- 
>>>> has that value >>    sdt >> >> 2016 4 16 9 12 59.257 >> >> To get the 
>>>> current minute I might do >> something like >>    ] mins=. {: 5 {. sdt >> 
>>>> 12 >> which gives the same >> result some time after, unless I explicitely 
>>>> do >>    ] mins=. {: 5 {. >> sdt=. 6!:0 '' >> 30 >> >> Q: >> Is there a 
>>>> way to sort of "wrap" the >> foreign (6!:0 '') so that "sdt" will >> show 
>>>> the _current_ date/time string >> when called..? >> (Sorry if I missed to 
>>>> make myself clear.) >> >> Same >> question arose when e.g. trying stuff 
>>>> like >> -- check print precision >> >>   ppchk=. 9!:10 '' >> -- set print 
>>>> precision >>    ppset=. 3 : '9!:11 (y)' >> NB. seems to work ... >>    
>>>> ppset 7 >> >>    9!:10 '' >> 7 >>    ppchk >> 7 >> >>    ppset 11 >> >>    
>>>> 9!:10 '' >> 11 >>    ppchk  NB. has (of course) >> still the previous 
>>>> value ... >> 7 >> >> And (again) here comes the silly >> >> Q: >> Is there 
>>>> a way to define "sdt" or "ppchk" (from above) so that they >> >> 
>>>> immediately react to changes to the environment..? >> (Looks to me if >> 
>>>> I'm asking for a verb without a noun to act on; is that >> the moment the 
>>>> >> empty string ('') comes into play and the dog chases its >> tail..?) >> 
>>>> >> >> -M >> >> >> 
>>>> ----------------------------------------------------------------------  >> 
>>>> >> 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
>
>>>
>>> ----------------------------------------------------------------------
>>> 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