OK. Your strategy of discarding the head of
random sequence of the base representation
is winning. Moreover, there is no hope of turning it into
array processing code. But the "notation" could be restated
in a different taste for a number of reasons besides goto.
dice3=: 9999&$: : (4 : 0)"0
y=. x #.^:_1 y-1
q=. (1+{.y) , x
r=. ''
while. r <&# y do.
r=. r, ? (*#r) { q
select. * ({:r) - (<:#r){y
case. 1 do. r=. ''
case._1 do. break.
end.
end.
x #. r , ? (y -&# r) # x
)
> I am not sure which one you are referring to, switch, or
> throw/catch pair, please elaborate.
> Neither of them would work naturally in this situation. Or
> you can demonstrate otherwise, if you disagree.
Hah, I was right you didn't know it. Well, I guess some
things are better left unknown. Plus it's not in the sprit of
the piscine tradition. I can only say that in numerous
JavaScripts I have seen and wrote, I recall seeing it
only once in my own code, for completeness (i.e. vanity).
There is a place for goto: the good old APL is a most
prominent example. Another interesting language that
comes to mind is FOCAL.
----- Original Message ----
From: Andrew Nikitin <[EMAIL PROTECTED]>
To: [email protected]
Sent: Saturday, July 15, 2006 12:18:43 AM
Subject: [Jbeta] monadic '?' (and #. slowdown
Oleg Kobchenko:
> How about this for a simple unoptimized solution:
>
> dice2=: 9999&$: : (4 : 0)"0
> d=. x (>[EMAIL PROTECTED] # [) y
> while. y <: z=. (#.?) d do. end.
> z
> )
Not very practical. For one thing, in the form it is written
it fails to produce desired result on large extended
integers, the entire reason for this endevour.
Even with the obvious fix try
6!:2 'z=.9999x dice2 9999#.1,150$9998x'
9.34617
and compare it to the verb from wiki.
Depending on how paranoid you are about your random
numbers, rnd can be expensive operation. It makes practical sense
for the algorithm to discard as little of precious
randomness as possible.
> JavaScript and Java do have a goto statement,
> it's just called differently to fit with the structural model.
> That explains it why your JavaScirpt programs look
> so nicely readable and unobfuscated--you just haven't
> discovered it.
I am not sure which one you are referring to, switch, or
throw/catch pair, please elaborate.
Neither of them would work naturally in this situation. Or
you can demonstrate otherwise, if you disagree.
I am amazed how decades of brainwashing and propaganda (I am
referring here to goto bashing) really make some people not to
see the obvious. And you, among all the rest, should be at
least slightly inoculated to such things.
The naked truth is: goto is very effective, simple, straightforward,
predictable and easy to read construct. Any convoluted
attempts to avoid it in places where goto is appropriate lead
to atrocities far uglier than any mild occasional misuse of goto.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm