2 ms·
I hate to be the guy who's always saying the same thing but, that is easy in python. dx = 0.00001 def deriv(f): return lambda x: \ (f(x
by sharkbrainguy 18y ago
I hate to be the guy who's always saying the same thing but, that is easy in python.
dx = 0.00001
def deriv(f):
return lambda x: \
(f(x + dx) - f(x))/dx
In [11]: def cube(x):
....: return x*x*x
....:
In [12]: deriv(cube)(5)
Out[12]: 75.000149996640175
I'd also so that most (high school) educated people find infix easier to read than prefix, so isn't the homoiconicity a detriment to readability in this example (and any involving mid sized arithmetic expressions).
I love scheme (alot more than I do python), but the only example that seems "impossible" to do is to implement a large subset of <language> in <language>.
You could obviously implement, a scheme-ish lisp in python, but there are alot of advantages to the host and guest languages being similar (or so that berkley professor would have me believe) that you would miss out on.
(You would also need a scheme expression reader in python... which I'm just itching to write now ... )
the example is from sicp: http://tinyurl.com/cubk49 http://tinyurl.com/cubk49