Re: [racket-users] Simple define-require-syntax question

2017-06-24 Thread Matthias Felleisen

> On Jun 18, 2017, at 8:09 AM, Matthew Flatt  wrote:
> 
> At Sun, 18 Jun 2017 06:47:24 -0400, Tony Garnock-Jones wrote:
>> First, it seems like since the whole point of require is to pollute the
>> surrounding namespace, an "unhygienic" require would be better.
> 
> Generally, I don't see the difference between `require` and `define` in
> terms of the intent to bind identifiers. Many parts of Racket rely on
> `require` binding being hygienic in the same way as definitions.
> 
> But...
> 
>> My past experiences of this kind of problem have all been related to
>> #lang and module and require-level binding, come to think of it. It
>> seems a murky area. Perhaps other kinds of hygiene-preserving techniques
>> than those that work well for expressions are needed for these areas?
> 
> ... I agree that hygiene is not always a convenient default for module
> languages, which frequently want to introduce non-hygienic bindings. I
> don't know how to make this better, but it's something to think about.


Perhaps the default setting needs a switch so it can be flipped for
some contexts. The module language seems to be the first serious 
feature that could benefit from such a thing but I could imagine 
that classes (or extensions of class.rkt) may benefit from it too. 

— Matthias

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Simple define-require-syntax question

2017-06-18 Thread Matthew Flatt
At Sun, 18 Jun 2017 06:47:24 -0400, Tony Garnock-Jones wrote:
> First, it seems like since the whole point of require is to pollute the
> surrounding namespace, an "unhygienic" require would be better.

Generally, I don't see the difference between `require` and `define` in
terms of the intent to bind identifiers. Many parts of Racket rely on
`require` binding being hygienic in the same way as definitions.

But...

> My past experiences of this kind of problem have all been related to
> #lang and module and require-level binding, come to think of it. It
> seems a murky area. Perhaps other kinds of hygiene-preserving techniques
> than those that work well for expressions are needed for these areas?

... I agree that hygiene is not always a convenient default for module
languages, which frequently want to introduce non-hygienic bindings. I
don't know how to make this better, but it's something to think about.

Also, the way that `require` forms synthesize binding names is
non-hygienic in a sense or at some level, which is probably what you're
getting at initially.


> And second, I'm used to macros hinging on the binding of the identifier
> in their car, namely `submod` here.

That would be worse, because `submod` itself is bound (as a `require`
form), and you might want to introduce a binding using `submod` in a
context that doesn't have a binding for `submod` itself.

Most binding-synthesizing macros in Racket work that way (or should)
--- using the context of the parentheses for introducing bindings,
instead of the context of the identifier. Non-hygienic macros don't
compose well, but that distinction makes them usefully more composable.

In the case of `submod`, the context of the submodule name would work
just as well as the context of the parentheses, and would have been
more convenient for your use, but it's less convenient in some other
uses.

> PS. Why do *parentheses* have a binding context, anyway??

Mostly for `#%app`, but it's also a handy as a general convention for
distinguishing binding context from use context.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Simple define-require-syntax question

2017-06-18 Thread Tony Garnock-Jones
On 06/17/2017 08:02 PM, Matthew Flatt wrote:
> As a `require` form, a `submod`'s binding context is taken from the
> parenthesis around the `submod`. With options (A) and (B), the context
> of those parentheses is macro-introduced.

Thanks!

So this `submod` binding context is being used to mark the
ultimately-introduced identifiers, right? So, in the example, v1 would
be marked with the (macro-introduced) context of the `submod` form. And
it is this marking that prevents the use of v1 in `main` from lining up
with the definition of v1.

This seems weird to me for two reasons.

First, it seems like since the whole point of require is to pollute the
surrounding namespace, an "unhygienic" require would be better. (I don't
know how this would work!)

And second, I'm used to macros hinging on the binding of the identifier
in their car, namely `submod` here. (Using #'submod instead of 'submod
in option (C) works fine too, incidentally.) This point is definitely
minor compared to the first one.

Either way, I was confused that the obvious thing didn't work, and maybe
other authors of define-require-syntax transformers start out confused
too. It took me quite a while, and past scars from mysterious binding
problems, to think of option (C).

My past experiences of this kind of problem have all been related to
#lang and module and require-level binding, come to think of it. It
seems a murky area. Perhaps other kinds of hygiene-preserving techniques
than those that work well for expressions are needed for these areas?

Cheers,
  Tony

PS. Why do *parentheses* have a binding context, anyway??

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Simple define-require-syntax question

2017-06-17 Thread Matthew Flatt
As a `require` form, a `submod`'s binding context is taken from the
parenthesis around the `submod`. With options (A) and (B), the context
of those parentheses is macro-introduced.

At Sat, 17 Jun 2017 16:49:50 -0400, Tony Garnock-Jones wrote:
> #lang racket
> ;;
> ;; Hi all (Matthew in particular I imagine :-) ),
> ;;
> ;; Why does option (C) work, but options (A) and (B) do not?
> ;;
> ;; They fail with:
> ;;
> ;; t.rkt:31:2: v1: unbound identifier in module
> ;;   in: v1
> ;;   context...:
> ;;standard-module-name-resolver
> ;;
> ;; -- Tony
> 
> (require racket/require-syntax)
> 
> ;;--(A)--
> ;; (define-require-syntax m+
> ;;   (syntax-rules ()
> ;; [(_ xs ...)
> ;;  (submod ".." xs ...)]))
> 
> ;;--(B)--
> ;; (define-require-syntax (m+ stx)
> ;;   (syntax-case stx ()
> ;; [(_ xs ...)
> ;;  #'(submod ".." xs ...)]))
> 
> ;;--(C)--
> (define-require-syntax (m+ stx)
>   (syntax-case stx ()
> [(_ xs ...)
>  (datum->syntax stx (list* 'submod ".." #'(xs ...)))]))
> 
> 
> (module+ m1
>   (provide v1)
>   (define v1 123))
> 
> (module+ main
>   (require (m+ m1))
>   v1)
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Simple define-require-syntax question

2017-06-17 Thread Tony Garnock-Jones
#lang racket
;;
;; Hi all (Matthew in particular I imagine :-) ),
;;
;; Why does option (C) work, but options (A) and (B) do not?
;;
;; They fail with:
;;
;; t.rkt:31:2: v1: unbound identifier in module
;;   in: v1
;;   context...:
;;standard-module-name-resolver
;;
;; -- Tony

(require racket/require-syntax)

;;--(A)--
;; (define-require-syntax m+
;;   (syntax-rules ()
;; [(_ xs ...)
;;  (submod ".." xs ...)]))

;;--(B)--
;; (define-require-syntax (m+ stx)
;;   (syntax-case stx ()
;; [(_ xs ...)
;;  #'(submod ".." xs ...)]))

;;--(C)--
(define-require-syntax (m+ stx)
  (syntax-case stx ()
[(_ xs ...)
 (datum->syntax stx (list* 'submod ".." #'(xs ...)))]))


(module+ m1
  (provide v1)
  (define v1 123))

(module+ main
  (require (m+ m1))
  v1)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.