yuhsien77
2020-12-24 08:38:25

Heh, alright. syntax-parse it is.


yuhsien77
2020-12-24 08:38:52

Though I do wonder why the Guide/Reference don’t reflect this state of affairs.


sorawee
2020-12-24 08:41:27

It’s an additional library (you need to require it), whereas syntax-case and friends are in the core Racket.


sorawee
2020-12-24 08:41:42

But it would indeed be nice to have a pointer to the library.


yuhsien77
2020-12-24 08:46:04

Is there talk of including syntax-parse in Racket’s standard library?


sorawee
2020-12-24 08:47:44

There’s a discussion that it should be in Rhombus (previously known as Racket 2)


yuhsien77
2020-12-24 08:48:18

Is Rhombus still a thing? How serious is it?


samth
2020-12-24 14:55:10

Yes, it’s still a thing and definitely serious


samth
2020-12-24 14:55:32

Big things take time


samth
2020-12-24 14:57:10

Also, syntax-parse is in the standard library


samth
2020-12-24 14:57:32

Discussing it in the Guide would be a useful addition/change


rmathews
2020-12-24 14:57:56

@rmathews has joined the channel


cdep.illabout_slack
2020-12-25 04:03:30

In a thread yesterday, samth made a comment which sounded like he is saying syntax-rules should never be used.

Why is this? The <https://docs.racket-lang.org/reference/stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._syntax-rules%29%29|reference documentation for >syntax-rules seems to indicate that it is just a small wrapper around syntax-case. From the conversation yesterday, it didn’t seem like anyone was saying to actively avoid syntax-case (just that syntax-parse was more feature-full).

https://racket.slack.com/archives/C09L257PY/p1608782960003600?thread_ts=1608779679.474200&amp;cid=C09L257PY


yuhsien77
2020-12-25 06:23:24

@cdep.illabout_slack The message I got from yesterday’s conversation was that syntax-parse is what people actually use with Racket. There may be several reasons why the community doesn’t simply deprecate all other macro-writing utilities. I can think of the following: • syntax-case is (iirc) part of the Scheme standard, and while Racket is no longer considered synonymous with Scheme, I don’t think the core language developers want to abandon the standard just yet. • syntax-rules et al. are perceived by many experienced developers as easier for beginners (I don’t know if I completely agree here, but people do say this). At the same time, according to @greg’s Fear of Macros tutorial, syntax-rules and friends are almost deceptively easy, and don’t really give a good intuition for how macros work. In other words, it’s a double-edged sword when learning macros, but very simple to use. On the other hand, the syntax/parse library also includes provisions such as https://docs.racket-lang.org/syntax/Defining_Simple_Macros.html?q=define-simple-macro#%28form._%28%28lib._syntax%2Fparse%2Fdefine..rkt%29._define-simple-macro%29%29\|define-simple-macro, which work in much the same way, but also include all the goodness of syntax-parse under the hood. Thus my conclusion is that syntax-case and syntax-rules are included mostly for historical reasons, and aspiring macro writers should aim for syntax-parse.


yuhsien77
2020-12-25 06:25:03

I’m no expert in either, but my understanding is that syntax-parse does everything that syntax-case does, and a lot more besides, so there really is no good reason to eschew syntax-parse imo.


notjack
2020-12-25 06:45:17

the tl;dr: • replace define-syntax-rule with define-simple-macro • replace syntax-rules with syntax-parse • replace syntax-case with syntax-parse


notjack
2020-12-25 06:46:34

it’s not that the former are dangerous or bad or anything like that. it’s just that syntax-parse has all the same features and a lot more, and it gives you much better error messages by default even if you don’t use any of the extra features.


sorawee
2020-12-25 06:56:07

I’d say replace syntax-rules and syntax-case and with define-syntax-parser. For most applications you rarely need pure syntax-parse.


sorawee
2020-12-25 06:58:12

(In case it was not clear, define-syntax-parser is syntax-parse + define-syntax)


343519265
2020-12-25 07:08:47

syntax-rules doesn’t cooperate well with disappeared-use properties, which make it less useful for me. syntax-parse and its wrappers have #:track-literals , which make things easier.