Skip to content

Instantly share code, notes, and snippets.

@fbanados
Created April 20, 2012 14:58
Show Gist options
  • Save fbanados/2429315 to your computer and use it in GitHub Desktop.
Save fbanados/2429315 to your computer and use it in GitHub Desktop.
Laziness en #lang plazy
#lang plazy
(define (my-if p t f)
(if p t f))
(define (infiniteloop x)
(infiniteloop x))
;al contrario de #lang racket, aquí esta función sí funciona correctamente.
(my-if #f (infiniteloop 0) 123)
(define ones (cons 1 ones))
(take 10 ones)
(define naturales
(cons 0 (map add1 naturales)))
(take 10 naturales)
(take 10 (filter even? naturales))
(define (intsfrom n)
(cons n
(map add1 (intsfrom n))))
(take 10 (intsfrom -11123456))
(define (circular lista)
(append lista (circular lista)))
(take 10 (circular '(1 2 3)))
(define (criba lista)
(let ((n (car lista)))
(cons n
(filter
(λ (x) (not (= 0 (modulo x n))))
(criba (cdr lista))))))
(take 10 (criba (intsfrom 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment