2,337 karma · joined Jun 25, 2011 (15y ago) · 1,518 submissions
comment 9y ago · link · parent
(let-every [x (foo) err "foo failed"
y (bar x) err (format "bar %s failed" x)
z (goo x y) err (format "goo %s %s failed" x y)]
(qux x y z)
(handle-error err))
Where `let-every` is a macro that works like let, but stops short on the first nil/false variable, runs only the next symbol binding expression, and then runs the else-clause.There'd be nothing special about the "err" symbol on each line. It's just the next symbol binding, but on the same line as a convenience, and this means it can reference any previously valid symbol bindings.
Here's a quick & dirty implementation of that macro. I don't have a Clojure interpreter installed, so I don't know if it works.
(defmacro let-every [bindings if-body else-body]
(let [pairs (partition 2 bindings)
quad-pairs (partition 2 pairs)]
(loop [quad-pairs quad-pairs]
(if quad-pairs
(let [[quad-pair] quad-pairs
[try-pair err-pair] quad-pair
[try-sym try-expr] try-pair
[err-sym err-expr] err-pair]
`(if-let [~try-sym ~try-expr]
(recur (next quad-pairs))
`(let [~err-sym ~err-expr]
~else-body)))
if-body))))
Given the above example, it should expand to this: (if-let [x (foo)]
(if-let [y (bar x)]
(if-let [z (goo x y)]
(qux x y z)
(let [err (format "goo %s %s failed" x y)]
(handle-error err)))
(let [err (format "bar %s failed" x)]
(handle-error err)))
(let [err "foo failed"]
(handle-error err)))comment 9y ago · link · parent
comment 9y ago · link · parent
And without even needing to install anything! "Processing maliciously crafted web content may lead to arbitrary code execution."
comment 9y ago · link · parent
comment 9y ago · link · parent
Let that be a warning to everyone here, never to post comments or links the HN mods do not approve of. Their vengeance is moderate and permanent.
comment 9y ago · link · parent
Very imaginative and sci-fi, but not likely. Just because we've advanced this fast in the past 50 years doesn't mean we'll be able to keep this rate up. There are physical limits to the things we can do, even if we keep gaining knowledge at the same speed. We'd have to break a lot of very big scientific barriers before any such technology would be both practical and affordable.
comment 9y ago · link · parent
// This was useful in C to avoid accidentally
// typing variable = null. These days it will
// confuse most people, with little benefit.
The use of "was" and "these days" in the link shows that the author of this piece is in a tiny little bubble of development, and is far from being able to give general advice for programming. C is not past-tense. C, C++, Objective-C, these are all still widely used today by modern professionals. I'm very tired of articles and authors which claim to be representative of all programming or programmers, when they're isolated to a tiny little bubble. Especially when they only know JavaScript.comment 9y ago · link · parent