[plt-scheme] problem with example macro
Thanks.
I'm familiar with multiple values but didn't pick up
the hint from values-producing-form and missed it
again in the call-with-values. I thought he was just
making his own version of nth as an example. Must read
more carefully.
Michael
--- Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
> michael rice skrev:
> > Noticed this about the first macro given in
> > "Syntax-rules Primer for the Merely Eccentric" in
> the
> > Macro section of schematics:cookbook.
> >
> > Hope it's not something I'm doing wrong.
> >
> > Michael
> >
> >
> > (define-syntax nth-value
> > (syntax-rules ()
> > ((nth-value n values-producing-form)
> > (call-with-values
> > (lambda () values-producing-form)
> > (lambda all-values
> > (list-ref all-values n))))))
> >
> > =================================
> >
> > Welcome to DrScheme, version 360.
> > Language: Swindle.
> >> (nth-value 3 '(a b c d e f))
> > . list-ref: index 3 too large for list: ((a b c d
> e
> > f))
>
>
> Your values-producing-form is '(a b c d e f).
> That produces 1 value. This explains, why the
> error say index 3 is too large.
>
> Try
>
> (nth-value 3 (values 'a 'b 'c 'd 'e 'f))
>
> --
> Jens Axel Søgaard
>
>
____________________________________________________________________________________
Sponsored Link
Mortgage rates near 39yr lows. $510k for $1,698/mo.
Calculate new payment! www.LowerMyBills.com/lre