Re: [racket] how to use 'lazy' from racket/promise

2013-04-10 Thread Stephen Chang
Here's a program that prints the first 10 Fibonacci numbers: #lang racket (define (lazy-map f . lsts) (define flsts (map force lsts)) (if (ormap null? flsts) null (cons (apply f (map car flsts)) (lazy (apply lazy-map f (map cdr flsts)) (define fib (cons 1 (cons 1

Re: [racket] how to use 'lazy' from racket/promise

2013-04-10 Thread Eli Barzilay
10 hours ago, Ryan Culpepper wrote: See SRFI-45 (http://srfi.schemers.org/srfi-45/srfi-45.html) for a discussion of why lazy is necessary (ie, why force and delay are not sufficient in practice). Racket's lazy might (?) be slightly different from the one discussed there, though. See this

[racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Lewis Brown
I'm trying to understand how to use (lazy body ...+) to generate an infinite list. Would somebody please provide an example or two using it, say for ones and fibs. Thanks very much. lb Racket Users list: http://lists.racket-lang.org/users

Re: [racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Danny Yoo
Are you sure you're not looking for the racket/stream library instead? For example: #lang racket (require racket/stream) (define ones (stream-cons 1 ones)) Racket Users list: http://lists.racket-lang.org/users

Re: [racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Lewis Brown
Thanks, Danny. I am trying to understand how to use promises, in particular for lazy programming. I know there are various implementations that solve this more simply: racket/stream and racket/lazy; but I'd like to see how it's done with the more primitive racket/promise library. It appears

Re: [racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Neil Toronto
The following program creates four infinite lists and tries to take the first of each. Only the last expression raises an error. #lang racket (require racket/promise) (define ones (lazy (cons 1 ones))) (define ones* (delay (cons 1 ones*))) (car (force ones)) (car (force ones*)) (define twos

Re: [racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Ryan Culpepper
See SRFI-45 (http://srfi.schemers.org/srfi-45/srfi-45.html) for a discussion of why lazy is necessary (ie, why force and delay are not sufficient in practice). Racket's lazy might (?) be slightly different from the one discussed there, though. See this post by Eli for why:

Re: [racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Stephen Chang
Here's a program that prints the first 10 Fibonacci numbers: #lang racket (define (lazy-map f . lsts) (define flsts (map force lsts)) (if (ormap null? flsts) null (cons (apply f (map car flsts)) (lazy (apply lazy-map f (map cdr flsts)) (define fib (cons 1 (cons 1