In Racket, if a non-dimensioned pair is constructed with dot notation, is it possible to use a variable or an expression value for the second element?

advertisements

In Racket, the following works:

(+ . [1 2]) ; => 3

{ define a + }
(a . [1 2]) ; => 3

However, i see no way to define b to be the (1 2) list so as to get (+ . b) and (a . b) to return 3. Is it possible?


Sure, just use apply:

(define a +)
(define b '(1 2))
(apply a b)       ; => 3
(apply + b)       ; => 3