guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SICP stream question


From: Marius Vollmer
Subject: Re: SICP stream question
Date: 27 Apr 2001 13:13:23 +0200
User-agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7

Chris Baker <address@hidden> writes:

> I'm trying to implement streams (delayed lists) from SICP.  Here's
> what I have so far:
> 
>       ;;; stream definitions
>       (define cons-stream
>         (procedure->macro
>          (lambda (x env) `(cons ,(cadr x) (delay ,(caddr x))))))

Please use

    (define-macro (cons-stream a b)
      `(cons ,a (delay ,b)))

or

    (defmacro cons-stream (a b)
      `(cons ,a (delay ,b)))

instead.  `procedure->macro' is some obscure low-level thing used to
implement macros, but it is not meant to be used in ordinary programs.
What you are seeing is that the internal, `compiled' form of your
program leaks back to the surface, but that form is no longer made up
of lists, so `caddr' breaks.  Really obscure stuff, simply don't use
`procedure->macro'.

`defmacro' and `define-macro' are equivalent, modulo syntax.

You will also need to increase the stack depth of Guile before you can
evaluate (stream-ref primes 200):

    (debug-set! stack 100000)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]