Re: [racket] Syntax certificate question

2011-06-04 Thread Carl Eastlund
Okay, I don't understand what's going on, but I've fixed the program.
First I had to apply the result of (syntax-local-certifier #t)
directly to the reference to identity.  I don't know why this is.  I
also had to expand the body of with-macro in the internal definition
context I created, so that references to lhs don't escape the
expansion of with-macro.  That part makes sense to me.

#lang racket/load

(module A racket
  (provide with-macro)
  (require (for-syntax racket/syntax syntax/parse))
  (define-for-syntax (identity x) x)
  (define-syntax with-macro
(syntax-parser
  [(_ lhs:id rhs:expr e:expr)
   (define ctx (syntax-local-make-definition-context))
   (syntax-local-bind-syntaxes
 (list #'lhs)
 #`(#,((syntax-local-certifier #t) #'identity) rhs)
 ctx)
   (internal-definition-context-seal ctx)
   (local-expand #'e (list (gensym 'with-macro)) null ctx)])))

(module B racket
  (require 'A (for-syntax syntax/parse))
  (with-macro thunk (syntax-parser [(_ e:expr) #'(lambda () e)])
(thunk (printf "Boo!\n"

On Sat, Jun 4, 2011 at 3:13 PM, Carl Eastlund  wrote:
> A question for the syntax certificate connoisseurs out there.  The
> program below produces the following error message:
>
>  compile: access from an uncertified context to unexported variable
> from module: "A" in: identity
>
> Why is the reference to identity from within the module that binds it
> illegal?  Is that syntax object somehow not certified correctly, or
> does syntax-local-bind-syntaxes result in some illegal destructuring
> of its input?  I imagine I can work around this by providing identity
> so that the certificate system ignores it, but I'd like to at least
> understand what's causing this error.
>
> #lang racket/load
>
> (module A racket
>  (provide with-macro)
>  (require (for-syntax racket/syntax syntax/parse))
>  (define-for-syntax (identity x) x)
>  (define-syntax with-macro
>    (syntax-parser
>      [(_ lhs:id rhs:expr e:expr)
>       (define ctx (syntax-local-make-definition-context))
>       (syntax-local-bind-syntaxes (list #'lhs) #'(identity rhs) ctx)
>       (internal-definition-context-seal ctx)
>       (internal-definition-context-apply ctx #'e)])))
>
> (module B racket
>  (require 'A (for-syntax syntax/parse))
>  (with-macro thunk (syntax-parser [(_ e:expr) #'(lambda () e)])
>    (thunk (printf "Boo!\n"
>

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Syntax certificate question

2011-06-04 Thread Carl Eastlund
On Sat, Jun 4, 2011 at 3:17 PM, Jay McCarthy  wrote:
> 2011/6/4 Carl Eastlund :
>> A question for the syntax certificate connoisseurs out there.  The
>> program below produces the following error message:
>>
>>  compile: access from an uncertified context to unexported variable
>> from module: "A" in: identity
>>
>> Why is the reference to identity from within the module that binds it
>> illegal?  Is that syntax object somehow not certified correctly, or
>> does syntax-local-bind-syntaxes result in some illegal destructuring
>> of its input?  I imagine I can work around this by providing identity
>> so that the certificate system ignores it, but I'd like to at least
>> understand what's causing this error.
>>
>> #lang racket/load
>>
>> (module A racket
>>  (provide with-macro)
>>  (require (for-syntax racket/syntax syntax/parse))
>>  (define-for-syntax (identity x) x)
>
> Isn't this a phase 1 binding?

Yup.

>>  (define-syntax with-macro
>>    (syntax-parser
>>      [(_ lhs:id rhs:expr e:expr)
>>       (define ctx (syntax-local-make-definition-context))
>>       (syntax-local-bind-syntaxes (list #'lhs) #'(identity rhs) ctx)
>
> And this a phase -1 (template) use, which normally goes for the phase 0 
> binding

Nope.  The second argument to syntax-local-bind-syntaxes is a
compile-time (phase 1) expression.  It is essentially equivalent to a
syntax definition:

  (define-syntaxes [lhs] (identity rhs))

>>       (internal-definition-context-seal ctx)
>>       (internal-definition-context-apply ctx #'e)])))
>>
>> (module B racket
>>  (require 'A (for-syntax syntax/parse))
>>  (with-macro thunk (syntax-parser [(_ e:expr) #'(lambda () e)])
>
> And this is a phase 0 use?
>
> Is that the problem?

Sadly, no.  This would be easier to work out if it were a phase
problem.  The error message clearly says that identity refers to an
unexported variable from A.  If this were a phase problem, it should
instead say that identity is unbound.

--Carl

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Syntax certificate question

2011-06-04 Thread Jay McCarthy
2011/6/4 Carl Eastlund :
> A question for the syntax certificate connoisseurs out there.  The
> program below produces the following error message:
>
>  compile: access from an uncertified context to unexported variable
> from module: "A" in: identity
>
> Why is the reference to identity from within the module that binds it
> illegal?  Is that syntax object somehow not certified correctly, or
> does syntax-local-bind-syntaxes result in some illegal destructuring
> of its input?  I imagine I can work around this by providing identity
> so that the certificate system ignores it, but I'd like to at least
> understand what's causing this error.
>
> #lang racket/load
>
> (module A racket
>  (provide with-macro)
>  (require (for-syntax racket/syntax syntax/parse))
>  (define-for-syntax (identity x) x)

Isn't this a phase 1 binding?

>  (define-syntax with-macro
>    (syntax-parser
>      [(_ lhs:id rhs:expr e:expr)
>       (define ctx (syntax-local-make-definition-context))
>       (syntax-local-bind-syntaxes (list #'lhs) #'(identity rhs) ctx)

And this a phase -1 (template) use, which normally goes for the phase 0 binding

>       (internal-definition-context-seal ctx)
>       (internal-definition-context-apply ctx #'e)])))
>
> (module B racket
>  (require 'A (for-syntax syntax/parse))
>  (with-macro thunk (syntax-parser [(_ e:expr) #'(lambda () e)])

And this is a phase 0 use?

Is that the problem?

Jay

>    (thunk (printf "Boo!\n"
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>



-- 
Jay McCarthy 
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users