[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: macro like "my" in Perl

From: Paul Jarc
Subject: Re: macro like "my" in Perl
Date: Fri, 12 Jul 2002 16:43:04 -0400
User-agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2 (i686-pc-linux-gnu)

Thanks for the input.  The scoping of identifiers in top-level defines
is close enough to what I want, so I ended up with this macro to wrap
all top-level forms, rather than trying to modify the scoping of
internal bindings.

(define-macro (top-scope . exprs)
  (let loop ((vars (map (lambda (expr)
                          (and (pair? expr)
                               (member (car expr)
                                       '(define define* define-macro))
                               (let ((x (cdr expr)))
                                 (and (pair? x)
                                      (let ((x (car x)))
                                         ((symbol? x) x)
                                         ((pair? x)
                                          (let ((x (car x)))
                                            (and (symbol? x) x)))
                                         (#t #f)))))))
    (if (null? vars) #t
        (let ((sym (car vars))
              (rest (cdr vars)))
          (if (and sym (member sym rest))
              (scm-error 'misc-error "top-scope" "duplicate bindings: ~S"
                         `(,sym) #f))
          (loop rest))))
  `(begin ,@exprs))

I don't suppose there's any way to find line numbers for the error
message, is there?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]