packages feed

egison-3.3.9: sample/sequence.egi

;;;
;;;
;;; Pattern-matching against sequence of natural numbers
;;;
;;;

;; Extract all twin primes from the infinite list of prime numbers with pattern-matching!
(define $twin-primes
  (match-all primes (list integer)
    [<join _ <cons $p <cons ,(+ p 2) _>>>
     [p (+ p 2)]]))

;; Enumerate first 10 twin primes
(test (take 10 twin-primes))

;; Extract all prime-triplets from the infinite list of prime numbers with pattern-matching!
(define $prime-triplets
  (match-all primes (list integer)
    [<join _ <cons $n <cons (& $m (| ,(+ n 2) ,(+ n 4))) <cons ,(+ n 6) _>>>>
     [n m (+ n 6)]]))

;; Enumerate first 10 twin primes
(test (take 10 prime-triplets))