
Hey, my company bought a couple extra diversity tickets for racketfest, if you know anyone who’s in an underrepresented group and would be interested, please have them reach out!

@earl Awesome. Have you tweetted about it?

@pocmatos not yet, I have all of ~300 twitter followers so not sure it’s going to move the needle a ton.

but it will allow others to retweet you. :slightly_smiling_face: Not that I have that many followers myself though.


If you do follow me, you can get my best take on Amsterdam, Scala, running an Agtech startup in the developing world… and customer service issues and complaining about american politics which is what I really use it for.

Anyone who’s going to racketfest in berlin interested in doing a long bike ride on Sunday?

@n.huu.long has joined the channel

Is there any difference between stx->list
and syntax->list
? The documentation seems to imply that stx->list
uses syntax->list
, but it seems to be identical on all inputs I tried so far

@sorawee stx->list
has a much bigger domain: > (stx->list (list 1 2 3))
'(1 2 3)
> (syntax->list (list 1 2 3))
; syntax->list: contract violation
; expected: syntax?
; given: '(1 2 3)
; [,bt for context]

Ah, I see

Thanks

Perhaps the examples at https://docs.racket-lang.org/syntax/syntax-helpers.html#%28def._%28%28lib._syntax%2Fstx..rkt%29._stx-list~3f%29%29 should include a list that doesn’t have any syntax object inside?

It also includes things that are neither proper lists nor syntax objects, but chains of cons
pairs that might have syntax-lists in the rest
instead of normal lists: > (stx->list (cons 1 (cons 2 #'(5 3))))
'(1 2 #<syntax 5> #<syntax 3>)
> (syntax->list (cons 1 (cons 2 #'(5 3))))
syntax->list: contract violation
expected: syntax?
given: '(1 2 . #<syntax (5 3)>)

Does anyone know if there is a package for doing transactions (NOT database transactions)?

@pocmatos can you change the gitlab notifications to not email me? and even better, to post to the #notifications channel here?

@samth Sure. I am out today but will do that today as soon as I return.

@mark.warren like, transactions in the sense of software transactional memory (STM)?

Good heavens: #lang racket
(define (println/c v)
(make-contract
#:projection (λ (blame) (λ (val) (println v) val))))
(define/contract foo%
(class/c (override [m (println/c #f)]))
(class object%
(super-new)
(define/public (m) #f)))
(define/contract foo+c1%
(class/c (override [m (println/c 1)]))
foo%)
(define/contract foo+c2%
(class/c (override [m (println/c 2)]))
foo%)
(class foo+c2%
(super-new)
(define/override (m) #f))
outputs 2
1
#f
#<class:/tmp/test.rkt:21:0>
:scream:


Is it bad for me to prefer (for ([_ (in-producer void)])
__)
over (let id ()
_
(id))
or the equivalent (define (id)
_
(id))
?

Is there some other idiom for “forever” that is too clever for its own good? :grin:

So you want a for-ever
! :wink:

… and corresponding for*/ever

The documentation says that define-struct
is deprecated and struct
is more preferable. However, there’s only define-struct/contract
and no struct/contract
. Is define-struct/contract
considered deprecated too? And what should we use instead?

(I’m aware of contract-out
with struct/c
, but that’s not what I want to do)

@sorawee I’ve wondered the same thing, then just used define-struct/contract
, assuming it hadn’t been worth getting around to renaming or aliasing that, yet.

@sorawee If you want to be able to protect your struct inside a module, you could define the struct inside a sub module then provide the struct bindings via contract-out
and struct/c
so they’re protected and available for use in the parent module.

There’s a thing called struct-guard/c
on HEAD that will be in 7.3 that might be interesting to you.

It lets you write this: > (struct snake (weight hungry?)
#:guard (struct-guard/c real? boolean?))
> (snake 1.5 "yep")
snake, field 2: contract violation
expected: boolean?
given: "yep"
in: boolean?
contract from: top-level
blaming: top-level
(assuming the contract is correct)
at: eval:2.0

I’ve also done (module foo typed/racket/base __)
and a TR struct b/c I prefer its syntax ¯_(ツ)_/¯

I meant that in response to @abmclin, another variation on defining the struct in a submod. I didn’t mean I prefer this to what @lexi.lambda suggested; I’d never heard of that until now. :smile:

It’s very new! It isn’t even in 7.2.

Robby added it about a month ago.

That looks very nice! I’m looking forward to 7.3

It is in a nightly build I believe.

Feedback is easier to respond to before it gets into a release. :)

So comparing things, I’m guessing the #:guard (struct-guard/c __)
approach is only checking contracts when updating the struct — not when reading it. (Which if that’s the case, is either a drawback or a huge perf advantage, depending on what you want.) ?

It guards the constructor. Doesn’t work for mutable struct

S

Is struct-guard/c
only available in racket/contract
and racket
?

If you use immutable structs, struct-guard/c
is the safest way to enforce things

I meant, with define-struct/contract
, I thought the contract is applied/checked even when using read accessors. No?

@greg I don’t know, but for immutable structs you probably don’t want to check the reads anyway

That’s why I thought, “Oh, maybe part of the motivation for struct-guard/c
was it intentionally only guards the construction, not the read accesses, as contrasted with d-s/c
.” Just curious.

@greg out of curiosity, what sort of places do you usually find yourself using mutable structs?

Almost never.

I don’t like mutability. And when I have to use it, the struct setters are super verbose and it’s usually easier to set!
local variables in a closure.

I’m looking forward to using struct-guard/c
!

@mflatt what guarantee does Racket give when I mess with current-compile
? In particular, my buggy code results in the following error:
hash-ref: no value found for key
key: 'foo
context...:
compile-identifier22
compile5
[repeats 1 more time]
compile-let13
compile5
[repeats 4 more times]
compile-let13
compile5
[repeats 5 more times]
for-loop
compile-let13
compile5
for-loop
loop!
compile-forms33
compile-module-from-parsed34
...
Is this considered a Racket bug? Or all bets are off when I mess with the compiler?