[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Scheme-reports] Legacy caar to cddddr
On Fri, 21 Oct 2011, Aubrey Jaffer wrote:
> | I've used those procedures myself, and *every* single time it has
> | been a mistake. I'd rather they go away so I'm not tempted, and am
> | forced to properly abstract from the start.
>
> C*R procedures are very useful in symbolic algebra, for graphs and
> trees, and for manipulating programs (such as compiling). Claims of
> their demise are premature.
I agree. I have found them useful for manipulating programs. Once you are
used to them, you can see at a glance what they are doing (just like with CAR
and CDR).
Here is an example of their use in a renaming-style macro (as WG2 promises us
we will have). Used here are CAR, CDR, CADR, CDDR, CADDR, and CDDDR. All
these are used in a completely obvious and transparent way. This is not a
"code smell".
(define-syntax do
(er-transformer
(lambda (exp r c)
(or (and (pair? (cdr exp))
(pair? (cddr exp)))
(syntax-error))
(let ((specs (cadr exp))
(end (caddr exp))
(body (cdddr exp))
(loop (syntax loop)))
(or (and (list? specs)
(every? do-spec? specs)
(list? end))
(syntax-error))
(quasiquote
(,(r 'letrec) ((,loop
(,(r lambda) ,(map car specs)
(,(r 'cond) ,end
(,(r 'else) ,@body
(,loop
,@(map (lambda (spec)
(if (null? (cddr spec))
(car spec)
(caddr spec)))
specs)))))))
(,loop ,@(map cadr specs))))))))
_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports