Next: , Previous: , Up: iklib syntaxes   [Index]


6.8.15 Splice first form syntax

Syntax: splice-first-expand ?form

When the use of a splice-first-expand syntax appears as first subform of an enclosing form, ?form must have the format:

(?rator ?rand ...)

and it is spliced in the enclosing form, then the result is expanded:

((splice-first-expand (?rator ?rand ...) ?arg ...)
→ (?rator ?rand ... ?arg ...)

When the use of a splice-first-expand syntax appears as second or subsequent subform: it expands into ?form itself, which is then expanded:

(splice-first-expand ?form)
→ ?form

This syntax must be used with care.

Usage examples:

(import (vicare))

(splice-first-expand 123)               ⇒ 123
(splice-first-expand (+ 1 2))           ⇒ 3

((splice-first-expand (+)) 1 2)           ⇒ 3
((splice-first-expand (+) 1 2) 3 4)       → (+ 1 2 3 4)

(let-syntax ((doit (syntax-rules ()
                     ((_ ?arg ...)
                      (+ (square ?arg) ...)))))
  ((splice-first-expand (doit 1 2)) 3 4))
→ (+ (square 1) (square 2) (square 3) (square 4))

(let-syntax ((arg1 (identifier-syntax 1))
             (arg2 (identifier-syntax 2))
             (doit (syntax-rules ()
                     ((_ ?arg ...)
                      (+ (square ?arg) ...)))))
  ((splice-first-expand (doit arg1 arg2)) 3 4))
→ (+ (square 1) (square 2) (square 3) (square 4))

(let*-syntax ((arg1 (identifier-syntax 1))
              (arg2 (identifier-syntax 2))
              (doit (syntax-rules ()
                      ((_ ?arg ...)
                       (+ (square ?arg) ...))))
              (flop (syntax-rules ()
                      ((_ ?arg ...)
                       (splice-first-expand
                        (doit arg1 ?arg ...))))))
  ((flop arg2) 3 4))
→ (+ (square 1) (square 2) (square 3) (square 4))

(let*-syntax ((arg1 (identifier-syntax 1))
              (arg2 (identifier-syntax 2))
              (doit (syntax-rules ()
                      ((_ ?arg ...)
                       (+ (square ?arg) ...))))
              (flop (syntax-rules ()
                      ((_ ?arg ...)
                       (splice-first-expand
                        (doit arg1 ?arg ...)))))
              (flip (syntax-rules ()
                      ((_ ?arg ...)
                       (flop ?arg ...)))))
  ((flip arg2) 3 4))
→ (+ (square 1) (square 2) (square 3) (square 4))