Skip to content

Instantly share code, notes, and snippets.

@shanecelis
Forked from deech/is-prime.shen
Last active February 16, 2017 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanecelis/a74732c697e9dcfb56a4d0e2763b7aad to your computer and use it in GitHub Desktop.
Save shanecelis/a74732c697e9dcfb56a4d0e2763b7aad to your computer and use it in GitHub Desktop.
(datatype is-prime
if (is-prime? N)
N : number;
==============
N : prime;)
(define is-prime?
2 -> true
X -> (prime* X (/ X 2) 2) where (number? X)
_ -> false)
(define prime*
X Max Div -> false where (integer? (/ X Div))
X Max Div -> true where (> Div Max)
X Max Div -> (prime* X Max (+ 1 Div)))
\*
Sample REPL interaction:
(12-) (tc +) \* Turn on the type checker. *\
true
(13+) 1 : prime
1 : prime
(14+) 2 : prime
type error
*\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment