mit-scheme-devel
[Top][All Lists]
Advanced

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

Re: [MIT-Scheme-devel] named parameters


From: Taylor R Campbell
Subject: Re: [MIT-Scheme-devel] named parameters
Date: Sun, 12 Jun 2011 16:16:53 +0000
User-agent: IMAIL/1.21; Edwin/3.116; MIT-Scheme/9.1

   Date: Sat, 11 Jun 2011 20:49:26 -0700
   From: "Arthur A. Gleckler" <address@hidden>

   Would you care to expand upon the relationship between this and "less broken
   macros and modules?"  I'm not disagreeing, at least on the modules front,
   but would just like to hear more.

KLAMBDA expands to a call to %%MAKE-KEYWORD-PROCEDURE.  But that's
supposed to be an internal binding, not exposed to the world.  That
doesn't work in MIT Scheme unless you either (a) always work in-image
without saving syntaxed/compiled files to disk, or (b) essentially do
the hygiene yourself and rely on the global package hierarchy, by
generating code of the form (access FOO (->environment '(BAR))).

In Racket, this works.  In a module M, I can write

(define make-promise ...)
(define-syntax delay
  (syntax-rules ()
    ((delay x) (make-promise (lambda () x)))))

and expose only DELAY.  In a module N, I can use M and write

(delay 123)

without seeing MAKE-PROMISE; it's an implementation detail of M.


In Racket, I can lexically modify the semantics of application by
supplying a different binding for the name #%APP.  Trivial examples:

(let-syntax ((#%app (syntax-rules () ((#%app f . x) 0))))
  (cons 1 2))
;Value: 0

(let-syntax
    ((#%app (syntax-rules () ((#%app x ... f) (#%app f x ...)))))
  (1 2 cons))
;Value: (1 . 2)

(Note that the expansion of #%APP in the latter example refers to the
binding of #%APP in the enclosing environment; there is no recursion
here because I used LET-SYNTAX rather than LETREC-SYNTAX.)

These examples use LET-SYNTAX to lexically scope the binding of #%APP
but Racket's module system lets me do the same for an entire module --
and the same with LAMBDA.  So I can replace LAMBDA by KLAMBDA and
#%APP by K (K being written in terms of the base Scheme #%APP) locally
for a whole module, which is necessary in order for the whole named
parameter business to be palatable and nonintrusive as an experiment.



reply via email to

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