retroforth/example/Primes.retro
crc 6e7c73f93b work on 2020.10 is under way, begin updates to remove deprecated words
FossilOrigin-Name: 1a4cb2c13230dafba7a0e14e512fe3f97aeb4b3a7b28cac5db5ec404b2acd5a2
2020-08-09 03:27:42 +00:00

24 lines
455 B
Text

This is a quick and dirty way to find prime numbers in a set.
~~~
{{
#2 'NextPrime var-n
:extract (s-s)
[ @NextPrime dup-pair eq?
[ drop-pair TRUE ]
[ mod n:-zero? ] choose ] a:filter ;
---reveal---
:get-primes (s-s)
#2 !NextPrime
dup fetch [ extract &NextPrime v:inc ] times ;
}}
~~~
And a test:
~~~
:create-set (-a)
here #1000 , #2 #1002 [ dup , n:inc ] times drop ;
create-set get-primes [ n:put sp ] a:for-each
~~~