migueldrums741
2021-9-3 14:33:02

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.


spdegabrielle
2021-9-3 15:16:42

badkins
2021-9-3 16:27:28

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?


badkins
2021-9-3 16:28:51

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


mflatt
2021-9-3 16:36:35

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


mflatt
2021-9-3 16:37:23

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.


badkins
2021-9-3 17:08:16

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?


mflatt
2021-9-3 17:11:53

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.


badkins
2021-9-3 17:14:37

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.


badkins
2021-9-3 17:15:13

vs. a structural solution due to the limitations you mentioned


greg
2021-9-3 17:37:50

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


greg
2021-9-3 17:39:27

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.


sorawee
2021-9-3 18:08:09

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 defines


sorawee
2021-9-3 18:12:23

Oh, just saw that Matthew also said this above


badkins
2021-9-3 20:52:58

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


badkins
2021-9-3 20:53:24

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


sorawee
2021-9-3 20:54:23

Good point, yes, you are right.


badkins
2021-9-3 20:54:46

@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.


dan.ml.901
2021-9-4 01:19:52

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


kellysmith12.21
2021-9-4 02:16:00

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


sorawee
2021-9-4 02:16:43

#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")


sorawee
2021-9-4 02:17:04

If matching regexp literal is what you want


rokitna
2021-9-4 04:55:54

or string literals that match a regexp?