Re: [racket-users] format-id question

2016-05-09 Thread Matthew Butterick
On Monday, May 9, 2016 at 11:10:07 AM UTC-7, Matthew Butterick wrote:
> Or `format-id` could be patched to automatically unwrap any syntax object 
> that contains a single datum, obviating the need for `syntax-e` (which would 
> seem consistent with its handling of things like #'foo)

Actually, that wouldn't be restrictive enough, because not every "single datum" 
can properly be part of an identifier. Moreover, that's probably the reason for 
the restriction against arguments like #'7 in the first place — to preclude 
uses like `(format-id stx "~a" #'numeric-datum)`, which would not produce a 
valid identifier.

-- 
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] format-id question

2016-05-09 Thread Matthew Butterick

On May 9, 2016, at 10:41 AM, Kevin Forchione  wrote:
> 
> That was a surprise. So ids can’t have numerics as part of their arguments in 
> format-id? Is that correct? How would I make this work if I wanted to pass 
> numbers into the format-id to generate ids like foo7, bar3, etc?

The answer is in your error message. `format-id` only works with:

> (or/c string? symbol? identifier? keyword? char? number?)

In your example, you're passing #'7 as an argument, which is none of those 
things (it's not a number, because it's syntax; it's not an identifier, because 
7 is not a symbol)

As Ben mentioned, unwrapping the syntax with `syntax-e` will cure the problem, 
because then it will be a number.

Or `format-id` could be patched to automatically unwrap any syntax object that 
contains a single datum, obviating the need for `syntax-e` (which would seem 
consistent with its handling of things like #'foo)

-- 
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] format-id question

2016-05-09 Thread Benjamin Greenman
On Mon, May 9, 2016 at 1:41 PM, Kevin Forchione  wrote:

> (with-syntax ([name (format-id stx "~a-~a" #'a #'b)])


Change this line to:

(with-syntax ([name (format-id stx "~a-~a" (syntax-e #'a) (syntax-e #'b))])

Using syntax-e explicitly gets the value out of the syntax objects #'a &
#'b.

(I'm not sure why the original worked)

-- 
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] format-id question

2016-05-09 Thread Kevin Forchione
Hi guys, 
I’ve been working with Racket 6.5 refreshing my macro knowledge and ran into a 
situation with format-id that baffles me. There’s an example of format-id on 
the “Fear of Macros” webpage that puzzles me. 

>(require (for-syntax racket/syntax))
>(define-syntax (hyphen-define/ok3 stx)
(syntax-case stx ()
  [(_ a b (args ...) body0 body ...)
   (with-syntax ([name (format-id stx "~a-~a" #'a #'b)])
 #'(define (name args ...)
 body0 body ...))]))
>(hyphen-define/ok3 bar baz () #t)
>(bar-bas)
#t

So far so good… so I tried a few other arguments:

>(hyphen-define/ok3 bar ? () #t)
>(bar-?)
#t

>(hyphen-define/ok3 bar 7 () #t)
>(bar-7)
 ../../Applications/Racket v6.5/collects/racket/private/map.rkt:26:19: 
format-id: contract violation
  expected: (or/c string? symbol? identifier? keyword? char? number?)
  given: #

That was a surprise. So ids can’t have numerics as part of their arguments in 
format-id? Is that correct? How would I make this work if I wanted to pass 
numbers into the format-id to generate ids like foo7, bar3, etc?

Thanks so much for any insight into this!

-Kevin

-- 
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] How to write a #%module-begin that inspects a syntax property post expansion?

2016-05-09 Thread Matthew Flatt
At Sun, 8 May 2016 21:40:04 -0700 (PDT), Jack Firth wrote:
> I'm writing a series of macros that attach metadata using syntax properties 
> during expansion, and I'm attempting to write a #lang whose module-begin form 
> expands the module and then inspects the metadata attached. The problem I'm 
> getting is that local-expand seems to not "expand enough" - it returns a 
> partially expanded syntax object in which the macros that attach the metadata 
> haven't run yet. I'm not sure how to fully expand the syntax object in the 
> context of a module begin form. Do I need to do something with the stop-ids 
> argument to local-expand to do this properly?

Unless you provide a non-empty stop list to `local-expand`, then it
should fully expand. Can you provide an example to demonstrate the
problem?

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