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.