That's not considered good practice in Lisp either. One would use a
lambda expression to delay the computation, as others have suggested.
You might be able to arrange your program so that tryAppend is called
with the error-raising function and its arguments separately. I mean
like this:
def r(x):
if x > 3:
raise(ValueError)
return x
def tryAppendDecorator(fn):
def new(xs, f, *args):
try:
fn(xs, f(*args))
except:
pass
return new
@tryAppendDecorator
def tryAppend(items, item):
items.append(item)
sub3 = []
tryAppend(sub3, r, 3)
tryAppend(sub3, r, 1)
tryAppend(sub3, r, 4)
tryAppend(sub3, r, 1)
tryAppend(sub3, r, 5)
Maybe you should only ignore some specific type of exception, like
ValueError if you are specifically using r as a filter whose task it
is to raise a ValueError.