Re: [q-lang-users] Re: Optimizations and tweaks
Brought to you by:
agraef
From: <Dr....@t-...> - 2004-10-23 09:20:58
|
Tim Haynes wrote: > def HASH = ref emptyhdict; > > public hashed F X; > hashed F X = get HASH!(F,X) if member (get HASH) (F,X); > = put HASH (update (get HASH) (F,X) Y) || Y > where Y = F X otherwise; > > hashed isprime = hisprime; > > hisprime N = not (any ((=0).(N mod))) (primes (intsqrt N)) ; > > hashed primes = hprimes; > > hprimes N = [2] if N=2; > = [2,3] if N=3; > = [2,3|filter isprime [5,7..N]] otherwise; Hmm, when I run this code over here, the hashed function is apparently never invoked. In fact, with filter isprime [5000000..5000100] I even get a failed condition: ! Error in conditional 0> stdlib.q, line 134: filter isprime [5000011,5000012,5000013,...] ==> [5000011|filter isprime [...]] if isprime 5000011 I think the applications of hashed are the wrong way round (it's easy to fall into this trap, it has happened to me, too). I've attached my (hopefully corrected) version of the script to this post. This one *does* invoke hashed now (verified with tbreak). I'm ready to add this version to the examples now (if you don't complain -- better do that quickly, as I'm currently doing the final touches for Q 6.0 ;-). Cheers, Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikwissenschaft.uni-mainz.de/~ag |