[plt-scheme] Re: trying not to use eval - in a define-syntax

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Wed Oct 30 08:49:04 EST 2002

--- John Clements <clements at brinckerhoff.org> wrote:
> As for the index argument, you can add this in a
> similar way, just by 
> writing a function.  I'm calling it indexed-map
> rather than 
> indexed-for-each because (unlike a for-each) it
> returns the list of 
> results:
> (define indexed-for-each
>    (lambda args
>      (when (< (length args) 2)
>        (error 'indexed-for-each "indexed for-each
> requires at least two 
> arguments. Given: ~v" (length args)))
>      (apply map (append args (list (build-list
> (length (cadr 
> args))(lambda (x) x)))))))

You can also do it using fold:

  (define (indexed-map fn list)
       (foldr (lambda (elt seed)
                (match seed
                  [#(rest index)
                   (vector (cons (fn elt index) rest)
(add1 index))]))




Do you Yahoo!?
HotJobs - Search new jobs daily now

Posted on the users mailing list.