4 ms·
It's a trivial example and I wouldn't focus on it too much. It's not that peculiar -- instead of parsing the same character twice you simply return the value t
by agentultra 13y ago
It's a trivial example and I wouldn't focus on it too much.
It's not that peculiar -- instead of parsing the same character twice you simply return the value that you parsed or None. My inspiration was from the CLHS predicate function, DIGIT-CHAR-P [0].
The real point I was making is that Python has warts that make writing idiomatic code impractical in some situations. I suggest that practicality take precedence over purity. There are some situations that lead to non-idiomatic code and that's okay.
[0] http://clhs.lisp.se/Body/f_digi_1.htm http://clhs.lisp.se/Body/f_digi_1.htm
Update: forgot the link. :)
Update update: Perhaps peculiar to Python because all values of integers are not False except for 0 whereas in another language that doesn't have this wart, anything that isn't False is True... even 0. In other words, anything that isn't False is True. :D
- masklinn 13y ago> In other words, anything that isn't False is True. :D Except for `nil` (lisps, ruby), and possibly a host of other things depending on the language (empty strings in javascript).
- agentultra 13y agoScheme is the only PL I know that has an explicit #f value. CL, for all intents and purposes, treats nil as False... but some find the conflation of nil and the empty list runs into the same issue when operating on s-exprs. CL-USER> (if '() 1 0) 0 vs scheme> (if '() 1 0) 1
- aiiane 13y agoWhat is a "wart" is subjective. C-like languages also have this "wart" and it's used to great effect, enabling different idioms that would be messier without it.