tiotolstoy
2020-10-3 07:15:11

@tiotolstoy has joined the channel


notjack
2020-10-3 10:32:10

I’d much rather see a pr to add a version that works on arbitrary sequences


greg
2020-10-3 12:52:59

(struct foo (a)) defines a basic constructor function foo where you need to supply all the parameters for all the struct fields.

What @laurent.orseau means by a “smart constructor” (I believe) is, you just also define your own function (say you call it make-foo) that has any fancier behavior you want. Such as default parameters. Keyword parameters. A contract, or, manual validation. And so on.


greg
2020-10-3 12:53:43

I think @samth meant “unnecessary” more than “unhelpful”. All those things can be helpful. But you can handle it yourself, it doesn’t need to be baked into the core struct.


greg
2020-10-3 12:54:33

Of course if you do this kind of thing a lot, you can write your own “define struct” macro that defines both a struct and its fancy-constructor.


greg
2020-10-3 12:55:08

I think various people have done this. Various opinions how.


greg
2020-10-3 12:56:18

@jestarray @kellysmith12.21 ^


samth
2020-10-3 13:00:20

I specifically mean the default value feature that actually exists is unhelpful


samth
2020-10-3 13:00:50

A different feature, or a way to create smart constructors, would be useful, and many exist


samth
2020-10-3 13:02:35

The existing feature of struct is only useful for mutable fields that will only ever be set by a client not constructing the struct


blerner
2020-10-3 14:17:45

Is there a way in a #lang scribble/manual file to hide some of the for-label bindings, so that @racketblock doesn’t hyperlink them?


soegaard2
2020-10-3 14:18:18

only-in ?


soegaard2
2020-10-3 14:18:29

except-in ?


blerner
2020-10-3 14:19:56

I didn’t require any particular bindings though; these are (I think) coming from the #lang line itself


soegaard2
2020-10-3 14:20:20

Ah. Tricky.


soegaard2
2020-10-3 14:20:34

Don’t know.


sorawee
2020-10-3 14:52:07

@blerner I don’t think that’s true. If you use #lang scribble/manual without any for-label, then nothing will be linked. You need to (require (for-label racket/base)) explicitly to at least get built-in bindings.


blerner
2020-10-3 14:53:07

yeah, after tracing through our imports some more, it looks like there in fact was a required library for-label that I hadn’t noticed. now that I see it, I can except-in eliminate the parts I don’t want


joel
2020-10-3 14:54:29

Could you somehow use a dummy module that shadows the bindings you don’t want?


joel
2020-10-3 14:54:49

Ah nvm


joel
2020-10-3 14:58:10

Is it a bug that build-path/convention-type cannot construct a Unix-style path when running on Windows?


sorawee
2020-10-3 15:01:56

yeah, was going to comment on the Pollen issue that you might want to report the problem lol


jestarray
2020-10-3 23:31:55

for pairs i need '(0 . (1 . 2)) where the 2nd element is a pair and the first is a value


jestarray
2020-10-3 23:32:07

but racket turns that into '(0 1 . 2)


jestarray
2020-10-3 23:33:03

i need the parenthesis there for the 2nd element because the serializer to a rust struct requires: (name . ( (first . "bob" ) (last . smith))) the first element to be the name of the field, and the second to be the value


franklai_slack
2020-10-3 23:36:08

@franklai_slack has joined the channel


kellysmith12.21
2020-10-3 23:37:22

@jestarray The parentheses are implicit, however, you could write a custom print function to keep them.


jestarray
2020-10-3 23:40:22

im unsure how to go about doing so…


kellysmith12.21
2020-10-3 23:57:23

Oh, it’s for a serializer? That’s the format that needs to be read in?


jestarray
2020-10-3 23:58:33

yeppers. #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] struct Person { name: String, age: u8, }; // always in the format of (symbol . value). Trying to get (symbol . (symbol . value)) e.g (name . ((first . "bob) (last . smith))) working but racket excludes the parens needed let joanne: Person = from_str("((name . \"Joanne\") (age . 23))").unwrap(); https://docs.rs/serde-lexpr/0.1.1/serde_lexpr/


kellysmith12.21
2020-10-4 00:01:56

Ah, I see.


kellysmith12.21
2020-10-4 00:04:49

In that case, I would suggest defining a Racket struct to represent a Rust struct. Then, you can define a function to serialize it.


kellysmith12.21
2020-10-4 00:06:34

I’ll write up a quick example.


jestarray
2020-10-4 00:08:29

gonna try to see if i can get it to print pairs with the parens first… the docs on it is a bit scruffy…


kellysmith12.21
2020-10-4 00:19:43

This function will print a list to the provided output-port, while keeping parens and middle dots: (define (print-pair/parens pr [port (current-output-port)]) (fprintf port "'(~a . ~a)" (car pr) (let loop ([val (cdr pr)]) (if (pair? val) (format "(~a . ~a)" (car val) (loop (cdr val))) val))))


jestarray
2020-10-4 00:30:54

thanks, ill give it a shot


jestarray
2020-10-4 00:31:23

so close yet so far to near zero friction….


kellysmith12.21
2020-10-4 00:33:13

(If you don’t want the leading quote, then that function can be simplified.)


rokitna
2020-10-4 02:57:11

Treating (a b . c) and (a . (b . c)) as equivalent is one of the things s-expression formats typically have in common. I bet serde-lexpr would accept either one.


rokitna
2020-10-4 03:01:09

That being said, it’s good to write explicit serializing code in situations like this. If Racket and serde-lexpr do turn out to differ on some aspect of the s-expression syntax, trying to rely on Racket’s write will only get you so far.


jestarray
2020-10-4 03:28:42

i was using print because it initially gave me the least resistance but now write is turning out better now


jestarray
2020-10-4 03:29:08

just have to replace a few things


jestarray
2020-10-4 03:32:03

i could very easily swap this out with json which has a lot more work put into rust serialization and deserialization libs but ill mucking everything to s-expressions for consistency since the scripting language for my game will probably try to integrate racket or some scheme