mflatt
2017-7-20 12:36:35

@notjack Yes, Racket could exit before the thread finishes


fluffywaffles
2017-7-20 17:13:58

is there a way to define something once and have it be available in both the for-syntax and the top-level without copying and pasting? (begin-for-syntax (define my-fn my-fn)) is the dumb first thought that comes to mind, and obviously that doesn’t work. (If it did, I would be surprised.) (edit: where my-fn is already defined, of course)


greg
2017-7-20 17:31:34

@fluffywaffles You can define the thing in a module, then require the module both for runtime and for-syntax.

For instance using module in the same file: #lang racket (module m racket/base (provide f) (define (f) (println "f") 42)) (require (for-syntax 'm) 'm)


greg
2017-7-20 17:32:42

Or you could define f in a module that is another file like f.rkt, and (require "f.rkt" (for-syntax "f.rkt")). Same difference.


fluffywaffles
2017-7-20 17:34:07

gotcha, thanks @greg


greg
2017-7-20 17:35:12

@fluffywaffles You’re welcome. The TL;DR is define things once in a module. Then, how/when they’re available is a function of how you require their module.


leif
2017-7-20 20:32:41

@mflatt How often do we update the versions of various native packages?



leif
2017-7-20 20:33:09

I ask because I would like to know if I can rely on Racket coming with libpng16. (Except on Linux obviously.)


mflatt
2017-7-20 20:33:23

Rarely, and on no particular schedule


leif
2017-7-20 20:33:39

That makes sense. Do we have any announcement when we do?


leif
2017-7-20 20:34:57

I mean, I would be happy to have racket install libpng16 when its needed. But I’m worried about that conflicting with the one Racket comes with.


leif
2017-7-20 20:36:00

I guess, since its not going to update in the middle of a Racket version, I can just make a libpng16 package, and have an exception to not install libpng16 for versions that already have it installed.


mflatt
2017-7-20 20:37:40

We provide libpng16 right now on Windows and Mac OS, right?


leif
2017-7-20 20:42:40

That is correct.


leif
2017-7-20 20:43:01

And on linux it needs to be installed (which it is on basically every distro….)


fluffywaffles
2017-7-20 20:59:41

I’ve having trouble with the str syntax class (or, at least I think I am…?): I have a custom syntax class that uses str in its pattern, but when I give it a str in the correct location it fails to match, even though the output of (string? (syntax-e stx)) is #t.

I made a gist of the issue in an effort to make up a minimal reproduction: https://gist.github.com/fluffywaffles/e616df5399d5e7140b76229af94b30d0

Any help would be much appreciated! I have absolutely no idea why this is happening.


lexi.lambda
2017-7-20 21:00:49

@fluffywaffles It looks like the q class matches a string, but the last subform provided to select is a list containing a string.


fluffywaffles
2017-7-20 21:01:08

Right; I explain that I still think the error is unexpected… Can you explain why it does what it does?


fluffywaffles
2017-7-20 21:01:23

In the gist, rather, I explain in a comment (on the gist, not in the code)


lexi.lambda
2017-7-20 21:03:01

I think you’ll get the behavior you expect if you add the #:commit option to the q syntax class.


lexi.lambda
2017-7-20 21:03:18

Unfortunately, I have to run—maybe someone else can explain in more detail (or I can once I get back).


fluffywaffles
2017-7-20 21:03:35

that works — thanks @lexi.lambda


fluffywaffles
2017-7-20 21:03:51

I don’t know why, but it works


lexi.lambda
2017-7-20 21:04:49

I have another minute or two… basically, without #:commit, syntax-parse can backtrack back into a syntax class even if the syntax class originally succeeded if a later parse fails.


lexi.lambda
2017-7-20 21:05:31

So your q pattern successfully matches "hello" against the first pattern, then continues matching the top-level pattern, and that fails. So it backtracks into q and tries to match "hello" against the second pattern, which always fails.


lexi.lambda
2017-7-20 21:05:56

And specifically, it fails by throwing an exception, not by using ~fail or something like that, so that failure is unrecoverable, and parsing halts.


fluffywaffles
2017-7-20 21:07:33

oh, interesting — so if the first syntax class pattern matches, but then after moving on, the next form in the overall syntax object doesn’t match, it’ll go back to the most recently tested syntax class and try other patterns?


fluffywaffles
2017-7-20 21:07:34

Why is that?


lexi.lambda
2017-7-20 21:07:36

You probably want to use ~fail instead of (~do (raise-syntax-error ...)). Of course, in this case, you probably don’t want the second case at all, and instead might just want to add #:description "question" to q and just let syntax-parse generate its own error message.


lexi.lambda
2017-7-20 21:08:17

But yes, generally, syntax-parse tries everything. It backtracks to try every possible solution unless you explicitly add cuts/commits.


lexi.lambda
2017-7-20 21:08:59

It’s possible to construct a situation in which that backtracking behavior is desirable, but it often isn’t, so #:commit is a useful option for a lot of syntax classes.


lexi.lambda
2017-7-20 21:09:15

Unfortunately, I don’t have time to construct such an example, though.


fluffywaffles
2017-7-20 21:12:44

No, you’ve been plenty helpful even without! Thanks @lexi.lambda


notjack
2017-7-20 21:30:53

@fluffywaffles The “try everything” approach is also paired with a notion of “progress” - syntax-parse orders possible parses based on how early they fail. When parsing fails, this lets syntax-parse choose the parse that failed the latest and uses that parse for an error message, since that’s likely what you want. The “Introduction” section of the syntax parse docs describes this and other aspects of syntax-parse in a friendly manner, I recommend reading it: http://docs.racket-lang.org/syntax/stxparse-intro.html?q=syntax%20parse