|
|
|
|
|
by ANTSANTS
4441 days ago
|
|
>Also I have made use of improper lists in my code, usually when I need to do something with multiple values and I don't want to mess with multiple return values, or if I just want to create a list of tuples for some reason and don't feel like defining an actual struct (can't think of a good example right now...) I get what you're saying, but isn't this just a shortcoming of the language? It's pretty common to want to write something like (define (string-lookup-that-might-fail)
(if (random) <"string you were trying to look up" nil> <nil "It wasn't there.">))
(define <some-string error-msg> (string-lookup-that-might-fail))
without wanting to destructure a list or use the call-values hack. That's a bad example, just pretend there were multiple reasons the lookup could fail.I totally agree about there being pedagogical value in having a simple core. I'm torn between appreciating minimalism and believing that it's ok to introduce complexity to a language that people will use to get things done every day, so long as it's useful complexity and not just historical accident. |
|
So I think that is actually a good argument for introducing option types (like Haskell's Either a b) into the language. I think Typed Racket has something like this, but in either case you'd want some nice syntax to handle it as well.
Hash tables make this sort of thing fairly easy though (at least in Racket)
(define h #hash{["a" . 3] ["b" . 5]})
(hash-ref h k "failed")
I think most lisps support this right? I remember seeing something similar in pg's bayesian spam filter code.