Re: [Factor-talk] An alternative for foldable?

2008-12-29 Thread Samuel Tardieu
 Sam == Samuel Tardieu s...@rfc1149.net writes:

Sam What is the best way to initialize primes-under-million at
Sam parsing time?

One intermediate solution is to make it foldable despite its output
being mutable. This is not worse semantically than what was done
before when the list was hardcoded (it can be modified by one of its
users). However, it also means that the primes list will be recomputed
when parsing every word that uses primes-under-million.

The following makes it be computed at parsing time, but I guess there
is a cleaner alternative:

USING: compiler.units math.primes namespaces ;
IN: math.primes.list

PRIVATE

SYMBOL: (primes-under-million)

[ 100 primes-upto (primes-under-million) set ] with-compilation-unit

PRIVATE

: primes-under-million ( -- seq ) (primes-under-million) get ;


--
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] An alternative for foldable?

2008-12-29 Thread Doug Coleman
call it as a toplevel form and drop the result.

Doug

On Dec 29, 2008, at 12:10, Samuel Tardieu s...@rfc1149.net wrote:

 Slava == Slava Pestov sl...@factorcode.org writes:

 Slava Make it a MEMO: word. Then the result will only be computed
 Slava once.

 Done, you can pull from

   git://git.rfc1149.net/factor.git for-slava

 However, this will degrade performance for benchmark.binary-search,
 as the list will be computed at the first occurrence.

 Sam
 -- 
 Samuel Tardieu -- s...@rfc1149.net -- http://www.rfc1149.net/


 ---
 ---
 ---
 -
 ___
 Factor-talk mailing list
 Factor-talk@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/factor-talk

--
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] An alternative for foldable?

2008-12-29 Thread Samuel Tardieu
Slava Make it a MEMO: word. Then the result will only be computed
Slava once.

Sam Done, you can pull from
Sam   git://git.rfc1149.net/factor.git for-slava

Sam However, this will degrade performance for
Sam benchmark.binary-search, as the list will be computed at the
Sam first occurrence.

Doug call it as a toplevel form and drop the result.  Doug

Fair enough. Pushed to the same place as well.

  Sam
-- 
Samuel Tardieu -- s...@rfc1149.net -- http://www.rfc1149.net/


--
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] An alternative for foldable?

2008-12-28 Thread Samuel Tardieu
I find it frustrating that foldable cannot be used when the word you
want to apply it to returns a mutable sequence, even if I understand
why.

What could we do to allow compile-time evaluation of words returning
sequences for example? It would be nice to have words such as

  : sum-of-small-primes ( -- n ) 2 10 primes-between sum ;

compute their content as compile time.

  Sam
-- 
Samuel Tardieu -- s...@rfc1149.net -- http://www.rfc1149.net/


--
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] An alternative for foldable?

2008-12-28 Thread Samuel Tardieu
 Slava == Slava Pestov sl...@factorcode.org writes:

Slava why not just define a word : sum-of-primes ( m n -- x )
Slava primes-between sum ; foldable

Sure, but that was just an example. It would be great to be able to
indicate that the list of primes between two numbers can be known at
compile time if the bounds are.

  Sam
-- 
Samuel Tardieu -- s...@rfc1149.net -- http://www.rfc1149.net/


--
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk