Re: [racket-users] How to disallow certain characters in identifiers?
Thanks for your response Alexis. You are right: once I figured out the correct way to customize the reader, the rest fell into place much more easily. Now, when my reader sees a dot it asks the base reader to read another piece of syntax, which must be an identifier. So (define a.b 3) becomes (define a .b 3) and the default error message is good enough for now, especially since Racket prints out the 2nd version with the error message. Also, I realized what a bad idea rewriting "a+b" to (+ a b) is. Because then I should do the same for subtraction. And then, for example, "struct-info" becomes (- struct info) which is a death sentence for a language based on Racket. So now infix notation requires whitespace around the operator. For those curious "what are you really trying to do anyway?" I really like how at-exp can attach a convenient syntax onto racket without interfering with your ability to write standard racket. I am trying to do something similar. In my language, curly braces will get treated differently than the other paren-shapes. For example {if 10 .add1 {.equal? 11} 'yep 'nope} will get rewritten to (if (equal? (add1 10) 11) 'yep 'nope). My hope is that experienced Racketeers will find it convenient when they want to use it, and unintrusive when they don't. And that beginners who would be scared off by raw s-expressions will find it familiar enough to be pleasant. -- 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] Racket 5, multiple-collection packages and info.rkt
I am trying to split the package graph into graph-doc and graph-lib, see: https://github.com/stchang/graph/pull/37 So far, the package has been compatible with Racket 5.3.2, and I image the original author Mr. Chang would like to keep it that way, if possible. In their respective graph/info.rkt (until now a single file, now split into two files), graph-lib wants to define test-timeouts and graph-doc wants to define scribblings. On Racket 6 this is fine, but on Racket 5[0] I get: raco pkg install: packages conflict package: ./graph-lib package: graph-doc file: graph/info.rkt If I remove graph-doc/graph/info.rkt, the documentation does not get built. Do we have to drop Racket 5 compatibility to split this package in two? [0] not on Racket 5.92, but I guess that would be more appropriately named something like 6.0rc or 6.0pre? - - - - I looked in Racket 5.93 and there pkgs/net-pkgs/net-doc/net didn't have an info.rkt. How did the documentation get built? Is there some special workaround for release packages? On Racket 5.3.6 and earlier the release packages weren't separate packages, they were simply in core collects, and I assume there was no racket-minimal? So I have nothing to learn from by looking there. -- /c -- 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] Macro introducing definitions from list of ids
Ha! A new question! 1. My macro expands. I use the macro expander (which is wonderful), and everything looks good. 2. In my code, Racket helpfully claims the identifier that I believe should be bound, is not bound. 3. I copy the expanded macro from the expander. 4. I comment out the macro use site. 5. I paste in the expanded macro. 6. Everything works. This suggests to me I have the expansion I want. Does each step of the macro expander change color for friendliness, or are those expansion phases, and therefore only my first round of expansion is being recognized as being in the environment (as opposed to a macro that expands to a macro that expands to identifiers)? I'm enjoying rereading "Fortifying Macros," and think I'll rewrite things I've written in my explorations now, but I don't know if that will address this question. Many thanks, Matt On Tue, Dec 11, 2018 at 5:21 PM Matt Jadud wrote: > I'm wondering if... > > > https://stackoverflow.com/questions/41102630/transforming-a-list-of-symbols-to-a-list-of-identifiers-to-be-used-in-a-macro > > is what I'm looking for (he says, answering himself)... > > (define-syntax (introduce stx) > (syntax-case stx () > [(_ tag ids ...) > (with-syntax ([(getter ...) (datum->syntax #'tag > (map (λ (id) >(string->symbol > (format "~a-get-~a" > > (syntax->datum #'tag) > > id))) > (syntax->datum #'(ids > ...]) >#`(begin >(define (getter) > ;; Generating a do-nothing body for demonstration... > (format "get ~a ~a" (quote tag) (quote getter))) ... > ))])) > > Here's one answer. And I just crossed with Jens... > > Many thanks, Jens. That's much nicer. It illustrates how to decompose the > problem into a few clean helpers to make the resulting macro much clearer. > > Thank you, > Matt > > On Tue, Dec 11, 2018 at 5:07 PM Matt Jadud wrote: > >> Many thanks, John. >> >> I've made it that far. I'll be more specific... >> >> Conceptually, I want... >> >> (define-syntax (introduce stx) >> (syntax-case stx () >> [(_ tag ids ...) >> (with-syntax ([(getters ...) >> (map (λ (id) (format-id #'tag "~a-get-~a" tag id)) >> ids ...)]) >>#`(begin >>(define (getters) 'get-something) ...) >>)])) >> >> so that >> >> (introduce tag a b c) >> >> produces >> >> (define (tag-get-a) ...) >> (define (tag-get-b) ...) >> (define (tag-get-c) ...) >> >> I am aware that I can't use 'map' in the context above. I... know, but do >> not understand, that the LHS of with-syntax is a syntax pattern. However, >> how I would generate a syntactic form that I would match against that >> pattern where I generate the identifiers for the defines (and then how I >> would appropriately use ... to indicate repetition of the defines form, if >> the structure above is even close) is what I'm wrestling with. >> >> Cheers, >> M >> >> >> >> On Tue, Dec 11, 2018 at 4:16 PM John Clements >> wrote: >> >>> In answer to at least one of your questions, top-level “begin”s are >>> “spliced” into their context to produce top-level bindings. So, for >>> instance, >>> >>> #lang racket >>> >>> (begin >>> (define a 3) >>> (define b 4)) >>> >>> (+ b a) >>> >>> … evaluates to 7 >>> >>> I think this is not the only issue you’re going to run into, but it’s at >>> least one of them. >>> >>> Apologies if I misunderstood your question! >>> >>> John >>> >>> > On Dec 11, 2018, at 1:12 PM, Matt Jadud wrote: >>> > >>> > Hi all, >>> > >>> > I'm exploring macros today. >>> > >>> > I'd like to introduce a set of bindings. For example, I would like >>> > >>> > (introduce tag a b c) >>> > >>> > to become >>> > >>> > (define (tag-get-a) ...) >>> > (define (tag-set-a! v) ...) >>> > >>> > or somesuch set of defines. I've discovered with-syntax and format-id, >>> and have had good success with introducing singular defines, but how to >>> expand the list of ids into a list of defines is something I'm not seeing >>> yet. Somehow, I feel like a macro that simply follows the natural recursion >>> on the syntax objects is probably the answer, but... that's like saying the >>> answer to a question in quantum mechanics is either 0, 1, or h-bar/2... >>> > >>> > I'm looking at the define-cbr example in the documentation, and >>> suspicious that I'm reaching a point with my macro authoring where the ... >>> and (... ...) are leaving me confused as to which layer of expansion I'm >>> dealing with as I look at my code. Hence, I'm asking for a nudge in the >>> right direction. >>> > >>> > Cheers, >>> > Matt >>> > >>> > >>> > >>> > -- >>> > 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,
[racket-users] Why enter/run a submodule in the REPL?
Hi, #lang racket (displayln "This is the main module") (module+ drracket (define foo 'FOO) (displayln "This is the drracket submodule")) Execute and DrRacket displays "This is the main module" in the interactions window type (require (only-in racket/enter dynamic-enter!) (only-in syntax/location quote-module-path)) (dynamic-enter! (quote-module-path drracket)) and bindings defined in the submodule are then available; e.g. > foo 'FOO Why and how do I use this for interactive development, scripting and debugging? There is also a DrRacket function (Submodules to Run), but I can't find any documentation for it. Stephen -- 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] Macro introducing definitions from list of ids
I'm wondering if... https://stackoverflow.com/questions/41102630/transforming-a-list-of-symbols-to-a-list-of-identifiers-to-be-used-in-a-macro is what I'm looking for (he says, answering himself)... (define-syntax (introduce stx) (syntax-case stx () [(_ tag ids ...) (with-syntax ([(getter ...) (datum->syntax #'tag (map (λ (id) (string->symbol (format "~a-get-~a" (syntax->datum #'tag) id))) (syntax->datum #'(ids ...]) #`(begin (define (getter) ;; Generating a do-nothing body for demonstration... (format "get ~a ~a" (quote tag) (quote getter))) ... ))])) Here's one answer. And I just crossed with Jens... Many thanks, Jens. That's much nicer. It illustrates how to decompose the problem into a few clean helpers to make the resulting macro much clearer. Thank you, Matt On Tue, Dec 11, 2018 at 5:07 PM Matt Jadud wrote: > Many thanks, John. > > I've made it that far. I'll be more specific... > > Conceptually, I want... > > (define-syntax (introduce stx) > (syntax-case stx () > [(_ tag ids ...) > (with-syntax ([(getters ...) > (map (λ (id) (format-id #'tag "~a-get-~a" tag id)) ids > ...)]) >#`(begin >(define (getters) 'get-something) ...) >)])) > > so that > > (introduce tag a b c) > > produces > > (define (tag-get-a) ...) > (define (tag-get-b) ...) > (define (tag-get-c) ...) > > I am aware that I can't use 'map' in the context above. I... know, but do > not understand, that the LHS of with-syntax is a syntax pattern. However, > how I would generate a syntactic form that I would match against that > pattern where I generate the identifiers for the defines (and then how I > would appropriately use ... to indicate repetition of the defines form, if > the structure above is even close) is what I'm wrestling with. > > Cheers, > M > > > > On Tue, Dec 11, 2018 at 4:16 PM John Clements > wrote: > >> In answer to at least one of your questions, top-level “begin”s are >> “spliced” into their context to produce top-level bindings. So, for >> instance, >> >> #lang racket >> >> (begin >> (define a 3) >> (define b 4)) >> >> (+ b a) >> >> … evaluates to 7 >> >> I think this is not the only issue you’re going to run into, but it’s at >> least one of them. >> >> Apologies if I misunderstood your question! >> >> John >> >> > On Dec 11, 2018, at 1:12 PM, Matt Jadud wrote: >> > >> > Hi all, >> > >> > I'm exploring macros today. >> > >> > I'd like to introduce a set of bindings. For example, I would like >> > >> > (introduce tag a b c) >> > >> > to become >> > >> > (define (tag-get-a) ...) >> > (define (tag-set-a! v) ...) >> > >> > or somesuch set of defines. I've discovered with-syntax and format-id, >> and have had good success with introducing singular defines, but how to >> expand the list of ids into a list of defines is something I'm not seeing >> yet. Somehow, I feel like a macro that simply follows the natural recursion >> on the syntax objects is probably the answer, but... that's like saying the >> answer to a question in quantum mechanics is either 0, 1, or h-bar/2... >> > >> > I'm looking at the define-cbr example in the documentation, and >> suspicious that I'm reaching a point with my macro authoring where the ... >> and (... ...) are leaving me confused as to which layer of expansion I'm >> dealing with as I look at my code. Hence, I'm asking for a nudge in the >> right direction. >> > >> > Cheers, >> > Matt >> > >> > >> > >> > -- >> > 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. >> >> >> >> -- 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] Macro introducing definitions from list of ids
Hi Matt, The following is one way to define the macro. The recipe is as follows: 1. Define format-functions that produce the identifiers needed. 2. Write the template (the syntax/loc expression) using the generated names 3. Wrap the template with a with-syntax that binds the generated names to names produced by format functions /Jens Axel #lang racket (require (for-syntax syntax/parse racket/syntax racket/sequence)) ; Example: ; (introduce tag a b c) ; => ; (begin ; (define tag-ht (make-hasheq)) ; (define (tag-get-a)(hash-ref tag-ht 'a #f)) ... ; (define (tag-set-a! v) (hash-set! tag-ht 'a v))) ...) (begin-for-syntax (define (format-tag-htctx loc tag) (format-id ctx "~a-ht" tag #:source loc)) (define (format-tag-get-name ctx loc tag name) (format-id ctx "~a-get-~a" tag name #:source loc)) (define (format-tag-set-name! ctx loc tag name) (format-id ctx "~a-set-~a!" tag name #:source loc))) (define-syntax (introduce stx) (syntax-parse stx [(_introduce tag:id x:id ...) (define tag-sym (syntax-e #'tag)) (with-syntax ([tag-ht (format-tag-ht stx #'tag tag-sym)] [(tag-get-x ...) (for/list ([name (in-syntax #'(x ...))]) (format-tag-get-name stx name tag-sym (syntax-e name)))] [(tag-set-x! ...) (for/list ([name (in-syntax #'(x ...))]) (format-tag-set-name! stx name tag-sym (syntax-e name)))]) (syntax/loc stx (begin (define tag-ht (make-hasheq)) (define (tag-get-x)(hash-ref tag-ht 'x #f)) ... (define (tag-set-x! v) (hash-set! tag-ht 'x v)) ...)))])) (introduce label a b c) (label-set-a! 42) (label-get-a) Den tir. 11. dec. 2018 kl. 23.08 skrev Matt Jadud : > Many thanks, John. > > I've made it that far. I'll be more specific... > > Conceptually, I want... > > (define-syntax (introduce stx) > (syntax-case stx () > [(_ tag ids ...) > (with-syntax ([(getters ...) > (map (λ (id) (format-id #'tag "~a-get-~a" tag id)) ids > ...)]) >#`(begin >(define (getters) 'get-something) ...) >)])) > > so that > > (introduce tag a b c) > > produces > > (define (tag-get-a) ...) > (define (tag-get-b) ...) > (define (tag-get-c) ...) > > I am aware that I can't use 'map' in the context above. I... know, but do > not understand, that the LHS of with-syntax is a syntax pattern. However, > how I would generate a syntactic form that I would match against that > pattern where I generate the identifiers for the defines (and then how I > would appropriately use ... to indicate repetition of the defines form, if > the structure above is even close) is what I'm wrestling with. > > Cheers, > M > > > > On Tue, Dec 11, 2018 at 4:16 PM John Clements > wrote: > >> In answer to at least one of your questions, top-level “begin”s are >> “spliced” into their context to produce top-level bindings. So, for >> instance, >> >> #lang racket >> >> (begin >> (define a 3) >> (define b 4)) >> >> (+ b a) >> >> … evaluates to 7 >> >> I think this is not the only issue you’re going to run into, but it’s at >> least one of them. >> >> Apologies if I misunderstood your question! >> >> John >> >> > On Dec 11, 2018, at 1:12 PM, Matt Jadud wrote: >> > >> > Hi all, >> > >> > I'm exploring macros today. >> > >> > I'd like to introduce a set of bindings. For example, I would like >> > >> > (introduce tag a b c) >> > >> > to become >> > >> > (define (tag-get-a) ...) >> > (define (tag-set-a! v) ...) >> > >> > or somesuch set of defines. I've discovered with-syntax and format-id, >> and have had good success with introducing singular defines, but how to >> expand the list of ids into a list of defines is something I'm not seeing >> yet. Somehow, I feel like a macro that simply follows the natural recursion >> on the syntax objects is probably the answer, but... that's like saying the >> answer to a question in quantum mechanics is either 0, 1, or h-bar/2... >> > >> > I'm looking at the define-cbr example in the documentation, and >> suspicious that I'm reaching a point with my macro authoring where the ... >> and (... ...) are leaving me confused as to which layer of expansion I'm >> dealing with as I look at my code. Hence, I'm asking for a nudge in the >> right direction. >> > >> > Cheers, >> > Matt >> > >> > >> > >> > -- >> > 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. >> >> >> >> -- > 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. > Fo
Re: [racket-users] Macro introducing definitions from list of ids
Many thanks, John. I've made it that far. I'll be more specific... Conceptually, I want... (define-syntax (introduce stx) (syntax-case stx () [(_ tag ids ...) (with-syntax ([(getters ...) (map (λ (id) (format-id #'tag "~a-get-~a" tag id)) ids ...)]) #`(begin (define (getters) 'get-something) ...) )])) so that (introduce tag a b c) produces (define (tag-get-a) ...) (define (tag-get-b) ...) (define (tag-get-c) ...) I am aware that I can't use 'map' in the context above. I... know, but do not understand, that the LHS of with-syntax is a syntax pattern. However, how I would generate a syntactic form that I would match against that pattern where I generate the identifiers for the defines (and then how I would appropriately use ... to indicate repetition of the defines form, if the structure above is even close) is what I'm wrestling with. Cheers, M On Tue, Dec 11, 2018 at 4:16 PM John Clements wrote: > In answer to at least one of your questions, top-level “begin”s are > “spliced” into their context to produce top-level bindings. So, for > instance, > > #lang racket > > (begin > (define a 3) > (define b 4)) > > (+ b a) > > … evaluates to 7 > > I think this is not the only issue you’re going to run into, but it’s at > least one of them. > > Apologies if I misunderstood your question! > > John > > > On Dec 11, 2018, at 1:12 PM, Matt Jadud wrote: > > > > Hi all, > > > > I'm exploring macros today. > > > > I'd like to introduce a set of bindings. For example, I would like > > > > (introduce tag a b c) > > > > to become > > > > (define (tag-get-a) ...) > > (define (tag-set-a! v) ...) > > > > or somesuch set of defines. I've discovered with-syntax and format-id, > and have had good success with introducing singular defines, but how to > expand the list of ids into a list of defines is something I'm not seeing > yet. Somehow, I feel like a macro that simply follows the natural recursion > on the syntax objects is probably the answer, but... that's like saying the > answer to a question in quantum mechanics is either 0, 1, or h-bar/2... > > > > I'm looking at the define-cbr example in the documentation, and > suspicious that I'm reaching a point with my macro authoring where the ... > and (... ...) are leaving me confused as to which layer of expansion I'm > dealing with as I look at my code. Hence, I'm asking for a nudge in the > right direction. > > > > Cheers, > > Matt > > > > > > > > -- > > 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. > > > > -- 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] Macro introducing definitions from list of ids
In answer to at least one of your questions, top-level “begin”s are “spliced” into their context to produce top-level bindings. So, for instance, #lang racket (begin (define a 3) (define b 4)) (+ b a) … evaluates to 7 I think this is not the only issue you’re going to run into, but it’s at least one of them. Apologies if I misunderstood your question! John > On Dec 11, 2018, at 1:12 PM, Matt Jadud wrote: > > Hi all, > > I'm exploring macros today. > > I'd like to introduce a set of bindings. For example, I would like > > (introduce tag a b c) > > to become > > (define (tag-get-a) ...) > (define (tag-set-a! v) ...) > > or somesuch set of defines. I've discovered with-syntax and format-id, and > have had good success with introducing singular defines, but how to expand > the list of ids into a list of defines is something I'm not seeing yet. > Somehow, I feel like a macro that simply follows the natural recursion on the > syntax objects is probably the answer, but... that's like saying the answer > to a question in quantum mechanics is either 0, 1, or h-bar/2... > > I'm looking at the define-cbr example in the documentation, and suspicious > that I'm reaching a point with my macro authoring where the ... and (... ...) > are leaving me confused as to which layer of expansion I'm dealing with as I > look at my code. Hence, I'm asking for a nudge in the right direction. > > Cheers, > Matt > > > > -- > 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. -- 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] Macro introducing definitions from list of ids
Hi all, I'm exploring macros today. I'd like to introduce a set of bindings. For example, I would like (introduce tag a b c) to become (define (tag-get-a) ...) (define (tag-set-a! v) ...) or somesuch set of defines. I've discovered with-syntax and format-id, and have had good success with introducing singular defines, but how to expand the list of ids into a list of defines is something I'm not seeing yet. Somehow, I feel like a macro that simply follows the natural recursion on the syntax objects is probably the answer, but... that's like saying the answer to a question in quantum mechanics is either 0, 1, or h-bar/2... I'm looking at the define-cbr example in the documentation, and suspicious that I'm reaching a point with my macro authoring where the ... and (... ...) are leaving me confused as to which layer of expansion I'm dealing with as I look at my code. Hence, I'm asking for a nudge in the right direction. Cheers, Matt -- 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.