tonyg changed the topic of #racket to: The Racket Programming Language -- https://racket-lang.org/ -- https://gather.town/app/wH1EDG3McffLjrs0/racket-users -- http://pasterack.org -- logged at https://libera.irclog.whitequark.org/racket/ -- This is the right place to ask for help with (Dr)Racket. Remember to wait around for an answer!
badkins has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Ping timeout: 255 seconds]
badkins has joined #racket
morte_ has joined #racket
morte_ has quit [Ping timeout: 246 seconds]
badkins has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Ping timeout: 255 seconds]
sagax has quit [Excess Flood]
ur5us has quit [Ping timeout: 246 seconds]
cky has quit [Ping timeout: 252 seconds]
ttree has quit [Ping timeout: 246 seconds]
cky has joined #racket
skapata has quit [Remote host closed the connection]
sxn has joined #racket
sxn has quit [Remote host closed the connection]
sxn has joined #racket
ec has quit [Remote host closed the connection]
ec has joined #racket
ns12 has quit [Quit: bye]
ns12 has joined #racket
sxn has quit [Ping timeout: 246 seconds]
badkins has joined #racket
sxn has joined #racket
avocadoist has quit [Ping timeout: 255 seconds]
szkl has joined #racket
msiism has joined #racket
jeosol has joined #racket
avocadoist has joined #racket
badkins has quit [Remote host closed the connection]
morte_ has joined #racket
<msiism> I have a module that handles some date-related tasks. In that module, there's a helper function `valid-year?` testing whether a given number represents a valid year.
<msiism> Now, I wonder which of two ways is the best to implement it.
<msiism> The reason is that while any natural number is a valid year number, the module only handles years 1000..9999 in order not to collide with ISO date format.
<msiism> That means, things can fail two ways.
<msiism> I'd like to indicate the exact reason of failure in the error the function returns, but this makes things really complicated.
<msiism> Err, well, the function itself does not return an error message, actually.
<msiism> Anyway, this is how I'd implement it if I wanted to be able to tell exactly why a given number is not a valid year: http://paste.debian.net/plainh/9144b1ee
<msiism> This is a bit of a pain to use, though.
<msiism> Just returning #t or #f would be way less complex.
<msiism> I mean, it would make that function an easy-to-use one-liner.
badkins has joined #racket
<samth> msiism: a few suggestions:
<samth> 1. write `validate-year` which returns a number or raises an exception
<samth> 2. write `validate-year` but return a number or a an error message
<samth> 3. write `valid-year?` which returns `#t` or a symbol for the error reason
<samth> 4. write `check-year` which returns void or raises an exception
<samth> 5. write `invalid-year?` which returns `#f` or a symbol (easy to use with `if`)
<msiism> Oh, cool.
<msiism> I had already thought baout 3. But I didn't like it returning different types of values depnding on what happens.
<msiism> I think I like 4. best.
<msiism> Also, thanks for reminding me about some syntax conventions.
<msiism> I shouldn't be putting a `?` at the end of a fcuntion name if it returns anything but #t or #f.
<msiism> Why is 4. called `check-year`, though, not `validate-year`? I mean, check is shorter anyway. But I'm still curious.
<samth> msiism: I think returning a value that you test for truthiness it's ok for it to use `?`
sxn has quit [Quit: sxn]
sxn has joined #racket
skapata has joined #racket
<msiism> I see.
sxn has quit [Ping timeout: 255 seconds]
sxn has joined #racket
badkins has quit [Remote host closed the connection]
sxn has quit [Ping timeout: 255 seconds]
jeosol has quit [Quit: Client closed]
badkins has joined #racket
sxn 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
sxn has quit [Ping timeout: 248 seconds]
morte_ has quit [Read error: Connection reset by peer]
morte_ has joined #racket
<msiism> I also wonder whether returning either #t or #f and raising an exception otherwise would be a viable solution.
<msiism> I mean, it does appear a bit weird. But I'm not sure why.
morte_ has quit [Ping timeout: 246 seconds]
morte_ has joined #racket
morte_ has quit [Ping timeout: 246 seconds]
<msiism> I've implemented year and month checks for my `days-in-month` function, using the `check-date` approach: http://paste.debian.net/plainh/427bcf47
<msiism> Seems good to me.
<dzoe> msiism: remember that non-#f values are effectively treated as #t in conditions
<dzoe> msiism: So returning number or #f is actually pretty common pattern if you want to handle it in the immediately surrounding code
<msiism> I see.
<dzoe> My contracted code contains a lot of (or/c fixnum? #f) ;-)
<msiism> One of my main concern here was/is not having to write write the code for raising the exceptions over and over again.
<msiism> I kind of struggled with returning a number or error message/exception simply because I wasn't sure what number to choose.
<msiism> 1 would probably have been a good choice.
badkins has quit [Remote host closed the connection]
sxn has joined #racket
sxn has quit [Ping timeout: 248 seconds]
ur5us has joined #racket
morte_ has joined #racket
sxn has joined #racket
sxn has quit [Ping timeout: 252 seconds]
badkins has joined #racket
badkins has quit [Ping timeout: 248 seconds]
morte_ has quit [Ping timeout: 255 seconds]
morte_ has joined #racket
sxn has joined #racket
sxn has quit [Ping timeout: 248 seconds]
msiism has quit [Quit: Konversation vaporized.]
dbohdan has quit [Quit: ZNC 1.8.2+deb2+b1 - https://znc.in]
dbohdan has joined #racket
morte_ has quit [Remote host closed the connection]
avocadoist has quit [Read error: Connection reset by peer]
szkl has quit [Quit: Connection closed for inactivity]
avocadoist has joined #racket
sxn has joined #racket
sxn has quit [Ping timeout: 248 seconds]
avocadoist has quit [Remote host closed the connection]
avocadoist has joined #racket
jeosol has joined #racket
badkins 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
badkins has quit [Ping timeout: 260 seconds]