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;








3















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









share|improve this question






























    3















    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









    share|improve this question


























      3












      3








      3








      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









      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      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

























          2 Answers
          2






          active

          oldest

          votes


















          2














          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)





          share|improve this answer



























          • Really nice trick, thanks!

            – Jérôme Martin
            Apr 30 at 8:12


















          1














          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.






          share|improve this answer



























            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
            );



            );













            draft saved

            draft discarded


















            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









            2














            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)





            share|improve this answer



























            • Really nice trick, thanks!

              – Jérôme Martin
              Apr 30 at 8:12















            2














            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)





            share|improve this answer



























            • Really nice trick, thanks!

              – Jérôme Martin
              Apr 30 at 8:12













            2












            2








            2







            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)





            share|improve this answer















            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)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            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

















            • 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













            1














            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.






            share|improve this answer





























              1














              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.






              share|improve this answer



























                1












                1








                1







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                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






























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript