Re: [racket-users] Confused about syntax properties

2017-02-03 Thread Sam Tobin-Hochstadt
On Fri, Feb 3, 2017 at 10:38 AM, Dupéron Georges
 wrote:
> * I'm not 100% sure if #%stratified-body, #%plain-module-begin and 
> #%printing-module-begin can be overridden in a useful way or not.

`#%stratified-body` is a way to get an older kind of internal
definition context, useful for implementing forms that are more
restrictive than Racket's usual internal definitions. It can't be
overridden in those contexts, typically.

`#%plain-module-begin` is a renaming of `#%module-begin` from
`'#%kernel`, similar to `#%plain-app`.

`#%printing-module-begin` is just like the module-begin form used by
`#lang racket`, but without adding any submodules.

Other uses of the "#%" prefix: Typed Racket names the submodule with
contract definitions `#%contract-defs`.

Sam

-- 
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] Confused about syntax properties

2017-02-03 Thread Laurent
Thanks, that's very informative!

On Fri, Feb 3, 2017 at 10:38 AM, Dupéron Georges <
jahvascriptman...@gmail.com> wrote:

> Le vendredi 3 février 2017 11:28:47 UTC+1, Laurent Orseau a écrit :
> > I see. So basically all #% things are extension points?
> > The list for the racket language:
> >
> > http://docs.racket-lang.org/search/index.html?q=%23%25%20L%3Aracket
>
> I think #% just means "low-level".
> * #%declare,  #%expression, #%require, #%provide and #%variable-reference
> are built-in forms with special meanings, and it does not really make sense
> to override them.
> * #lang racket/base overrides #%app, and re-provides the original as
> #%plain-app, so it is just an alias for the #%app from the '#%kernel. The
> same goes for #%plain-lambda.
> * #%app, #%datum, #%module-begin, #%top and #%top-interaction are
> extension points (for function calls, self-quoting data, handling the body
> of the entire module, unbound variables and REPL interactions, respectively)
> * I'm not 100% sure if #%stratified-body, #%plain-module-begin and
> #%printing-module-begin can be overridden in a useful way or not.
>
> --
> 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.


Re: [racket-users] Confused about syntax properties

2017-02-03 Thread Dupéron Georges
Le vendredi 3 février 2017 11:28:47 UTC+1, Laurent Orseau a écrit :
> I see. So basically all #% things are extension points?
> The list for the racket language:
> 
> http://docs.racket-lang.org/search/index.html?q=%23%25%20L%3Aracket 

I think #% just means "low-level".
* #%declare,  #%expression, #%require, #%provide and #%variable-reference are 
built-in forms with special meanings, and it does not really make sense to 
override them.
* #lang racket/base overrides #%app, and re-provides the original as 
#%plain-app, so it is just an alias for the #%app from the '#%kernel. The same 
goes for #%plain-lambda.
* #%app, #%datum, #%module-begin, #%top and #%top-interaction are extension 
points (for function calls, self-quoting data, handling the body of the entire 
module, unbound variables and REPL interactions, respectively)
* I'm not 100% sure if #%stratified-body, #%plain-module-begin and 
#%printing-module-begin can be overridden in a useful way or not.

-- 
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] Confused about syntax properties

2017-02-03 Thread Laurent
I see. So basically all #% things are extension points?
The list for the racket language:
http://docs.racket-lang.org/search/index.html?q=%23%25%20L%3Aracket

On Fri, Feb 3, 2017 at 10:04 AM, Dupéron Georges <
jahvascriptman...@gmail.com> wrote:

> Le vendredi 3 février 2017 10:56:10 UTC+1, Laurent Orseau a écrit :
> > Btw, with "Macro Hiding: Disabled" we can see that after foo is turned
> into #'1 (printed '1' in the macro stepper), then the 1 is 'tagged' with
> (#%datum . 1) and then right after that turned into (quote 1). Is the
> tagging step necessary for numbers?
>
> Yes, self-quoting values like numbers, vectors, booleans, strings etc. are
> wrapped with (#%datum).
>
> This is an extension point which allows languages to decide what to do
> with such values. For example, a language could disallow the use of some
> kinds of data, by making #%datum throw an error. This could also be used to
> treat the contents of vectors as expressions, so that (let ([x 1]) #(x x
> x)) produces #(1 1 1).
>
> Similar extension points are #%top, which is wrapped around unbound
> variables, and #%app, which is prepended to all function calls.
>
> --
> 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.


Re: [racket-users] Confused about syntax properties

2017-02-03 Thread Dupéron Georges
Le vendredi 3 février 2017 10:56:10 UTC+1, Laurent Orseau a écrit :
> Btw, with "Macro Hiding: Disabled" we can see that after foo is turned into 
> #'1 (printed '1' in the macro stepper), then the 1 is 'tagged' with (#%datum 
> . 1) and then right after that turned into (quote 1). Is the tagging step 
> necessary for numbers?

Yes, self-quoting values like numbers, vectors, booleans, strings etc. are 
wrapped with (#%datum).

This is an extension point which allows languages to decide what to do with 
such values. For example, a language could disallow the use of some kinds of 
data, by making #%datum throw an error. This could also be used to treat the 
contents of vectors as expressions, so that (let ([x 1]) #(x x x)) produces #(1 
1 1).

Similar extension points are #%top, which is wrapped around unbound variables, 
and #%app, which is prepended to all function calls.

-- 
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] Confused about syntax properties

2017-02-03 Thread Laurent
Very nice example, thanks Georges.

Btw, with "Macro Hiding: Disabled" we can see that after foo is turned into
#'1 (printed '1' in the macro stepper), then the 1 is 'tagged' with
(#%datum . 1) and then right after that turned into (quote 1). Is the
tagging step necessary for numbers?


On Fri, Feb 3, 2017 at 5:26 AM, Dupéron Georges  wrote:

> PS: a nice example to try in the macro stepper, to see the evaluation
> order:
>
> #lang racket
> (define-syntax (foo stx) #'1)
> (define-syntax (bar stx) #'foo)
>
> (let ()
>   bar
>   (let ()
> bar
> (let ()
>   bar
>   bar)
> (#%expression bar)
> bar)
>   (+ bar bar)
>   bar)
>
> --
> 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.


Re: [racket-users] Confused about syntax properties

2017-02-02 Thread Dupéron Georges
PS: a nice example to try in the macro stepper, to see the evaluation order:

#lang racket
(define-syntax (foo stx) #'1)
(define-syntax (bar stx) #'foo)

(let ()
  bar
  (let ()
bar
(let ()
  bar
  bar)
(#%expression bar)
bar)
  (+ bar bar)
  bar)

-- 
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] Confused about syntax properties

2017-02-02 Thread Dupéron Georges
Le lundi 30 janvier 2017 06:25:29 UTC+1, Matias Eyzaguirre a écrit :
> Nice, thanks! I wasn’t aware of that. so macros are expanded in the order 
> that the reader reads them, not in so called evaluation order.

>From experience, the order is outside-in, each form after the preceding one 
>(except when a macro produces a begin form, in which case the contents of the 
>begin are spliced, and handled one by one). The contents of let-values forms 
>are initially skipped, and expanded after every form in the outer let has been 
>expanded enough to determine that it is not a definition. This means that 
>within the body of a let (or of a module, I think), forms are expanded until 
>the first element is not a macro anymore (e.g. a function application with 
>#%app, an expression with #%expression, or a datum), as any remaining macro 
>could potentially expand to a definition.

Add to that a few exceptions, like things lifted with 
syntax-local-lift-expression or syntax-local-lift-module-end-declaration, and 
explicit expansion with local-expand.

I wonder if there's a definitive reference in the docs about this? I'd enjoy 
reading about how the built-in forms behave, and what mechanisms may influence 
the order of expansion (#%expression, local-expand, maybe some others?).

-- 
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] Confused about syntax properties

2017-01-29 Thread Matias Eyzaguirre

> On 29 Jan 2017, at 11:21, Ben Greenman  wrote:
> 
> The third result is #f because in the third example, stx is `(annotate 
> (annotate 4 2))`. So the first pattern matches and `val` is the syntax 
> `(annotate 4 2)`.
> 
> You can get a "strict" evaluation order by using `local-expand` inside the 
> `annotate` macro. For example:
> 
> #lang racket
> 
> (define-syntax (annotate stx)
>   (syntax-case stx ()
>[(_ val) ; read
>(or (syntax-property (local-expand #'val 'expression #f) 'annotation) 
> #'#f)]
>[(_ val ann) ; write
>(syntax-property #'val 'annotation #'ann #t)]))
> 
> (annotate 4) ;; ==> #f
> (annotate 1 6) ;; ==> 1
> (annotate (annotate 4 2)) ;; ==> 2

Nice, thanks! I wasn’t aware of that. so macros are expanded in the order that 
the reader reads them, not in so called evaluation order.

-- 
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] Confused about syntax properties

2017-01-29 Thread 'William J. Bowman' via Racket Users
On Sun, Jan 29, 2017 at 10:06:30AM -0800, Matias Eyzaguirre wrote:
> Hullo all,
> 
> I'm messing around with syntax properties to try to get a feel for them, but 
> in one of my tests they aren't behaving the way I would expect them to.
> 
> In my example the output is #f 1 #f, when I would have thought it would be #f 
> 1 2. Why is the third result #f and not 2?
> 
> 
> #lang racket
> 
> (define-syntax (annotate stx)
>   (syntax-case stx ()
> [(_ val) ; read
>  (or (syntax-property #'val 'annotation) #'#f)]
> [(_ val ann) ; write
>  (syntax-property #'val 'annotation #'ann #t)]))
> 
> (annotate 4) ; -> #f
> 
> (annotate 1 6) ; -> 1
> 
> (annotate (annotate 4 2)) ; -> 2
Because annotation is a macro, it receives the syntax of the input, not the 
value of the input.
The outer call to annotate receives the value #'(annotate 4 2), which has no 
syntax property, and
hence returns #f.

Your code is roughly like writing:
(syntax-property #'4 'annotation) ; -> #f

(syntax-property #'1 'annotation 6 #t) ; -> #'1

(syntax-property #'(syntax-property #'4 'annotation 2 #t)) ; -> #f

Try this instead:

(define annotated (syntax-property #'4 'annotation 2))
(syntax-property annotated 'annotation)

--
William J. Bowman

-- 
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.


signature.asc
Description: PGP signature


Re: [racket-users] Confused about syntax properties

2017-01-29 Thread Ben Greenman
The third result is #f because in the third example, stx is `(annotate
(annotate 4 2))`. So the first pattern matches and `val` is the syntax
`(annotate 4 2)`.

You can get a "strict" evaluation order by using `local-expand` inside the
`annotate` macro. For example:

#lang racket

(define-syntax (annotate stx)
  (syntax-case stx ()
   [(_ val) ; read
   (or (syntax-property (local-expand #'val 'expression #f) 'annotation)
#'#f)]
   [(_ val ann) ; write
   (syntax-property #'val 'annotation #'ann #t)]))

(annotate 4) ;; ==> #f
(annotate 1 6) ;; ==> 1
(annotate (annotate 4 2)) ;; ==> 2


On Sun, Jan 29, 2017 at 1:06 PM, Matias Eyzaguirre 
wrote:

> Hullo all,
>
> I'm messing around with syntax properties to try to get a feel for them,
> but in one of my tests they aren't behaving the way I would expect them to.
>
> In my example the output is #f 1 #f, when I would have thought it would be
> #f 1 2. Why is the third result #f and not 2?
>
>
> #lang racket
>
> (define-syntax (annotate stx)
>   (syntax-case stx ()
> [(_ val) ; read
>  (or (syntax-property #'val 'annotation) #'#f)]
> [(_ val ann) ; write
>  (syntax-property #'val 'annotation #'ann #t)]))
>
> (annotate 4) ; -> #f
>
> (annotate 1 6) ; -> 1
>
> (annotate (annotate 4 2)) ; -> 2
>
> --
> 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] Confused about syntax properties

2017-01-29 Thread Matias Eyzaguirre
Hullo all,

I'm messing around with syntax properties to try to get a feel for them, but in 
one of my tests they aren't behaving the way I would expect them to.

In my example the output is #f 1 #f, when I would have thought it would be #f 1 
2. Why is the third result #f and not 2?


#lang racket

(define-syntax (annotate stx)
  (syntax-case stx ()
[(_ val) ; read
 (or (syntax-property #'val 'annotation) #'#f)]
[(_ val ann) ; write
 (syntax-property #'val 'annotation #'ann #t)]))

(annotate 4) ; -> #f

(annotate 1 6) ; -> 1

(annotate (annotate 4 2)) ; -> 2

-- 
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.