@mbutterick you want -l
Hey all, In the “basic” tutorial for beautiful racket the author explains the following bit: > To generate the LINE-FUNC … names, we first put those NUM matches inside a new syntax template as #’(NUM …). Then, just as we did in the b-line macro, use http://docs.racket-lang.org/br/index.html#(def._((lib._br/syntax..rkt)._prefix-id))\|prefix-id to prefix each of them with line-. (This time, we don’t need to worry about source locations.) With this update, the finished macro looks like this: Causing two macros with hard coded prefix-ids: 1) (define-macro (b-line NUM STATEMENT ...)
(with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
#:source #'NUM)])
2) (define-macro (b-module-begin (b-program LINE ...))
(with-pattern
([((b-line NUM STATEMENT ...) ...) #'(LINE ...)]
[(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))])
Question: What’s the “rackety” way to define this prefix in one place and refer to it as a variable. In other languages I’d create some sort of global called “PREFIX-ID”, but I assume this is bad form in racket?
no, that’s fine
If you define it in the same module, remember that b-line
and b-module-begin
needs the value at compile time (phase 1), so you need to define as: (begin-for-syntax (define line-prefix "line-"))
.
Thanks to the both of you :slightly_smiling_face:
@dbriemann has joined the channel
You mentioned, “if you define it in the same module”. What would be the correct mechanic if each usage of my constant is in different files?
Then you need to use (require (for-syntax "the-module-with-configuration.rkt"))
to import it in the file, you use line-prefix
.
And in "the-module-with-configuration.rkt"
you’ll just have (define line-prefix "line-")
and (provide line-prefix)
.
Thank you so much!
Are there a set of exemplary packages I could look at? i’m just getting into package development and I’m looking for inspiration.
@robert.postill Yes… I think there is a blog post … somewhere… with a nice example. Hopefully some of the others can remember where exactly.
@soegaard2 I found https://blog.racket-lang.org/2017/10/tutorial-creating-a-package.html and that’s good but a little light on the end result
There is also a section in Beatiful Racket: https://beautifulracket.com/jsonic-3/the-package-server.html
But try it - and ask here if you get stuck.
Sweet thanks