
Hello group, I’m a beginner using Racket but I really need to create a simple website using this language. I’m trying to create html structure and so far I have done this, can anyone give me some advice to improve this part? And how can I use CSS (style.css) to improve the appearance of my website? Thanks in advance. Excuse my rookie question.

The continue tutorial shows you how to add CSS: https://docs.racket-lang.org/continue/index.html#%28part._.Decorating_.With_.Style_%29

I’m going through Greg’s “Fear of Macros” again, and in <https://www.greghendershott.com/fear-of-macros/What_s_the_point_of_splicing-let_.html|chapter 6>, he gives a splicing-let
example: #lang racket
(require racket/splicing)
(splicing-let ([ x 7 ])
(define (get-x)
x))
(get-x)
When I run this through the macro stepper in DrRacket, I get: Expansion finished
(module anonymous-module racket
(#%module-begin
(module configure-runtime '#%kernel
(#%module-begin (#%require racket/runtime-config) (#%app configure (quote #f))))
(#%require racket/splicing)
(define-values (x) (quote 7))
(define-values (get-x) (lambda () x))
(#%app call-with-values (lambda () (#%app get-x)) print-values)))
I’m failing to see how this prohibits access to x
- any pointers?

In other words, I expected the expansion to look something like: (define get-x
(let ([ x 7 ])
(λ ()
x)))

The x
in the expansion has an extra scope that other uses of x
wouldn’t have. Since other x
s won’t have that scope, they can’t refer to the same x
.

In the macro stepper, you can see that by adding x
to the end of the module, That will trigger a syntax error. But by going back a couple of steps, you can click on the bound x
and the referencing x
, and compare what shows up in the “Scopes” section on the panel on the right.

Thanks @mflatt - I can see the scopes differences now. Was it implemented this way because it was convenient to use Racket’s “set of scopes” functionality? Maybe a better question is, if this was done in a Scheme, would the macro expansion been more intuitive i.e. similar to what I expected above?

The expansion was essentially the same in Racket before switching to scope sets. You have a single function definition in your example for the body of splicing-let
, but you could have multiple functions or even macros in the body. With a mixture of functions and macros, a let
wrapper can’t work.

Interesting - thanks. If I’m understanding you correctly, the key to this is the use of scopes in the syntax object, so to do something in, for example, Chez Scheme, it would be similar in that regard.

vs. a structural solution due to the limitations you mentioned

Ugh that’s a weak section of FoM. I should try to find time to update that.

I mean, the whole thing is in that genre of, “follow along as I struggle and figure things out (mostly?)”, but even so, that’s a weak section.

I don’t think this can really be done. Consider:
#lang racket
(require racket/splicing)
(splicing-let ([v (vector 1)])
(define (put x)
(vector-set! v 0 x))
(define (get)
(vector-ref v 0)))
(put 5)
(get)
If it’s expanded in the way that you describe, then v
couldn’t be shared across define
s

Oh, just saw that Matthew also said this above

@sorawee I’m not sure I follow given the example in Greg’s article: (define-values (inc dec get)
(let ([x 0])
(values (lambda () ; inc
(set! x (+ x 1)))
(lambda () ; dec
(set! x (- x 1)))
(lambda () ; get
x))))

I thought the limitation Matthew was hinting at was a mixture of functions and macros, but I could be mistaken.

Good point, yes, you are right.

@greg I thought the section was fine, I was (am?) struggling to see how splicing-let
is implemented, but I suppose I should just go look at it.

How can I write a syntax class that only matches a regexp? I.e. (syntax-parse stx ([_ thing:my-class] #'thing)))
where my-class
is a regexp matcher

@dan.ml.901 Do you want to match regexp literals, or any expression that is a regexp?

#lang racket
(require (for-syntax syntax/parse))
(define-syntax (test stx)
(syntax-parse stx
[(_ x:regexp)
#'"this is a regexp literal"]
[_ #'"this is not a regexp literal"]))
(define x #px"abc")
(test x)
(test #px"abc")

If matching regexp literal is what you want

or string literals that match a regexp?