thanks for the perspective, @soegaard2
This is an interesting thread to read. It actually brings up an interesting philosophical question: to what extent should we change our programming style to allow abstractions that could enable better optimizations
I think the reason I feel weird about it is that multiple return values do not feel very structural in the language. And I do not like it when my language requires me to work with something that doesn’t feel structural in the same way as I could do with (say) an s-expression.
My personal take on this is that we should just use lists and have powerful static analyses that can detect idioms like multiple return values and optimize them
if the concern is over expressivity or style, I think I prefer @notjack’s suggestion, although maybe if I really wanted to go all the way I’d define my own piece of syntax for this via a macro, however, I’d like to clarify that I think there are two orthogonal problems here: one of expressivity and one of optimization hints. I am much more sympathetic to the first goal than the second.
(define-values (qutient remainder) (integer-division 13 5))
What’s not clear?! :stuck_out_tongue_winking_eye:
The error message of this: (define result (integer-division 13 5))
@soegaard2 honest answer is that I mostly try to avoid defines and prefer matches, so having to use define-values
feels a bit kludgey because it forces me to use define
also, define-values
just feels a bit special and inconsistent for something like this.
but I don’t think it’s bad, per-se.
You are in luck. There is a match-values :slightly_smiling_face:
I actually did not know about that, and maybe it would make me change my opinion :slightly_smiling_face:
I see your point though - most contexts expect a single value to be returned.
@krismicinski Do you use match-define
?
This might be an ill-formed question but does Racket have “reference” types?
Like a reference to a cell for cons, rather than the value
@slack1 There’s box
, which sounds sort of like what you want
Is that what someone might use to pass around references when writing data structures for learning?
Yes, I think it could work for that