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.