Yes. And note:
d * y >: 0
might have 2 numeric operations, or it might have just 1. It depends on
the implementation.
x * boolean
could be implemented as a loop to store 0 to the values of x
corresponding to zero y (and might be thus already, for aught I know).
Array thinking. Avoiding conditionals. Thinking big. Using
arithmetic. All keys to good J.
Henry Rich
On 5/18/2013 7:02 PM, Roger Hui wrote:
We don't do anyone any favors by providing
if. y<0 do. c elseif. y>:0 do. d end.
instead of
(c*y<0)+(d*y>:0)
For one thing, the former has to work scalar-by-scalar, and for now and for
the forseeable future it'll be orders of magnitude slower that the latter
expression.
There are many places where newer and better ways of doing things could
be added to save lots of new users many pitfalls.
Yes, we have newer and better ways of doing things; it's called array
thinking, and booleans returning 0 and 1 instead of false and true, and ...
On Sat, May 18, 2013 at 1:41 PM, Linda Alvord <[email protected]>wrote:
try=: 3 : 0
c=:12
d=:14
if. c*y<0 do. c elseif. d*y>:0 do. d end.
)
try _3
12
try 0
14
try 3
14
c=:12
d=:14
y=:_3
(c*y<0)+(d*y>:0)
12
x=:0
(c*y<0)+(d*y>:0)
12
x=:3
(c*y<0)+(d*y>:0)
12
Roger, Most people seem to go first to the vocabulary to find a starting
place to solve their problems.
Wouldn't it be useful to go to "Control Structures" to find a major
improvement such as the one you just wrote:
if. c*y<0 do. c elseif. d*y>:0 do. d end.
or:
(c*y<0)+(d*y>:0)
There are many places where newer and better ways of doing things could be
added to save lots of new users many pitfalls.
Linda
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm