The SRFI has already been finalized, but today I came up with an "even better" implementation:
(define-syntax extract-placeholders
(syntax-rules (_ is isnt)
((extract-placeholders final (() () body))
(final (infix/postfix . body)))
((extract-placeholders final (() args body))
(lambda args (final (infix/postfix . body))))
((extract-placeholders final (((is . t) . rest) args (body ...)) . *)
(extract-placeholders final (rest args (body ... (is . t))) . *))
((extract-placeholders final (((isnt . t) . rest) args (body ...)) . *)
(extract-placeholders final (rest args (body ... (isnt . t))) . *))
((extract-placeholders final (((h . t) . rest) args body) . *)
(extract-placeholders final ((h . t) () ()) (rest args body) . *))
((extract-placeholders final (() (args ...) body) (rest (args+ ...)
(body+ ...)) . *)
(extract-placeholders final (rest (args+ ... args ...)
(body+ ... body)) . *))
((extract-placeholders final ((_ . rest) (args ...) (body ...)) . *)
(extract-placeholders final (rest (args ... arg) (body ... arg)) . *))
((extract-placeholders final ((arg . rest) args (body ...)) . *)
(extract-placeholders final (rest args (body ... arg)) . *))
))
(define-syntax-rule (is . something)
(extract-placeholders identity-syntax (something () ())))
(define-syntax-rule (isnt . something)
(extract-placeholders not (something () ())))
The definition of infix/postfix remains the same.
The new definition allows to use placeholder in a nested position, as in
(is (length _) < 5)
is equivalent to
(lambda (_) (< (length _) 5))
It also allows to nest the "is" and "isnt" combinators (they are treated specially by the macro itself):
(is (length (filter (is (modulo _ 2) = 0) _)) < 5)
is equivalent to
(lambda (_) (< (length (filter (lambda (_) (= (modulo _ 2) 0)) _)) 5))
It's a shame that the SRFI process is over ;]
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 286 |
Nodes: | 16 (2 / 14) |
Uptime: | 87:04:37 |
Calls: | 6,496 |
Calls today: | 7 |
Files: | 12,099 |
Messages: | 5,277,134 |