A generalized array is only an array of links to arrays? When you allocate a new generalized array, the arrays it links to can remain? When you assign a new array in a cell of your generalized array, all you have to do is set a link to the array assigned to the cell? /Erling

On 2014-07-08 01:11, Dan Bron wrote:
J is not a pure functional language. But tacit J is a (n almost) purely 
functional subset of J (exceptions include things like ? and s:, but much more 
importantly !:).

In particular, tacit J /has no variables/. You can't, in any way, modify a 
previous result, because you have no way to refer to a previous result. All you 
know about is your input(s), and all you care about is your outputs. Tacit J is 
no more than a notation for describing how to transform inputs to outputs. 
That's all any functional language is.

Now, it happens to be that under to covers, J is copy-on-write, so that any 
time your tacit code amends an array (whether using } or + or %, which are 
conceptually the same), a new array is created and the original is left 
untouched. Sometimes a copy is made first and then modified, sometimes the new 
array is built up element by element, but that's irrelevant: an implementation 
detail.

But then, so is the fact that J is copy-on-write. If the interpreter could 
somehow determine that there was no further need for your input array, and than 
from here on only your output would be used, then it could decide, as an 
optimization, to reuse the memory allocated to the input and under the covers 
make the smallest amendment required to produce your output. But the key is 
that the input and output are logically distinct and the notation treats them 
as distinct and presents them to you as distinct, and if the interpreter reuses 
some memory under the covers, that's no more than an optimization. Tacit J is a 
functional language, regardless if you express your transformation of input to 
output using * or # or } or anything else, because it /has no variables/ [1].

Now explicit J is different story, because there, you've got =: and =.  . Now 
it happens that explicit J also happens to be mostly copy-on-write, but again 
that's an implementation detail. Since you have the logical capability to 
create, mention, and (critically) reassign vairables, explicit J is not 
functional, whether or not J reuses memory behind the scenes. Once you reassign 
a variable, you have no access to its previous value, whether or not that 
happens to still be in memory (ie, it's entirely possible for some previous 
value to be available to the interpreter but not to you). Again this applies 
irrespective how you achieved your modification, be that + or # or } or 
anything else.

In fact, the current implementation of explicit J (unlike the current 
implementation of tacit J) does offer the J programmer the option to optimize 
by reusing memory in certain cases, amend prominent (and mapped files 
notorious) among them. And amend is famous and mapped files infamous precisely 
because reuse of memory corresponds to reuse of variables in the former case 
and not in the latter (that's worth thinking about, BTW).

But the key is that's an implementation detail. a performance optimization, a 
convenience extended to the user. It has nothing to do with J qua a language, 
or the ability to formally reason about programs and their correctness. It's 
the existence of variables and the ability to reassign them that makes a 
language functional or not, not the tools it provides (or doesn't) to express 
calculations. Explicit J has variables and lets you reassign them; tacit J does 
not and (thus) can not. In short: tacit J is functional and explicit J isn't, 
and that doesn't depend, in either case, on what calculations you use, whether 
it's + or # or even } .

-Dan

[1] In fact the constraint is stronger: tacit J expressions don't even mention "data" (witness the 
absence of a lambda, just processes), which is why we prefer the label "function-level"  as opposed 
to straight "functional".

In other words, a function-level language is concerned with the composition of 
processes, whereas a functional language puts the focus on being side-effect 
free. This difference in focus may be one reason even pure tacit J is not truly 
functional (especially that non-functional bugbear !:).

Please excuse typos; sent from a phone.

On Jul 7, 2014, at 6:07 PM, Erling Hellenäs <[email protected]> wrote:

A principle of functional programming is you never modify a variable? What 
Amend does is create a new variable from other existing variables? Nothing is 
amended? /Erling

On 2014-07-07 23:50, Jose Mario Quintana wrote:
Erling wrote:
"
It's obviously not possible to do any amendments in tacit code? It is also
less elegant to pass these three parameters in the two arguments in tacit
code?
"

Well, Raul and I showed general verbs to perform amendments tacitly.  Once
I was as puzzled as you are (were?) but I found enlightenment; maybe you
can find it as well:
http://www.jsoftware.com/pipermail/general/2000-September/004192.html




On Mon, Jul 7, 2014 at 1:53 PM, Erling Hellenäs <[email protected]>
wrote:

It's obviously not possible to do any amendments in tacit code? It is also
less elegant to pass these three parameters in the two arguments in tacit
code? Any opinions about the use of From to do the same thing?


NB. x and y are arrays of the same rank
NB. q is a boolean, also of this rank
NB. The expression merges x and y.
NB. Where q is TRUE it picks from y, otherwise x
NB. q {"0 1 x,"0 y

If q is a vector and if we actually have a variable z of rank (+/q),}.$y
we can easily create x from q#^:_1 [ z ? No use for any indexes?

/Erling
----------------------------------------------------------------------
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