Created
July 8, 2012 02:56
-
-
Save fumieval/3069110 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- $は右結合、$$は左結合 | |
| main = proc -- proc [args]…argsを引数に取るブロックを表す | |
| oddprimes <- [] -- ミュータブルな変数への代入 | |
| for [3,5..] proc n | |
| it := forelse(takeWhile ((<n) . (**2)) oddprimes) -- :=は式に別名をつける | |
| $$ proc m (if n % m == 0 then break it) | |
| $$ proc (oddprimes <- append oddprimes n) | |
| for (2 : oddprimes) proc n | |
| print n -- 遅延評価のため、oddprimesに値が追加されるとすぐに出力する | |
| return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment