samdphillips
2019-3-15 19:11:06

@samdphillips has joined the channel


jerome.martin.dev
2019-3-15 20:18:41

I made the change: https://github.com/racket/racket/pull/2537 Feel free to review it :slightly_smiling_face:


jerome.martin.dev
2019-3-15 20:26:53

@sorawee Hey! Thanks for reviewing. I don’t know how to use ~bind, care to explain further?


sorawee
2019-3-15 20:28:45
(define-syntax (mycond stx)
  (syntax-parse stx
    [(mycond (~optional (~and (~bind [fallthrough
                                      #'[else
                                         (error 'failure
                                                "no clause matched")]])
                              #:error-on-fallthrough))
             clause ...)
     #'(cond clause ... (~? fallthrough))]))

sorawee
2019-3-15 20:28:49

Like this, I think


alexknauth
2019-3-15 20:29:51

For the purposes of the syntax-parse example though, maybe it should be something simpler, that doesn’t require ~bind or ~?.


sorawee
2019-3-15 20:31:14

I see. That’s a good point.


jerome.martin.dev
2019-3-15 20:31:37

@sorawee Oh, I see, thanks! I agree with @alexknauth, that would be cool to find a simpler example.


alexknauth
2019-3-15 20:32:52

The first thing that comes to mind is a struct-like macro with a #:transparent flag that determines whether the “inspector” argument is #f or (current-inspector), but that might also be more complicated than neccessary.


jerome.martin.dev
2019-3-15 20:33:39

Yep, I was thinking about something with structs too, because that’s one of the “standalone keywords” in the wild that are widely used


jerome.martin.dev
2019-3-15 20:34:24

But as all other examples were about this mycond thing, I tried to stay consistent


alexknauth
2019-3-15 20:42:01

The “More Keyword Arguments” section of the syntax-parse examples uses the struct options as examples: https://docs.racket-lang.org/syntax/More_Keyword_Arguments.html?q=Optional%20Keyword


alexknauth
2019-3-15 20:42:54

However, it uses it to explain ellipsis-head patterns, which is also more complicated than necessary when there’s only one flag.


alexknauth
2019-3-15 20:43:42

But maybe a simplified version of that struct example with only one flag would make sense in the first “Optional Keyword Arguments” section.


jerome.martin.dev
2019-3-15 20:44:51

Wow, yes, my solution was already buried in that big example, and I definitely couldn’t see it when I skimmed over the doc.


jerome.martin.dev
2019-3-15 20:45:12

I guess it’s a good reason for making a simpler example


alexknauth
2019-3-15 20:46:34

> There are two main problems with the pattern above: > • There’s no way to tell whether a zero-argument keyword like #:mutable was seen. > • Some options, like #:mutable, should appear at most once. > > The first problem can be remedied using ~and patterns to bind a pattern variable to the keyword itself, as in this sub-pattern: > (~seq (~and #:mutable mutable-kw))


jerome.martin.dev
2019-3-15 20:47:08

It happens a lot when Iearn new tricks in Racket: I read the doc, I don’t understand a thing, I try stuff by myself, I check on stackoverflow, I ask here, then days later, when I finally get it, I read the doc again, and now it makes sense.


alexknauth
2019-3-15 20:48:06

The problem is the doc example in “Other Keyword Arguments” tried to address both of those two bullet points at once, and the solution to the first ended up washed out by the solution to the second.


jerome.martin.dev
2019-3-15 20:48:34

yep


jerome.martin.dev
2019-3-15 20:49:32

I’d add that none of the examples in that page shows up the template part


jerome.martin.dev
2019-3-15 20:49:47

which means as a reader you don’t know how to use what you just matched


jerome.martin.dev
2019-3-15 20:51:37

By reading those example, as a beginner, I still don’t get why (~and) was used and what it did (create an attribute bound to the keyword)


jerome.martin.dev
2019-3-15 20:52:45

while the example I suggest shows precisely that, and nothing else


jerome.martin.dev
2019-3-15 20:53:08

(except from the ~@ usage which I find clumsy)


sorawee
2019-3-15 22:35:09

Sorry for a dumb question, but why is, for example, define-syntaxes a part of Racket core form? Ideally I think that after fully expand Racket code, I would have code in phase 0, and all define-syntaxes could be safely removed.


notjack
2019-3-15 23:49:27

@sorawee I think it’s because fully expanded modules can still export syntax definitions for other modules to import


notjack
2019-3-15 23:50:14

There may be other reasons too


shu--hung
2019-3-16 00:41:41

It’s possible that they will be used by some other module for example, the expansion time of another module could depend on those transformers and even the runtime of another module could depend on them if the module is require for-template


shu--hung
2019-3-16 00:44:53

if a module would only by instantiated at 0, then those define-syntaxes won’t be used but the module itself cannot determine that


samth
2019-3-16 00:47:18

@sorawee what @notjack says is right — if you are turning something into a single executable and you’ll never require the module, then define-syntax could be removed


sorawee
2019-3-16 03:25:07

I see. Thanks!