[plt-scheme] Is there an idiom for throwing away some values?

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Tue Jul 28 00:27:23 EDT 2009

This is probably the shortest thing:

(define-syntax-rule (first-of-two-values e) (let-values ([(x y) e]) x))

but I would probably just write out the let-values, myself.

Robby

On Mon, Jul 27, 2009 at 11:09 PM, Eric Hanchrow<eric.hanchrow at gmail.com> wrote:
> Here's some code that approximates e^x:
>
> (define (series x)
>  (call-with-values
>      (lambda ()
>        (for/fold ([sum 0]
>                   [factor 1])
>            ([n (in-range 20)])
>            (values
>             (+ sum factor)
>             (* factor (/ x (add1 n))))))
>    (lambda (sum ignore-me)
>      sum)))
>
> I'd like to be able to instead do something like
>
> (define (series x)
>  (just-the-first-value
>   (for/fold ([sum 0]
>              [factor 1])
>       ([n (in-range 20)])
>       (values
>        (+ sum factor)
>        (* factor (/ x (add1 n)))))))
>
> ... without having to actually write "just-the-first-value" myself :)
>
> Is there an idiom that makes this simpler than what I was doing above?
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.