laurent.orseau
2020-12-30 10:12:06

Is the grammar for https://docs.racket-lang.org/reference/lambda.html?q=lambda#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._lambda%29%29\|lambda loose on purpose? (simplicity?) It allows for mandatory positional arguments even after optional arguments


laurent.orseau
2020-12-30 10:13:36

I feel like this must have been asked several times already…


jesse697
2020-12-30 11:17:44

that sounds pretty bad — perhaps it’s just an oversight?


jesse697
2020-12-30 11:19:51

I suppose the grammar for lambda could be divided into two cases: one for at least one optional arg, another with no optional args


notjack
2020-12-30 12:10:57

Idle thought about the earlier conversation surrounding make-list: is there a function for making a sequence of N copies of a value? Then you wouldn’t need to make this constructor for each collection type (since it’s a pretty uncommon use case) and you could just do (sequence->mycollection (in-copies-of 'foo 5)) instead.


jesse697
2020-12-30 12:22:53

I wonder where the use case comes from. It’s like that in Common Lisp, too. The only use case that comes to mind is doing some kind of zero-filling to prepare for some destructive changes later on.


hectometrocuadrado
2020-12-30 12:38:09

Can I define a C-macro using de FFI in Racket? I need to define a C-macro before a header is included. How can be this achieved?


kellysmith12.21
2020-12-30 12:39:57

That reminds me, I need to fix the grammar for my lang’s lambda, as it allows optionals anywhere, too.


laurent.orseau
2020-12-30 12:45:41

The C ‘macro’ system is kind of terrible (so easy to introduce hard-to-debug bugs). If you have control over the C source file, I would play around replacing C macros with C code generated from scribble. Not sure how much of an enhancement that would be, but at least it would be fun :)


laurent.orseau
2020-12-30 12:52:02

Or maybe you mean that the C file contains a macro and you want to tell the ffi about the macro? My guess is that you don’t need to, as I think C macros are expanded before the ffi binds things(?)


notjack
2020-12-30 12:55:57

I’ve definitely had to do it occasionally, with both immutable lists and mutable vectors. Not sure I remember what the use cases were though.


hectometrocuadrado
2020-12-30 12:56:53

Im using GLFW and Vulkan, and the glfw reference says that i need to define a macro before include de glfw headers to use vulkan


laurent.orseau
2020-12-30 13:09:06

I’m not sure but then maybe you need to write a new C file


hectometrocuadrado
2020-12-30 13:17:10

The bindings of glfw and vulkan are available via the package-manager of DrRacket. Maybe, if I find the c files of glfw I can insert the macro.


hectometrocuadrado
2020-12-30 13:23:13

Cancel that, i can’t. XD


hectometrocuadrado
2020-12-30 13:34:04

Seems that i dont need that macro after all. hehe. Thanks anyway!


laurent.orseau
2020-12-30 13:35:58

Non-problems always have the best solutions!


laurent.orseau
2020-12-30 14:18:56

I’m trying to define a syntax-class that uses some fixed value but I appear to be lost between phases. Racket keeps saying that unsaved editor:15:28: some-value: unbound identifier; also, no #%top syntax transformer is bound in: some-value #(364 10) Any clue?


sorawee
2020-12-30 14:26:42

@laurent.orseau you need some-value to be for-template


sorawee
2020-12-30 14:27:18

sorawee
2020-12-30 14:29:26

Also, I think you need a quote around fml.name


laurent.orseau
2020-12-30 14:36:20

Thanks a ton! So basically, some-value can’t be inside the same module as macro because there’s no begin-for-template?


sorawee
2020-12-30 14:36:59

IIUC, yes


kellysmith12.21
2020-12-30 14:37:39

You could lift everything, except some-value, using begin-for-syntax. But, that could get messy.


sorawee
2020-12-30 14:38:01

it might be possible to create begin-for-template, but I don’t know how. The easiest way might be to expand to another module + require, but then things might get weird.


laurent.orseau
2020-12-30 14:39:24

@kellysmith12.21 Yes, but I’m working with an existing module that doesn’t do that.


kellysmith12.21
2020-12-30 14:40:22

Ah, I see.


gknauth
2020-12-30 15:02:33

(define a 43) (define b x) ... (define a b 43) ;; did you intend (define b a) above?


soegaard2
2020-12-30 15:25:04

Yes. I’ll fix it.


sorawee
2020-12-30 15:50:19

Is it clear from the documentation of datum->syntax that (datum->syntax ctx stx) is simply stx if stx is a syntax? already?


sorawee
2020-12-30 15:52:31

> Converted objects in v are given the lexical context information of ctxt and the source-location information of srcloc. If v is not already a syntax object, then the resulting immediate syntax object is given the properties Because the second sentence specifically calls out what will happen to syntax properties when “v is not already a syntax object”, it gives an impression that the first sentence is a general statement which includes the case when v is a syntax object. But that doesn’t seem to be the case…


soegaard2
2020-12-30 15:58:39

> For any kind of value other than a pair, vector, box, immutable <https://docs.racket-lang.org/reference/hashtables.html?q=datum-%3Esyntax#%28tech.hash.table%29|hash table>, immutable https://docs.racket-lang.org/reference/structures.html?q=datum-%3Esyntax#%28tech._prefab%29\|prefab structure, or <https://docs.racket-lang.org/reference/syntax-model.html?q=datum-%3Esyntax#%28tech.syntax.object%29|syntax object>, conversion means wrapping the value with lexical information, source-location information, and properties after the value is https://docs.racket-lang.org/reference/reader.html?q=datum-%3Esyntax#%28tech._interned%29\|interned via https://docs.racket-lang.org/reference/stxops.html?q=datum-%3Esyntax#%28def._%28%28quote._~23~25kernel%29._datum-intern-literal%29%29\|datum-intern-literal. I suppose the prose could tell that a syntax object converts to itself. > Converted objects in _v are given the lexical context information of _ctxt and the source-location information of _srcloc. If _v is not already a <https://docs.racket-lang.org/reference/syntax-model.html?q=datum-%3Esyntax#%28tech._syntax._object%29|syntax object>, then the … This hints that nothing happens to a syntax object.

I think the text could be a little more explicit - or maybe just an example below to clear things up?


greg
2020-12-30 16:09:27

It would be help if the very first sentence/paragraph were something like: “If v is already a syntax object, v is returned unchanged.” End sentence. End paragraph. Insert existing docs after.

Maybe even an itemlist to emphasize that everything to follow only applies to the “else” case where non-syntax is converted. i.e. Two item bullet points, just like the two branches of the implementation’s topmost if expression (assuming that’s what you’re saying is the impl, literally or conceptually.)


greg
2020-12-30 16:15:59

I mean, I think the existing docs are clear in the sense that they’re correct and complete. But I can also imagine glancing at them too quickly and thinking datum-&gt;syntax could be used as a swiss-army knife to update lexical context, syntax properties, and/or srcloc for some syntax … but it can’t.


kellysmith12.21
2020-12-30 16:48:04

Is there such a swiss-army knife for syntax updates?


soegaard2
2020-12-30 16:48:27

Maybe replace-context ?


sorawee
2020-12-30 16:50:42

(datum-&gt;syntax something (syntax-e stx) something something)


sorawee
2020-12-30 16:51:59

Hmm, swiss-army knife probably should work when stx is not a syntax object.


kellysmith12.21
2020-12-30 17:31:01

I’ve noticed that syntax-parse will parse a literal as an expression, sometimes. This has been the cause of a few buggy macros, which was resolved by reordering alternatives in a macro. Since, if I declare an id as a #:literal, I never want it to be parsed as an expression, is there a way to convince syntax-parse never to parse it as an expression?


soegaard2
2020-12-30 17:57:04

@laurent.orseau I found the cause of the two broken lines. I wanted the grey box around the code to have a width, that matched the code, so I used width: fit-contents . This causes Chrome to break the lines for smaller screens/pages. If I instead have no rule, it doesn’t break the line. But … now extra long comments doesn’t extend the width of the grey box, so the “stick out” to the right…


soegaard2
2020-12-30 18:13:45

Oooh - shiny. It seems adding a white-space: nowrap in combination with width: fit-content works.


sorawee
2020-12-30 18:34:30

@kellysmith12.21 example?


kellysmith12.21
2020-12-30 18:46:03

Given this definition of foo, if the user writes (foo 1 my-lit), then foo will parse my-lit as an expression, and my-lit will throw its syntax error. However, if the two syntax-parse clauses are swapped, then foo will correctly parse my-lit as a literal.


sorawee
2020-12-30 18:52:36

It would be difficult, I think. Ordering is important because you can have side conditions and other stateful stuff. If the grammar is more limited, then that might be possible, but would also limit expressiveness.


laurent.orseau
2020-12-30 19:05:55

I think you might also need to dance on foot under a full moon with a pineapple on your head to make it work


greg
2020-12-30 19:40:05

I can imagine getting surprised by that; I bet I’ve had similar bugs, if not that exact bug, many times. On the other hand it fits my intuition for pattern-matching, generally? With syntax-parse, or match, or X, I would expect I might need to order the more-specific match pattern first, before a clause that matches more generally. IIUC my-lit is more specific than e2:expr — that specific literal is more specific than “any expression (anything that’s not a #:keyword)”. So I think this makes sense, in hindsight. But, yeah, for me anyway, “debugging” is just an antonym for “hindsight”. :slightly_smiling_face:


notjack
2020-12-31 00:43:10

@kellysmith12.21 Does it work correctly regardless of clause ordering if you add a cut? (_ e:expr my-lit ~!)


notjack
2020-12-31 00:47:00

syntax-parse isn’t like match: it does try to use the pattern that makes the most “progress”, in some vague sense that I don’t fully understand. My guess is that it does actually try both patterns, see that they both match, then go with the first one because there’s no cuts to indicate priority and the progress ranking is mostly used for deciding which failing pattern to mention in an error message.


samth
2020-12-31 02:41:28

This is not true for syntax-parse, see https://docs.racket-lang.org/syntax/Parsing_Syntax.html


kellysmith12.21
2020-12-31 02:47:25

Even with a cut, the clause ordering matters.