Arc Forumnew | comments | leaders | submitlogin
2 points by eds 6123 days ago | link | parent

> > There's still this logical distinction between creating an anonymous function and assigning it to a variable, and I don't think merging 'def and 'fn captures this distinction.

> (fn name (arg) ...) and (fn (arg) ...) seem pretty distinct to me

Think about the difference between (car x) and (scar x). Those are two distinct cases (assignment and retrieval), we wouldn't want to create a single 'car function that would do assignment if given an optional parameter.

  (_car x)   =>  (car x)
  (_car x y) =>  (scar x y)
Because these are two entirely different concepts. Similarly the assignment of a function to a variable is distinct from creating that function. In my opinion, merely creating an optional parameter for it in 'fn doesn't capture that distinction.

> if fn is being used in a local context they probably won't need to give it a name

Then why do 'afn and 'rfn exist?

> fn and afn are substantially different in that the variable environments of their evaluated bodies are different

And thus 'fn and 'def are different in that 'fn creates no binding and 'def creates a global binding.



2 points by tokipin 6123 days ago | link

fn and def both create functions. in one case we donate money. in the other we donate money and get a star with our name on it. in both cases we've donated money. car vs scar would be like donating money vs robbing a bank

>> if fn is being used in a local context they probably won't need to give it a name

> Then why do 'afn and 'rfn exist?

to create self-referencing functions

> And thus 'fn and 'def are different in that 'fn creates no binding and 'def creates a global binding.

yes, and afn can create a different class of functions from fn. almkglor had a good point about requiring gymnastics in some cases with a God Fn. those sorts of issues wouldn't happen with (fn,def) -> fn and (afn,rfn) -> afn, except for the full vararg thing

if we use software structure/logic as the only metric, sure, they're all very different, but then we'll lose sight of the way the end user sees all these things

-----

2 points by eds 6122 days ago | link

> fn and def both create functions. in one case we donate money. in the other we donate money and get a star with our name on it.

No, the star gets permanently placed in the floor of the quad outside the central office. As opposed to 'afn and 'rfn where we get to keep the star.

Admittedly my 'car and 'scar example wasn't accurate. Let me try again. Say we have a version of 'table called 'ntable that is just like table except it assigns the new table to a global variable. Now suppose we redefine 'table to take an optional parameter, in which case it acts like 'ntable. But all this does is confuse the purpose of 'table, which is to create a table, and 'ntable which creates a table in the global namespace. The overloading here doesn't help shorten or clarify code. So we remove one function from the global namespace. So what?

Unlike in real life, the presence or absence of the star really does matter here, enough that the two shouldn't be condensed into a single operation.

>>> if fn is being used in a local context they probably won't need to give it a name

>> Then why do 'afn and 'rfn exist?

> to create self-referencing functions

Exactly! So you can use the function in more places than just the return value. 'def is similar in that the name allows it to be referenced elsewhere (or inside the definition), and this is totally different from the one-shot usage that 'fn gets most of the time.

> if we use software structure/logic as the only metric, sure, they're all very different, but then we'll lose sight of the way the end user sees all these things

I think we are making very different assumptions about the way the user thinks about 'fn and 'def. When I see 'fn, I think local/anonymous function. When I see 'def on the other hand, I think global/named function (and yes, where the name goes is an important issue, even to an end user). I don't think it is a simplification of this model to merge the two operations.

-----

1 point by tokipin 6122 days ago | link

when i see fn, i see "fundamental function-creating function." i see def as "(= name (fundamental function-creating function))." i said elsewhere that i can see how someone familiar with lisp would see fn and def as essentially lambda and set, and

  (lambda name (arg) ...)
would definitely be odd. but the name isn't "lambda," it's "fn." and i conceive that as "function," which has no semantic bias to locality or scope

-----

1 point by almkglor 6122 days ago | link

ooh, ECMAscript:

  function foo(x){
    return function(){return x;}
  }

-----