Is it possible to change the result of a syntax-class?define-match-expanderWhen should I use syntax/loc instead of #' (aka syntax)?How can I group optional attributes captured with syntax-parse?Use a syntax list as formal parameters to a functionDefining a nested racket macro with access to surrounding variablesA splicing syntax class that matches an optional pattern and binds attributesracket - define-syntax-class with pattern matching procedureread-syntax: `#…=` forms not enabledsyntax for unsyntax in syntax-parseHow to access syntax-class attributes in `~optional` that contains ellipsis?
How to create a summation symbol with a vertical bar?
How to specify and fit a hybrid machine learning - linear model
Does Swashbuckler's Fancy Footwork apply if the attack was made with Booming Blade?
How can I support the recycling, but not the new production of aluminum?
How to "know" if I have a passion?
To "hit home" in German
Sleeping solo in a double sleeping bag
What happens when I copy a legendary creature with Rite of Replication?
Vacuum collapse -- why do strong metals implode but glass doesn't?
Why didn’t Doctor Strange stay in the original winning timeline?
Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?
Metal that glows when near pieces of itself
How to setup a teletype to a unix shell
Why does my house heat up, even when it's cool outside?
Should my "average" PC be able to discern the potential of encountering a gelatinous cube from subtle clues?
Would combining A* with a flocking algorithm be too performance-heavy?
How to get the pandadocs from an opportunity?
Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")
How big would a Daddy Longlegs Spider need to be to kill an average Human?
How to dismiss intrusive questions from a colleague with whom I don't work?
The teacher logged me in as administrator for doing a short task, is the whole system now compromised?
!I!n!s!e!r!t! !n!b!e!t!w!e!e!n!
Are there nouns that change meaning based on gender?
Bug or undocumented behaviour in Intersection
Is it possible to change the result of a syntax-class?
define-match-expanderWhen should I use syntax/loc instead of #' (aka syntax)?How can I group optional attributes captured with syntax-parse?Use a syntax list as formal parameters to a functionDefining a nested racket macro with access to surrounding variablesA splicing syntax class that matches an optional pattern and binds attributesracket - define-syntax-class with pattern matching procedureread-syntax: `#…=` forms not enabledsyntax for unsyntax in syntax-parseHow to access syntax-class attributes in `~optional` that contains ellipsis?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I currently have a bunch of splicing syntax classes I use to generate code.
They look like this:
(define-splicing-syntax-class vec-exp
(pattern (~seq x y)
#:with result #'(vec x y)))
The goal is to be able to match a sequence x y
anywhere and replace it with (vec x y)
.
The only way I see for now is by creating an attribute called result
and use it:
> (syntax-parse #'(position 4.2 5.7)
[(<name> <pos>:vec-exp)
(attribute <pos>.result)])
#'(vec 4.2 5.7)
Is there a way to change my code so that I can get the same result by writing the following?
> (syntax-parse #'(position 4.2 5.7)
[(<name> <pos>:vec-exp)
(attribute <pos>)])
#'(4.2 5.7) ;; not what I want
racket
add a comment |
I currently have a bunch of splicing syntax classes I use to generate code.
They look like this:
(define-splicing-syntax-class vec-exp
(pattern (~seq x y)
#:with result #'(vec x y)))
The goal is to be able to match a sequence x y
anywhere and replace it with (vec x y)
.
The only way I see for now is by creating an attribute called result
and use it:
> (syntax-parse #'(position 4.2 5.7)
[(<name> <pos>:vec-exp)
(attribute <pos>.result)])
#'(vec 4.2 5.7)
Is there a way to change my code so that I can get the same result by writing the following?
> (syntax-parse #'(position 4.2 5.7)
[(<name> <pos>:vec-exp)
(attribute <pos>)])
#'(4.2 5.7) ;; not what I want
racket
add a comment |
I currently have a bunch of splicing syntax classes I use to generate code.
They look like this:
(define-splicing-syntax-class vec-exp
(pattern (~seq x y)
#:with result #'(vec x y)))
The goal is to be able to match a sequence x y
anywhere and replace it with (vec x y)
.
The only way I see for now is by creating an attribute called result
and use it:
> (syntax-parse #'(position 4.2 5.7)
[(<name> <pos>:vec-exp)
(attribute <pos>.result)])
#'(vec 4.2 5.7)
Is there a way to change my code so that I can get the same result by writing the following?
> (syntax-parse #'(position 4.2 5.7)
[(<name> <pos>:vec-exp)
(attribute <pos>)])
#'(4.2 5.7) ;; not what I want
racket
I currently have a bunch of splicing syntax classes I use to generate code.
They look like this:
(define-splicing-syntax-class vec-exp
(pattern (~seq x y)
#:with result #'(vec x y)))
The goal is to be able to match a sequence x y
anywhere and replace it with (vec x y)
.
The only way I see for now is by creating an attribute called result
and use it:
> (syntax-parse #'(position 4.2 5.7)
[(<name> <pos>:vec-exp)
(attribute <pos>.result)])
#'(vec 4.2 5.7)
Is there a way to change my code so that I can get the same result by writing the following?
> (syntax-parse #'(position 4.2 5.7)
[(<name> <pos>:vec-exp)
(attribute <pos>)])
#'(4.2 5.7) ;; not what I want
racket
racket
asked Mar 27 at 15:25
Jérôme MartinJérôme Martin
1,0421 gold badge11 silver badges24 bronze badges
1,0421 gold badge11 silver badges24 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
FWIW, you can do this. Not sure if it's acceptable for you or not.
(require syntax/parse
(for-syntax syntax/parse))
(define-splicing-syntax-class vec-exp
(pattern (~seq x y) #:with result #'(vec x y)))
(define-syntax ~res
(pattern-expander
(syntax-parser
[(_ pat cls)
#'(~and (~var PAT cls) (~bind [pat (attribute PAT.result)]))])))
And then:
> (syntax-parse #'(position 4.2 5.7)
[(<name> (~res <pos> vec-exp))
(attribute <pos>)])
#'(vec 4.2 5.7)
Really nice trick, thanks!
– Jérôme Martin
Apr 30 at 8:12
add a comment |
I don't think so. The pattern (<name> <pos>:vec-exp)
means "The input must be a list; bind its elements to pattern variables <name>
and <pos>
." Those pattern variables provide access to what got matched. The attributes returned by the syntax class are what got generated. The syntax-parse
system is very fastidious about keeping those two concepts distinct, so I don't think it will let you replace one with the other.
Are you trying to make your macro more readable or less error-prone? If so, maybe tell us a little more. Maybe there is a way to do that.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380849%2fis-it-possible-to-change-the-result-of-a-syntax-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
FWIW, you can do this. Not sure if it's acceptable for you or not.
(require syntax/parse
(for-syntax syntax/parse))
(define-splicing-syntax-class vec-exp
(pattern (~seq x y) #:with result #'(vec x y)))
(define-syntax ~res
(pattern-expander
(syntax-parser
[(_ pat cls)
#'(~and (~var PAT cls) (~bind [pat (attribute PAT.result)]))])))
And then:
> (syntax-parse #'(position 4.2 5.7)
[(<name> (~res <pos> vec-exp))
(attribute <pos>)])
#'(vec 4.2 5.7)
Really nice trick, thanks!
– Jérôme Martin
Apr 30 at 8:12
add a comment |
FWIW, you can do this. Not sure if it's acceptable for you or not.
(require syntax/parse
(for-syntax syntax/parse))
(define-splicing-syntax-class vec-exp
(pattern (~seq x y) #:with result #'(vec x y)))
(define-syntax ~res
(pattern-expander
(syntax-parser
[(_ pat cls)
#'(~and (~var PAT cls) (~bind [pat (attribute PAT.result)]))])))
And then:
> (syntax-parse #'(position 4.2 5.7)
[(<name> (~res <pos> vec-exp))
(attribute <pos>)])
#'(vec 4.2 5.7)
Really nice trick, thanks!
– Jérôme Martin
Apr 30 at 8:12
add a comment |
FWIW, you can do this. Not sure if it's acceptable for you or not.
(require syntax/parse
(for-syntax syntax/parse))
(define-splicing-syntax-class vec-exp
(pattern (~seq x y) #:with result #'(vec x y)))
(define-syntax ~res
(pattern-expander
(syntax-parser
[(_ pat cls)
#'(~and (~var PAT cls) (~bind [pat (attribute PAT.result)]))])))
And then:
> (syntax-parse #'(position 4.2 5.7)
[(<name> (~res <pos> vec-exp))
(attribute <pos>)])
#'(vec 4.2 5.7)
FWIW, you can do this. Not sure if it's acceptable for you or not.
(require syntax/parse
(for-syntax syntax/parse))
(define-splicing-syntax-class vec-exp
(pattern (~seq x y) #:with result #'(vec x y)))
(define-syntax ~res
(pattern-expander
(syntax-parser
[(_ pat cls)
#'(~and (~var PAT cls) (~bind [pat (attribute PAT.result)]))])))
And then:
> (syntax-parse #'(position 4.2 5.7)
[(<name> (~res <pos> vec-exp))
(attribute <pos>)])
#'(vec 4.2 5.7)
edited Apr 30 at 8:26
answered Apr 29 at 10:11
Sorawee PorncharoenwaseSorawee Porncharoenwase
2,5459 silver badges21 bronze badges
2,5459 silver badges21 bronze badges
Really nice trick, thanks!
– Jérôme Martin
Apr 30 at 8:12
add a comment |
Really nice trick, thanks!
– Jérôme Martin
Apr 30 at 8:12
Really nice trick, thanks!
– Jérôme Martin
Apr 30 at 8:12
Really nice trick, thanks!
– Jérôme Martin
Apr 30 at 8:12
add a comment |
I don't think so. The pattern (<name> <pos>:vec-exp)
means "The input must be a list; bind its elements to pattern variables <name>
and <pos>
." Those pattern variables provide access to what got matched. The attributes returned by the syntax class are what got generated. The syntax-parse
system is very fastidious about keeping those two concepts distinct, so I don't think it will let you replace one with the other.
Are you trying to make your macro more readable or less error-prone? If so, maybe tell us a little more. Maybe there is a way to do that.
add a comment |
I don't think so. The pattern (<name> <pos>:vec-exp)
means "The input must be a list; bind its elements to pattern variables <name>
and <pos>
." Those pattern variables provide access to what got matched. The attributes returned by the syntax class are what got generated. The syntax-parse
system is very fastidious about keeping those two concepts distinct, so I don't think it will let you replace one with the other.
Are you trying to make your macro more readable or less error-prone? If so, maybe tell us a little more. Maybe there is a way to do that.
add a comment |
I don't think so. The pattern (<name> <pos>:vec-exp)
means "The input must be a list; bind its elements to pattern variables <name>
and <pos>
." Those pattern variables provide access to what got matched. The attributes returned by the syntax class are what got generated. The syntax-parse
system is very fastidious about keeping those two concepts distinct, so I don't think it will let you replace one with the other.
Are you trying to make your macro more readable or less error-prone? If so, maybe tell us a little more. Maybe there is a way to do that.
I don't think so. The pattern (<name> <pos>:vec-exp)
means "The input must be a list; bind its elements to pattern variables <name>
and <pos>
." Those pattern variables provide access to what got matched. The attributes returned by the syntax class are what got generated. The syntax-parse
system is very fastidious about keeping those two concepts distinct, so I don't think it will let you replace one with the other.
Are you trying to make your macro more readable or less error-prone? If so, maybe tell us a little more. Maybe there is a way to do that.
answered Apr 8 at 18:52
Ben KovitzBen Kovitz
2,5451 gold badge14 silver badges38 bronze badges
2,5451 gold badge14 silver badges38 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380849%2fis-it-possible-to-change-the-result-of-a-syntax-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown