ntax-local-value ... how is the struct name
> overloaded? (Carl Eastlund)
>2. Re: Structs and syntax-local-value ... how is the struct name
> overloaded? (Greg Hendershott)
>
>
> ------
>
>
t;> (define-syntax my-fn 'something) then it works with
>>>> >>>>> syntax-local-value but
>>>> >>>>> any attempts to use it as a transformer result in illegal syntax.
>>>> >>>>>
>>>> >>>>
users digest..."
>>>>
>>>>
>>>> [Racket Users list:
>>>> http://lists.racket-lang.org/users ]
>>>>
>>>>
>>>> Today's Topics:
>>>>
>>>>1. Re: Structs and syntax-local-value ...
how is the struct name
>>> overloaded? (Carl Eastlund)
>>>2. Re: Structs and syntax-local-value ... how is the struct name
>>> overloaded? (Greg Hendershott)
>>>
>>>
>>> --
. Re: Structs and syntax-local-value ... how is the struct name
>> overloaded? (Greg Hendershott)
>>
>>
>> ------------------
>>
>> Message: 1
>> Date: Mon, 20 Jan 2014 13:00:35 -0500
>> From: Ca
On Mon, Jan 20, 2014 at 6:31 PM, Scott Klarenbach wrote:
>> If/when it does matter, instead you could use a hashtable on the side,
>> mapping from the procedure to the info. Of course that way, you need
>> to use `(lookup thing)` to get the info.
>
>
> Not to mention that it's vastly simpler to do
>
> Message: 1
> Date: Mon, 20 Jan 2014 13:00:35 -0500
> From: Carl Eastlund
> To: "Alexander D. Knauth"
> Cc: Scott Klarenbach , Racket mailing list
>
> Subject: Re: [racket] Structs and
>> and prop:procedure is how you make a procedure that can also be something
>> else.
One thing to keep in mind is that there is _some_ overhead. In my
recent experience, applying via prop:procedure took roughly 1.6X the
time as applying a plain procedure. (This with the variant of
prop:procedure
Yes, that's exactly it.
Carl Eastlund
On Mon, Jan 20, 2014 at 10:13 AM, Alexander D. Knauth
wrote:
> I'm just curious, is this what you mean?
>
> #lang racket
>
> (require rackunit
> (for-syntax
> syntax/parse))
>
> (begin-for-syntax
> (struct proc-with-info (proc info) #:p
I'm just curious, is this what you mean?
#lang racket
(require rackunit
(for-syntax
syntax/parse))
(begin-for-syntax
(struct proc-with-info (proc info) #:property prop:procedure
(struct-field-index proc)))
(define-syntax thing
(proc-with-info (lambda (stx)
It sounds like you've got it. A syntax transformer must be a procedure,
and prop:procedure is how you make a procedure that can also be something
else. So if you want something to be both a syntax transformer and a
struct binding, for instance, you need to use prop:procedure and
prop:struct-info.
>
> That doesn't look like a complete program; what does #'done refer to? And
> where did the "val is: " printout go?
That's just a quick hack for illustration purposes. #''done is just
something to return. (note the two quotes) The output is:
val is: ##
'done
But your supposition is correct:
That doesn't look like a complete program; what does #'done refer to? And
where did the "val is: " printout go?
But your supposition is correct: posn is always bound as syntax to a
self-ctor-checked-struct-info-object. That object works as a syntax
transformer; run time references to posn are tr
It's not changing it, I'm just trying to figure out the implementation and
understand what I'm seeing.
For example, given this:
(struct posn (x y))
(define-syntax (test stx)
(syntax-case stx ()
[(_ x)
(printf "val is: ~s" (syntax-local-value #'posn))
#''done]))
> posn
#
> (test x)
#
I'm su
If syntax-local-value is returning something other than the value you put
in, that's a bug. It shouldn't be wrapping it or changing it in any way.
Do you have a program where you bind something via define-syntax that
satisfies struct-info?, and get something out via syntax-local-value that
doesn't
But I don't see how the same binding can be a transformer and also return
something else (like a list, or a checked-struct-info-thing) via
syntax-local-value.
If I bind my-fn as a transformer, then any other macros that use it with
syntax-local-value will receive the transformer procedure back, no
Yes, I believe that the name of a structure defined by "struct" is bound at
syntax-time to a value that implements both prop:procedure, so that it can
expand to a use of the constructor when used in an expression, and
prop:struct-info so that it can be use to look up static information when
passed
How is it that the definition of (struct my-name (x y)) can bind
*my-name*both as a # at runtime and a
transformer-binding
*my-name* that at compile time (via syntax-local-value) produces
#.?
Or, put another way, how can I define a transformer *my-fn* that produces
syntax, but that also exposes hi
18 matches
Mail list logo