[Top][All Lists]

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

Re: Placement of defines

From: Kjetil S. Matheussen
Subject: Re: Placement of defines
Date: Fri, 19 Dec 2008 18:10:33 +0100 (CET)

Sebastian Tennant:

Quoth "Kjetil S. Matheussen" <address@hidden>:
Yes, this limitation in Scheme is a horrible pest. There's no
decent reason why you shouldn't be allowed to use define other
places than right after a lambda, except the long discussion
involved how it should behave in various situations. But even
inconsistant behaviour between implementations would be better
than the current situation where you either have to rewrite
perfectly fine expressions or use various types of lets or
lambdas in more or less ridiculous ways:

- ((lambda (x) (set! x "baz\n") (define bar x) (display bar)) "foo\n")
+ ((lambda (x) (set! x "baz\n") (let () (define bar x) (display bar) "foo\n"))

Your 'let' workaround gave me an idea.

I use this macro to bind lots of variables dynamically within my
scripts by wrapping calls to it in a map procedure:

(define-macro (definer var val)                  ;var must be a symbol
  `(module-define! (current-module) ,var ,val))

and it happens to work fine as a workaround for the restriction on
define placements in lambdas and lets :)

guile> ((lambda (x) (set! x "baz\n") (definer 'bar x) (display bar)) "foo\n")

Unfortunately, it's not the same. "definer" defines a global variable:

guile> bar

reply via email to

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