4 ms·
It is not a direct implementation, and may end up being clunky, but I expect a fairly small library of helper functions could improve ergonomics quite a bit: D
by greggyb 4y ago
It is not a direct implementation, and may end up being clunky, but I expect a fairly small library of helper functions could improve ergonomics quite a bit:
Define your booleans as functions of no args. A sample in Python:
var = 'abc'
var_contains_a = lambda: 'a' in var
var_shorter_than_5 = lambda: len(var) < 5
if var_contains_a() and var_shorter_than_5():
print(var)
- deleted 4y ago[deleted]
- greggyb 4y agoOne challenge with the chosen example language, Python, is that functions are truthy. So if you forget to call the function that computes your boolean test, you end up with a default true. Taking the last top-level statement, the `if`: if var_contains_a() and var_shorter_than_5: #note the lack of parens for the second print(var) This will print a string of any length that contains 'a' (or any other collection that implements `in` and does, in fact, contain an element, 'a'). The second function is passed directly as a boolean expression, and being a function, it resolves to true.