kyp0717
2021-6-30 14:03:55

Hi all. It seems that the following let binding syntax are the same. (let ([x 5] x)) ;; uses square brackets to bind variable (let ((x 5)) x) ;; uses parantheses to bind variable


kyp0717
2021-6-30 14:04:08


massung
2021-6-30 14:04:45

square brackets == parentheses. It’s just something people use to visually key different parts of code in their own way


massung
2021-6-30 14:04:55

They aren’t syntactically different like in clojure


soegaard2
2021-6-30 14:05:23

Yes. In standard Racket (), [] and {} mean the same.


massung
2021-6-30 14:05:36

For example [define x 10] is just fine


kyp0717
2021-6-30 14:05:37

Oh wow!! I did not know that.


soegaard2
2021-6-30 14:05:52

Usually [] is used to indicate pairings such as in let and in cond.


kyp0717
2021-6-30 14:05:55

It threw me off for a while there!


soegaard2
2021-6-30 14:06:08

The () is used to group a sequence of pairings.


soegaard2
2021-6-30 14:06:13

But, just a convention.


kyp0717
2021-6-30 14:06:38

But in racket, you create a vector with [ … ] correct?


massung
2021-6-30 14:06:58

no. #(1 2 3) is a vector


massung
2021-6-30 14:09:19

I usually use [ to indicate… non-evaluated forms or pairs. For example:

(match thing [(list x xs ...) x] [_ 'foo]) The [ pairs the pattern with the result and the car of the pair isn’t a function call. While anywhere I use ( I can assume the head item is applied.


massung
2021-6-30 14:10:22

That’s just me, though. Everyone likely has their own brand of how they use them. In the end, though, as @soegaard2 said, they’re all the same.


soegaard2
2021-6-30 14:14:11

Yeah, create a new vector with vector make-vector for/vector or use a vector literal #(1 2 3) . Literals are only created once, so beware of mutating them.


kyp0717
2021-6-30 14:19:06

Thanks all. These explanations have helped a lot!


greg
2021-6-30 14:32:47

Keep in mind that’s all true for #lang racket and most “normal” langs, as well as most macros.

But Racket does let a lang or macro distinguish the delimiters if it wants to. One example is #lang scribble where [] and {} are distinguished.

So the TLDR is definitely, yes, by default they mean the same. And it’s a convention or personal choice which to use, where. (But someday you might use or create a macro or lang where they’re not the same.)


jeremy.german
2021-6-30 18:58:58

@jeremy.german has joined the channel


joel
2021-7-1 01:35:37

Is there a special provide form for generic struct interfaces? Or would I need to use all-defined-out?


samth
2021-7-1 01:48:52

I guess I’d just list the methods.


samth
2021-7-1 01:49:11

But there is not something like struct-out for generics. Although it would be reasonable to write one.