On 11/26/2017 01:27 PM, Raul Miller wrote:
You don't really mean that. ;)
I do.

A function is a relationship between argument and result where there's
each argument has exactly one result.
That's the mathematical definition.  I'm talking about programming.
So a function of no arguments
would have no result. Or, if we are being generous, we could declare
that it has a constant argument (and, thus, a constant result). So
that would be a constant.

What you are asking for, I think, actually, is a procedure which
produces different results at different times based on whatever
obscure variables or whatever it depends on. (And your example of a
random number generation process sort of illustrates that concept.)
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.

(But when used in a tacit definition, you can just use your randdie as
is - it will ignore its arguments so put it where ever that fits.)

Anyways... the technical answer is "no".
Thanks.
The practical answer is "but
that should not matter"
Maybe.  It does make some things more verbose.  For example, suppose I need a random real in a function.  If I call ?0 in a tacit function the expression is evaluated only once, at the time of definition, and thereafter whenever the function is called the same value of ?0 is used.  Similarly, I defined a function randel to take a random element from a list.  If I want to take a random element of a list l in a tacit function, I can't just do

rand =: randel l

because then rand is a constant: the body of the definition is not reevaluated whenever rand is called.  To get the desired behavior I could use

rand =: randel @: (3 : 'l')

which is a bit gross.  Why does J conflate the category of tacit definitions with that of definitions that don't need to be reevaluated?

and the obscure answer is that you can map a
variable to a file if you really want to extend the reach of your
system (but that has all sorts of implications which you probably were
not looking for, so let's stick with the other two answers?)
I have absolutely no idea what this means, but I guess it's not important.

Anyways, I hope this helps (but it probably doesn't...).

Thanks,


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to