1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-11 17:20:26 +00:00
janet/examples/primes.janet
Calvin Rose 4e4dd31164 Change syntax for namespaces.
Add quasiquote, unquote, and unquote-splicing
as specials rather than a macro.
2018-11-30 22:49:21 -05:00

15 lines
376 B
Plaintext

# Return an array of primes. This is a trivial and extremely naive algorithm.
(defn primes
"Returns a list of prime numbers less than n."
[n]
(def list @[])
(for i 2 n
(var isprime? true)
(def len (length list))
(for j 0 len
(def trial (get list j))
(if (zero? (% i trial)) (:= isprime? false)))
(if isprime? (array/push list i)))
list)