[plt-scheme] On hygiene and trust

From: Abdulaziz Ghuloum (aghuloum at gmail.com)
Date: Thu Jul 9 17:59:28 EDT 2009

On Jul 9, 2009, at 8:24 PM, Joe Marshall wrote:

> Yeah.  it should be more like this:
> (defmacro named-let (name bindings &body body)
>   `(funcall (LABELS ((,name ,(map list #'car bindings) , at body))
>                  (function name)) ,@(map 'list #'cadr bindings)))
>
> But the compiler generates much worse code for this.  The scoping
> issue is a minor issue.


First, "Scope Is Everything"[*].

Second, if your common lisp compiler generates much worse code
for this (and it probably doesn't), then use a better compiler.
E.g.,

Ikarus Scheme version 0.0.4-rc1+ (revision 1828, build 2009-07-09)
Copyright (c) 2006-2009 Abdulaziz Ghuloum

 > (define-syntax named-let
     (syntax-rules ()
       [(_ name ([lhs* rhs*] ...) b b* ...)
        ((letrec ([name (lambda (lhs* ...) b b* ...)]) name)
         rhs* ...)]))

 > (expand/optimize
     '(named-let loop ([n 5] [ac 1])
        (if (zero? n) ac (loop (- n 1) (* n ac)))))
(letrec ((loop_0
           (lambda (n_1 ac_2)
             (if (zero? n_1)
                 ac_2
                 (loop_0 (- n_1 '1) (* n_1 ac_2))))))
   (loop_0 '5 '1))

Aziz,,,

[*] http://video.google.com/videoplay?docid=-3704713569771882785



Posted on the users mailing list.