<klf>
What is the Racket eqivalent to a Python 'None', if there is one at all?
<winny>
#f usually indicates an absence of data
<winny>
In python functions return None if no explicit return is used, in Racket this is `(void)`, which is kind of different, though also indicates an absence of data or useful result
<winny>
https://docs.racket-lang.org/guide/void_undefined.html (there's a section on boolean but doesn't seem to discuss the semantics of how most racket programs use #f, I remember in scheme r5rs there is a nice description of the intended behavior.)
<winny>
"Of all the standard Scheme values, only #f counts as false in conditional expressions. Except for #f, all standard Scheme values, including #t, pairs, the empty list, symbols, numbers, strings, vectors, and procedures, count as true." <- in this way None and False are usually collapsed into the same value in Racket https://schemers.org/Documents/Standards/R5RS/HTML/
johnjaye has quit [Remote host closed the connection]
klf has quit [Remote host closed the connection]
s-liao has joined #racket
m5zs7k has quit [Ping timeout: 272 seconds]
m5zs7k has joined #racket
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 240 seconds]
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 250 seconds]
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 256 seconds]
s-liao has quit [Quit: Client closed]
notzmv has quit [Ping timeout: 240 seconds]
s-liao has joined #racket
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 256 seconds]
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 272 seconds]
johnjaye has joined #racket
notzmv has joined #racket
johnjaye has quit [Ping timeout: 256 seconds]
s-liao has quit [Ping timeout: 256 seconds]
codingquark has quit [Read error: Connection reset by peer]
codingquark has joined #racket
codingquark has quit [Ping timeout: 240 seconds]
capfredf has joined #racket
codingquark has joined #racket
capfredf has quit [Ping timeout: 240 seconds]
cynomys has quit [Ping timeout: 250 seconds]
codingquark has quit [Read error: Connection reset by peer]
codingquark has joined #racket
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 256 seconds]
s-liao has joined #racket
capfredf has joined #racket
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 240 seconds]
johnjaye has joined #racket
johnjaye has quit [Remote host closed the connection]
badkins has joined #racket
s-liao has quit [Quit: Client closed]
badkins has quit [Ping timeout: 250 seconds]
badkins has joined #racket
s-liao has joined #racket
<undltd>
`none` would be easy to add - `(struct none)` and basically it
<undltd>
* `(struct none (), * ))` and
<bremner>
what advantages over just using a symbol would that bring?
badkins has quit [Ping timeout: 256 seconds]
<undltd>
bremner: things like a `none?` test
<bremner>
right, makes sense, thanks
<undltd>
but yeah, I think I underappreciate symbols:)
<undltd>
coming from Python
<bremner>
I think winny's suggestion of using #f is probably good, even if unpythonic. In particular people probably expect "None" to be "falsy"
<bremner>
if using one of typed variants, there are option types, which are a cleaner alternative
<bremner>
hmm. I only find "optionof" in plait / plait-typed. Those are mainly used in PL courses I suspect.
<undltd>
yeah, I actually find the only-#f-is-false approach cleaner
<undltd>
It's only when I need to distinguish #f as a valid value from a lack of value when I start to think of none
<undltd>
So a symbol might do, or `unsupplied-arg`
<bremner>
exceptions are an option, as is returning a Maybe style struct
<bremner>
I'm not sure what the idiomatic racket things to do is
casmajavi has joined #racket
<undltd>
Yeah it's that there doesn't seem to be a common style / tradition for it
thrilway has quit [Read error: Connection reset by peer]
thrilway has joined #racket
<bremner>
I guess returning a list of zero or more values is a simple option. then '() plays the role of None
<bremner>
It feels a bit overengineered for 0 or 1 values.
morte_ has joined #racket
s-liao has quit [Quit: Client closed]
badkins has joined #racket
capfredf has quit [Remote host closed the connection]
capfredf has joined #racket
capfredf has quit [Remote host closed the connection]
capfredf has joined #racket
capfredf has quit [Ping timeout: 240 seconds]
johnjaye has joined #racket
<winny>
Let's consider a use case where a boolean result is needed in addition to no data. That's a ternary (three valued boolean) result, not sure if you want that in your api?
<winny>
In python are there some standard library examples that use both None and False as a return value?
<samth>
Usually #f is the standard approach. In cases where that's potentially ambigious, a common option is to provide a callback for the "missing" case.
johnjaye has quit [Ping timeout: 256 seconds]
<winny>
dict.get might be one example, but one has to know what the dict contents look like, a value could contain None anyways, hence it's not completely unambiguous
<bremner>
samth: do you have an example handy of the callback approach?
<samth>
bremner: the interface for `hash-ref`
johnjaye has joined #racket
<bremner>
ah, gotcha. What it calls failure-result
<bremner>
and indeed it is a callback in the conventional sense
<bremner>
I have just only used non-procedures there
johnjaye has quit [Ping timeout: 245 seconds]
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 245 seconds]
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 240 seconds]
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 240 seconds]
capfredf has joined #racket
johnjaye has joined #racket
capfredf has quit [Remote host closed the connection]
capfredf has joined #racket
johnjaye has quit [Ping timeout: 250 seconds]
johnjaye has joined #racket
capfredf has quit [Ping timeout: 240 seconds]
johnjaye has quit [Ping timeout: 240 seconds]
johnjaye has joined #racket
skapata has joined #racket
skapata has joined #racket
skapata has quit [Changing host]
johnjaye has quit [Ping timeout: 260 seconds]
badkins has quit [Remote host closed the connection]
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 240 seconds]
badkins has joined #racket
johnjaye has joined #racket
badkins has quit [Ping timeout: 240 seconds]
johnjaye has quit [Ping timeout: 240 seconds]
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 250 seconds]
johnjaye has joined #racket
johnjaye has quit [Remote host closed the connection]
johnjaye has joined #racket
johnjaye has quit [Max SendQ exceeded]
johnjaye has joined #racket
johnjaye has quit [Ping timeout: 240 seconds]
johnjaye has joined #racket
johnjaye has quit [Max SendQ exceeded]
johnjaye has joined #racket
badkins_ has joined #racket
badkins_ has quit [Remote host closed the connection]
johnjaye has quit [Max SendQ exceeded]
johnjaye has joined #racket
johnjaye has quit [Max SendQ exceeded]
johnjaye has joined #racket
johnjaye has quit [Max SendQ exceeded]
johnjaye has joined #racket
badkins has joined #racket
badkins has quit [Remote host closed the connection]
capfredf has joined #racket
ec has joined #racket
morte_ has quit [Ping timeout: 240 seconds]
capfredf has quit [Remote host closed the connection]
capfredf has joined #racket
morte_ has joined #racket
badkins has joined #racket
capfredf has quit [Ping timeout: 256 seconds]
badkins has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Remote host closed the connection]
skapata has quit [Ping timeout: 250 seconds]
skapata has joined #racket
badkins has joined #racket
badkins_ has joined #racket
badkins has quit [Ping timeout: 256 seconds]
badkins_ has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Remote host closed the connection]
capfredf has joined #racket
badkins has joined #racket
capfredf has quit [Ping timeout: 252 seconds]
badkins has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Remote host closed the connection]
morte_ has quit [Ping timeout: 250 seconds]
badkins has joined #racket
Codaraxis has joined #racket
badkins has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Remote host closed the connection]
morte_ has joined #racket
Nselm has joined #racket
badkins has joined #racket
Nselm has quit [Quit: Client closed]
skapata has quit [Ping timeout: 240 seconds]
skapata has joined #racket
kenran has joined #racket
ur5us has joined #racket
badkins has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Remote host closed the connection]
badkins has joined #racket
monkey_ has joined #racket
capfredf has joined #racket
capfredf has quit [Remote host closed the connection]
capfredf has joined #racket
badkins has quit [Remote host closed the connection]
badkins has joined #racket
capfredf has quit [Ping timeout: 240 seconds]
badkins has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Ping timeout: 240 seconds]
monkey_ has quit [Remote host closed the connection]
kenran has quit [Quit: WeeChat info:version]
monkey_ has joined #racket
_patrice has joined #racket
cynomys has joined #racket
casmajavi has quit [Remote host closed the connection]
rgherdt has joined #racket
cynomys has quit [Quit: Lost terminal]
cynomys has joined #racket
badkins has joined #racket
monkey_ has quit [Ping timeout: 240 seconds]
morte_ has quit [Read error: Connection reset by peer]
evdubs_ is now known as evdubs
capfredf has joined #racket
monkey_ has joined #racket
_patrice has quit [Ping timeout: 272 seconds]
capfredf has quit [Remote host closed the connection]