The reason J has no nullary (niladic, in APL terminology) functions is
that the syntax doesn't support it very well. How do you know when to
evaluate a niladic function? If f is a regular (monadic or dyadic,
depending on context) functions and nil is niladic, is (f@:nil) the same
as ([: f nil)?

Ultimately it's a consequence of not having a special syntax for a
function call (i.e. application is juxtaposition). This choice makes J
code look a lot cleaner, and allows mathematical infix functions to have
the same syntax as user-defined ones. It definitely has consequences,
and this is one of the milder ones.

I tend not to use small "niladic" functions very often--when I write a
function that ignores its arguments, it tends to be a larger explicit
function which does some sort of initialization. That means it's written
as an explicit function that doesn't make any reference to x or y, and
invoked with fun'' rather than fun() as in some other languages. If I do
make a no-argument function, I usually construct it with bind, for
example (".bind'val') to get the value of a variable in a tacit context
or (? bind 20) to get a random number.

Marshall

On Mon, Nov 27, 2017 at 12:50:53PM -0500, Andrew Dabrowski wrote:
> Yes, J has a the function "prompt" that when called with the same argument
> can return different values.  So J is not a pure functional programming
> language like Haskell.  That's why I thought it might allow nullary
> functions.
> 
> I didn't say it was a big problem, it's just a slight problem but one that
> came up when I was trying to do something very simple. That's what worries
> me: I can't write even simple programs without using what seem like kludges
> and workarounds.  No doubt after years of practice those would come to seem
> natural to me and programming in J would be a snap, as has happened to me to
> some extent with Perl.  But Perl I was forced to use, J I have the option of
> placing in the Museum of Brilliant but Useless Languages, next to Haskell.
> 
> 
> On 11/27/2017 12:30 PM, Daniel Lyons wrote:
> > > On Nov 27, 2017, at 10:03 AM, Andrew Dabrowski <[email protected]> 
> > > wrote:
> > > 
> > > Is J supposed to be a pure functional language, like Haskell? Outside of 
> > > that narrow category functions like this are common, and hard to get 
> > > around for io - input functions are like this.
> > > 
> > I thought I’d look into this specific example and found an interesting page 
> > on the Wiki about the problem of reading user input interactively:
> > 
> > http://code.jsoftware.com/wiki/User:Ric_Sherlock/Temp/InteractivePrompt 
> > <http://code.jsoftware.com/wiki/User:Ric_Sherlock/Temp/InteractivePrompt>
> > 
> > All of the examples I see relating to I/O wind up requiring an argument:
> > 
> >   - The foreign conjunction itself needs some parameters to figure out 
> > which function it is returning
> >   - (1!:1) needs an argument of either file name or file descriptor
> >   - The prompt function defined on that wiki page needs an argument for 
> > what prompt to display
> > 
> > I suspect that this is another case where it seems to us newbies like it 
> > would be a big problem, but in practice it really isn’t. I note that the 
> > addon installation procedure tells you to call the function with an empty 
> > string argument. Every language has to make some decisions about how to 
> > handle functions and those decisions always have seemingly-obvious 
> > downsides. Usually they are compensated for by other upsides, but the 
> > upsides aren’t always totally obvious. Ruby, for instance, seems to improve 
> > on Python by not requiring parentheses on nullary functions. But you pay 
> > for that later when you can’t pass a function by reference (you must 
> > instead wrap it in a block). Oftentimes increasing the complexity of a 
> > language’s function system has downstream consequences, like worsening 
> > performance or complicating metaprogramming. TANSTAAFL.
> > 
> 
> ----------------------------------------------------------------------
> 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