This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: conditional bindings


On Dec 10, 2014, at 11:38 PM, Per Bothner <per@bothner.com> wrote:

> Looks correct to me ... If you redefine ? then it is just a regular identifier.
> I.e.
>  (let ((? 0+0i)) (if (? r ::real ?) r +nan.0))
> is the same as:
>  (let ((x 0+0i)) (if (x r ::real x) r +nan.0))
> 
> Remember - Scheme has no reserved identifiers.

Yeah I guess so, it just seems so.. unhygienic? dynamic?, for a macro to
work or not work depending upon the lexical scope of the call site.  It's
not like it was invoking the top-level-bound "?" anyway -- like you said,
(? NAME::TYPE VALUE) isn't an expression.

Plus, function keywords are immune to these shenanigans, so it seems like
macro literals should be, too.

(define (f #!key (x 0) (y 0)) (cons x y))
(let ((y: 7) (x: 1)) (f y: 2 x: 3))
=> (3 . 2)

But since that's not the case, I wonder if a macro literal renamer -- akin
to how (import (rename ...)) works for libraries -- could be useful.

It's already possible to wrap a macro to effectively remap its keywords:

(let-syntax ((if (lambda (x) (syntax-case x (q ::)
                               ((_ (q pattern :: type init) then else)
                                #'(if (? pattern :: type init) then else))))))
  (let ((? 3))
    (if (q r :: real ?) r 0)))

=> 3

but that's awfully verbose.

Maybe something like:

(syntax-rename macro (identifier1 identifier2) ...)

as in

(let-syntax ((if (syntax-rename if (? q))))
  (if (q r ::real ?) r +nan.0))

or

(define-syntax lisplike-cond (syntax-rename cond (else t)))

Do the original syntax-rules/syntax-case literal list and patterns
survive to runtime to facilitate the kind of introspection such a
thing would need?

--
Jamison Hope
The PTR Group
www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]