I can't be disagree with that! :-)
But I'm confused with the fact that in the result, clear, functional, human-readable phrase is need to be transformed to complex algorithm with tricks, that doesn't ports any useful functionality.
I.e., in my example, we need to use "let", temp. variable, "if", a bunch of parantehisis ony for simply signalling that "nil" will be ok here. Also we got a visually broken calculations order.
It would be cool to have more lightweight trick here, I think.
What do I want - is to save functional way in some code where now I must use algorithmic tricks.
Frequently I meet situation where this can be done by allowing inner functions to break execution flow of next outer one.
Sort of "near" throw w/o catch.
Consider function "break", working as follows:
(break expr1 expr2)
If the result of expr1 is not nil it is returned.
Else expr2 is evaluated and it's result is returned _instead_ of next outer function.
If expr2 is missing, nil is returned.
Simple example:
Code: Select all
(parse (break (lookup "key" some-list 1)) "delimiter")
This solution:
- still requiring explicit care about nil appearance.
- has functional style that keeping clear readability
- often allowing to eliminate temp. variables