[racket] Constructors for sequences

From: Galler (lzgaller at optonline.net)
Date: Sun Apr 29 15:44:26 EDT 2012

> (sequence-constructor (list 1 2 3))  = list
> (sequence-constructor (vector 1 2 3))  = vector
> etc
> 
> I'd like to use it for a declare-mappable macro that extends functions
> of one argument
> to map over sequences. As in (sin (list 1 2 3)) = (list (sin 1) (sin
> 2) (sin 3)).
> 

I think you are seeking a distributive mapping of two functions f and g

;(f (g . rest)) ->  g (f(arg) .  f(arg2).....)

So (I think) the evaluative order of racket becomes the impediment, and not the
type of the sequence  


try this:

(require mzlib/defmacro)

(define-macro (distribute . (f g . rest))
    `(,g ,@(map (λ (x) `(,f  ,x)) rest)))
     
> (distribute sin list 1 2 3)
(0.8414709848078965 0.9092974268256817 0.1411200080598672)
> (distribute sin vector 1 2 3)
#(0.8414709848078965 0.9092974268256817 0.1411200080598672)
> 






Posted on the users mailing list.