4 ms·
One is a function, one is a call to that function. I think this is just hard to grasp because in other languages there's often not occasion to use a function po
by lgessler 7y ago
One is a function, one is a call to that function. I think this is just hard to grasp because in other languages there's often not occasion to use a function pointer. But compare these two code snippets in Python and Scheme:
>>> def add_one(x):
... return x + 1
...
>>> add_one
<function add_one at 0x7f7504bf2050>
>>> add_one(1)
2
>>> list(map(add_one, [1,2,3]))
[2, 3, 4]
That's the same as:
=> (define (add-one x)
(+ x 1))
add-one
=> add-one
#[compound-procedure add-one]
=> (add-one 1)
2
1 ]=> (map add-one (list 1 2 3))
(2 3 4)