Skip to content

Instantly share code, notes, and snippets.

@egisatoshi
Created July 9, 2014 09:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egisatoshi/0cd4bd96b9a2bde0fa3f to your computer and use it in GitHub Desktop.
Save egisatoshi/0cd4bd96b9a2bde0fa3f to your computer and use it in GitHub Desktop.
続編 - RubyにHaskellよりも強力なパターンマッチを実装した ref: http://qiita.com/egisatoshi/items/dfa13e45edbc71430048
require 'egison'
require 'prime'
include Egison
twin_primes = match_stream(Prime) {
with(List.(*_, _x, __("x + 2"), *_)) {
[x, x + 2]
}
}
# print the first 10 prime twins
p twin_primes.take(10)
#=>[[3, 5], [5, 7], [11, 13], [17, 19], [29, 31], [41, 43], [59, 61], [71, 73], [101, 103], [107, 109]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment