505 karma · joined June 22, 2010
Here's a small summary about the numbers with many examples: https://www.unicode.org/L2/L2020/20290-cistercian-digits.pdf
lst.lazy.grep(Array).flat_map(&:itself).sum
Not as clear, because the standard library doesn't have a `#flatten` method for lazy enumerators.But the point is the interface, not the implementation. Efficiency doesn't mandate assembly-like DSLs. Your interface could be as clear and clean as Ruby's and produce fast, inlined code by the power of macros. Ruby doesn't have macros, so chaining lambdas is the best it can do.
Ruby also has call/cc. None of the iterating methods has any provision to make them "safe" from it. They aren't safe from modifications to the iterated collection either. I think it makes sense; being forced to accumulate using only linked lists and having to be constantly on guard to support a rarely used quirky feature is a bad tradeoff IMO.
Like the example you showcase your macro with. In Ruby it would be:
lst = [[1, 2], :dud, [3, 4], [5, 6]]
lst.grep(Array).flatten.sum
=> 21
You can see what it does at a glance, you don't have to immerse yourself inside the directives to follow the logic. And when you can't do that, declaring iterators and accumulators outside a loop and then iterating and accumulating "by hand" yields code not so different than your more complex examples. def partition (arr)
yes = []
no = []
arr.each do |elt|
if yield elt
yes << elt
else
no << elt
end
end
[yes, no]
endHere's an account: https://www.huffpost.com/entry/wash-post-busted-pressmens-un...
With immutable strings literals, string literals can be reused.
Obviously he's not serious, he's playing the part of the out of touch old man.
I think CSV or TSV are good enough. People keep trying to find a format where you can separate the records and fields with a simple string.split and there's no need to contemplate escapes.
But that's not possible, no matter the format you'll have to parse it right. And then, a format that uses visual delimiters has the obvious advantage of being editable with any text editor.