[Jprogramming] FW: A simple function
dhky at shaw.ca
dhky at shaw.ca
Mon Nov 28 12:37:03 HKT 2011
and -----Original Message-----
From: Linda Alvord
Sent: Saturday, November 26, 2011 7:56 PM
To: 'Programming forum'
Subject: Re: [Jprogramming] FW: A simple function
Here you have the code that creates the result. Copy and paste and execute
it and you should get a readable tree diagram of the verb.
f=: 13 :'<.0.5+x*%:x*y'
f
[: <. 0.5 + [ * [: %: *
Or you can now write a tacit definition with the above result
g=:[: <. 0.5 + [ * [: %: *
4 f 17
33
4 g 17
33
5!:4 <'f'
-- [:
+- <.
--+ -- 0.5
+- +
L----+ -- [
+- *
L-----+ -- [:
L---+- %:
L- *
Linda
----------------------------
As a beginner, I would suggest an explicit formulation to start- just to get
the logic in order and test it.
For example work out on paper the step by step logic involved. Then put it
together and it may take a few trials to get it to work- then after some
stumbling around, get it together as an explicit definition such as:
f1=: dyad define
<. 0.5 + x*%:x*y
)
4 f1 17
33
Then proceed to deal with the parts that I am not yet comfortable with (at
least getting them to do what I want)
i.e. using [: and [ correctly-I think that I have been adding an
unnecessary ] and not breaking things down as I should.
f1
4 : '<. 0.5 + x*%:x*y'
4:<. 0.5 + x*%:x*y
This leads to :
f2=:4 : '<. 0.5 + x*%:x*y'
which is the same as f1 (but has no computational or comprehension
advantages over f1
The difference is the use of [: and [ - cap and same right vs the x and y
Does this mean anything of importance?
It appears to as even in this simple case, your g and f win hands down in
terms of performance.
The performance of g vs f1 (1000 iterations)
time: 60%
space: 41%
This appears to be costs of storage of x and y.
The f1 and a transition to f2 are more direct in terms of seeing the logic
for a raw beginner and are good to experiment with (using a script file
because direct editing is a bit more cumbersome in the ijx window). This
comes down to one of the problems with learning J- we don't have a Gilman
and Rose as for APL and some of the vocabulary/dictionary material is
difficult to follow at first- in that it tends to jump to examples that
require prior knowledge of more advanced methods. It is a bit like ordering
a meal in a foreign country with no translator and a cook who wants a
laugh - does special bong mean raisins, cowpies, or pot mixed into the
porridge? The frustration index is high.
The bane of computing is that the computer is an idiot and does exactly what
the idiot at the keyboard tells it- not what the latter idiot thinks it is
telling it!
Thank you for an approach using left and right arguments as an alternative
to a right hand vector which also has been explained well- particularly the
use of "cap'.
Don Kelly
cross out to reply
More information about the Programming
mailing list