Re: Terminology: “non-method function”

2012-04-13 Thread Axel Rauschmayer
> On Tue, Apr 10, 2012 at 4:01 PM, Axel Rauschmayer  wrote:
> What is a good term for functions that don’t have/use dynamic `this`? 
> “Non-method function” defines them by what they aren’t, I would like a 
> positive definition. I’ve considered the term “pure function”, but the 
> adjective “pure” is already heavily overloaded, especially in functional 
> programming.
> 
> Your combination 'don't have/use'  confuses me. A function declaration does 
> not have a 'this', dynamic or not, but it can use 'this' and expect it to be 
> bound dynamically. A function object created from the function declaration 
> can have 'this', but only if it is bound, which in my understanding is 
> therefore not dynamic. To me 'having a dynamic this' is an oxymoron: if you 
> have it, then it ain't dynamic.
> 
> Can you un-confuse me?


I was thinking of the function’s “activation record” where a `this` field is 
part of the ExecutionContext.

Maybe a better way is to ask:
“What is a good term for functions that have no use for their own `this`, that 
want to access the `this` of their surrounding scope?”

I find human language tricky here...

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-11 Thread Rick Waldron
On Wed, Apr 11, 2012 at 4:32 PM, Wes Garland  wrote:

> From a developer's POV - the terms bound/unbound makes a create deal of
> sense, since already have bind, which effectively turns an unbound function
> into a bound function.  It basically completes the thought and makes it
> easy to explain.
>

Absolutely agree


>
> Heck, it even makes this behaviour easy to explain:
>
> function ABC()
> {
>   this.hello = "world";
> }
> ABC.prototype.def = function() { alert(this.hello) };
> window.onclick = new ABC().def;
>
> Q: Why does my program alert undefined?
> A: The default behaviour for an event handler is to bind the event itself
> as 'this'.


Just to avoid any confusion, you'll actually get the event.currentTarget as
|this|

Rick


> If you wanted that program to alert "world", you should have used a *bound
> function* instead.
>
> Wes
>
> --
> Wesley W. Garland
> Director, Product Development
> PageMail, Inc.
> +1 613 542 2787 x 102
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-11 Thread Wes Garland
>From a developer's POV - the terms bound/unbound makes a create deal of
sense, since already have bind, which effectively turns an unbound function
into a bound function.  It basically completes the thought and makes it
easy to explain.

Heck, it even makes this behaviour easy to explain:

function ABC()
{
  this.hello = "world";
}
ABC.prototype.def = function() { alert(this.hello) };
window.onclick = new ABC().def;

Q: Why does my program alert undefined?
A: The default behaviour for an event handler is to bind the event itself
as 'this'. If you wanted that program to alert "world", you should have
used a *bound function* instead.

Wes

-- 
Wesley W. Garland
Director, Product Development
PageMail, Inc.
+1 613 542 2787 x 102
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-11 Thread Allen Wirfs-Brock
(corrected a pretty obvious typo in the first sentence)

On Apr 11, 2012, at 7:12 AM, Peter van der Zee wrote:

> On Wed, Apr 11, 2012 at 1:01 AM, Axel Rauschmayer  wrote:
>> What is a good term for functions that don’t have/use dynamic `this`?
> 
> A bound function?

I'm leaning in that direction.  A unbound function has an unbound (dynamic) 
this while a bound function has a bound (fixed) this.

To further clarify this it might be useful to better differentiate  binding 
this from currying the arguments.

We might do this by adding a new Function.prototype.curry function that doesn't 
have a this value as its first argument.

You would then
 fn.curry(1,2)

If you want to create a curried function from fn with 1 and 2 as the first two 
fn arguments. And:

 fn.bind(foo)

if you want to create a bound version of fn where this is bound to the value of 
foo.

The semantics of 

   fn.bind(foo,1,2)

could then be explained as being equivalent to 

   fn.bind(foo).curry(1,2)

Allen




___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-11 Thread John J Barton
On Tue, Apr 10, 2012 at 4:01 PM, Axel Rauschmayer  wrote:

> What is a good term for functions that don’t have/use dynamic `this`?
> “Non-method function” defines them by what they aren’t, I would like a
> positive definition. I’ve considered the term “pure function”, but the
> adjective “pure” is already heavily overloaded, especially in functional
> programming.
>

Your combination 'don't have/use'  confuses me. A function declaration does
not have a 'this', dynamic or not, but it can use 'this' and expect it to
be bound dynamically. A function object created from the function
declaration can have 'this', but only if it is bound, which in my
understanding is therefore not dynamic. To me 'having a dynamic this' is an
oxymoron: if you have it, then it ain't dynamic.

Can you un-confuse me?

jjb


>
> Any ideas?
>
> Thanks!
>
> Axel
>
> --
> Dr. Axel Rauschmayer
> a...@rauschma.de
>
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
>
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Terminology: “non-method function”

2012-04-11 Thread Domenic Denicola
We use `Function.prototype.partial` in our codebase. We consider 
`Function.prototype.papply` but thought that would be too confusing with 
`Function.prototype.apply`.


From: es-discuss-boun...@mozilla.org [es-discuss-boun...@mozilla.org] on behalf 
of Axel Rauschmayer [a...@rauschma.de]
Sent: Wednesday, April 11, 2012 12:54
To: Allen Wirfs-Brock
Cc: es-discuss
Subject: Re: Terminology: “non-method function”

Great idea. Do we need similar this-less variants for call and apply? Probably 
not, the former is just a normal function call. The latter can by handled by 
the spread operator.

IIRC, what one actually does here is not currying, but partial application. 
However, I don’t see any good method name being derived from “partial 
application”.


On Apr 11, 2012, at 18:44 , Allen Wirfs-Brock wrote:


On Apr 11, 2012, at 7:12 AM, Peter van der Zee wrote:

On Wed, Apr 11, 2012 at 1:01 AM, Axel Rauschmayer 
mailto:a...@rauschma.de>> wrote:
What is a good term for functions that don’t have/use dynamic `this`?

A bound function?

I'm leaning in that direction.  A bound function has an unbound (dynamic) this 
while a bound function has a bound (fixed) this.

To further clarify this it might be useful to better differentiate  binding 
this from currying the arguments.

We might do this by adding a new Function.prototype.curry function that doesn't 
have a this value as its first argument.

You would then
 fn.curry(1,2)

If you want to create a curried function from fn with 1 and 2 as the first two 
fn arguments. and:

 fn.bind(foo)

if you want to created a bound version of fn where this is bound to the value 
of foo.

The semantics of

   fn.bind(foo,1,2)

could then be explained as being equivalent to

   fn.bind(foo).curry(1,2)

Allen






--
Dr. Axel Rauschmayer
a...@rauschma.de<mailto:a...@rauschma.de>

home: rauschma.de<http://rauschma.de>
twitter: twitter.com/rauschma<http://twitter.com/rauschma>
blog: 2ality.com<http://2ality.com>

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-11 Thread Axel Rauschmayer
Great idea. Do we need similar this-less variants for call and apply? Probably 
not, the former is just a normal function call. The latter can by handled by 
the spread operator.

IIRC, what one actually does here is not currying, but partial application. 
However, I don’t see any good method name being derived from “partial 
application”.


On Apr 11, 2012, at 18:44 , Allen Wirfs-Brock wrote:

> 
> On Apr 11, 2012, at 7:12 AM, Peter van der Zee wrote:
> 
>> On Wed, Apr 11, 2012 at 1:01 AM, Axel Rauschmayer  wrote:
>>> What is a good term for functions that don’t have/use dynamic `this`?
>> 
>> A bound function?
> 
> I'm leaning in that direction.  A bound function has an unbound (dynamic) 
> this while a bound function has a bound (fixed) this.
> 
> To further clarify this it might be useful to better differentiate  binding 
> this from currying the arguments.
> 
> We might do this by adding a new Function.prototype.curry function that 
> doesn't have a this value as its first argument.
> 
> You would then
>  fn.curry(1,2)
> 
> If you want to create a curried function from fn with 1 and 2 as the first 
> two fn arguments. and:
> 
>  fn.bind(foo)
> 
> if you want to created a bound version of fn where this is bound to the value 
> of foo.
> 
> The semantics of 
> 
>fn.bind(foo,1,2)
> 
> could then be explained as being equivalent to 
> 
>fn.bind(foo).curry(1,2)
> 
> Allen
> 
> 
> 
> 
> 

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-11 Thread Allen Wirfs-Brock

On Apr 11, 2012, at 7:12 AM, Peter van der Zee wrote:

> On Wed, Apr 11, 2012 at 1:01 AM, Axel Rauschmayer  wrote:
>> What is a good term for functions that don’t have/use dynamic `this`?
> 
> A bound function?

I'm leaning in that direction.  A bound function has an unbound (dynamic) this 
while a bound function has a bound (fixed) this.

To further clarify this it might be useful to better differentiate  binding 
this from currying the arguments.

We might do this by adding a new Function.prototype.curry function that doesn't 
have a this value as its first argument.

You would then
  fn.curry(1,2)

If you want to create a curried function from fn with 1 and 2 as the first two 
fn arguments. and:

  fn.bind(foo)

if you want to created a bound version of fn where this is bound to the value 
of foo.

The semantics of 
  
fn.bind(foo,1,2)

could then be explained as being equivalent to 

fn.bind(foo).curry(1,2)

Allen




___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-11 Thread Peter van der Zee
On Wed, Apr 11, 2012 at 1:01 AM, Axel Rauschmayer  wrote:
> What is a good term for functions that don’t have/use dynamic `this`?

A bound function?
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-11 Thread Rick Waldron


On Wednesday, April 11, 2012 at 6:37 AM, Alex Russell wrote:

>  
> On Apr 11, 2012, at 1:02 AM, Allen Wirfs-Brock wrote:
>  
> > On Apr 10, 2012, at 4:01 PM, Axel Rauschmayer wrote:
> >  
> > > What is a good term for functions that don’t have/use dynamic `this`? 
> > > “Non-method function” defines them by what they aren’t, I would like a 
> > > positive definition. I’ve considered the term “pure function”, but the 
> > > adjective “pure” is already heavily overloaded, especially in functional 
> > > programming.
> > >  
> > > Any ideas?
> >  
> > How about:
> >  
> > procedure - call "callable" object
> > method - a procedure that has a dynamic this (or super) dependency
> > function - a procedure that does not have a dynamic this dependency
> > detached method - a method that has not been associated with an object via 
> > Object.defineMethod
> >  
>  
>  
> What in the world would "defineMethod" do?
>  
> The confusing nature of the word "method" seems not to be cleared up by this. 
> How about "bound" and "unbound" functions? Their iterability might bump them 
> into "method" category if bound, but I think that's still just going to 
> confuse non-JS folk.

This is actually how most JS devs, that I regularly speak with, describe the 
functions you're describing: constructor, bound/unbound function, method.

  
>  
> > FunctionDeclarations and FunctionExpressions may be used to define either 
> > methods or functions.
> > Arrow Function expression only define functions
> > Concise method definitions in object literals and class definitions may 
> > define either methods or functions
> >  
> > It's messy, but emphasizes that the important thing is what the function 
> > depends upon rather than which syntactic form was used to define it.
> >  
> > Allen
> >  
> >  
> > ___
> > es-discuss mailing list
> > es-discuss@mozilla.org
> > https://mail.mozilla.org/listinfo/es-discuss
> >  
>  
>  
> --
> Alex Russell
> slightly...@google.com
> slightly...@chromium.org
> a...@dojotoolkit.org BE03 E88D EABB 2116 CC49 8259 CF78 E242 59C3 9723
>  
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>  
>  


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-11 Thread Axel Rauschmayer
On Apr 11, 2012, at 12:37 , Alex Russell wrote:

> On Apr 11, 2012, at 1:02 AM, Allen Wirfs-Brock wrote:
> 
>> On Apr 10, 2012, at 4:01 PM, Axel Rauschmayer wrote:
>> 
>>> What is a good term for functions that don’t have/use dynamic `this`? 
>>> “Non-method function” defines them by what they aren’t, I would like a 
>>> positive definition. I’ve considered the term “pure function”, but the 
>>> adjective “pure” is already heavily overloaded, especially in functional 
>>> programming.
>>> 
>>> Any ideas?
>> 
>> How about:
>> 
>> procedure - call "callable" object
>> method - a procedure that has a dynamic this (or super) dependency
>> function - a procedure that does not have a dynamic this dependency
>> detached method - a method that has not been associated with an object via 
>> Object.defineMethod
> 
> What in the world would "defineMethod" do?

For `super` to work, a function needs a reference to the object that it is 
stored in. In the current object literal proposal [1], an object literal does 
it for you. If you don’t use an object literal, you need defineMethod.

> The confusing nature of the word "method" seems not to be cleared up by this. 
> How about "bound" and "unbound" functions? Their iterability might bump them 
> into "method" category if bound, but I think that's still just going to 
> confuse non-JS folk.

I would make the following distinction:
#1 Intended use: non-method (callback? subroutine?) versus method.
#2 Implementation technique: bound function versus unbound function.

ES.next will shield you from the fact that you have to bind functions for them 
to work as expected as callbacks. I’m looking for a term that explains 
non-methods at #1 to people who are not familiar with JavaScript.


[1] http://wiki.ecmascript.org/doku.php?id=harmony:object_literals

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-11 Thread Alex Russell

On Apr 11, 2012, at 1:02 AM, Allen Wirfs-Brock wrote:

> On Apr 10, 2012, at 4:01 PM, Axel Rauschmayer wrote:
> 
>> What is a good term for functions that don’t have/use dynamic `this`? 
>> “Non-method function” defines them by what they aren’t, I would like a 
>> positive definition. I’ve considered the term “pure function”, but the 
>> adjective “pure” is already heavily overloaded, especially in functional 
>> programming.
>> 
>> Any ideas?
> 
> How about:
> 
> procedure - call "callable" object
> method - a procedure that has a dynamic this (or super) dependency
> function - a procedure that does not have a dynamic this dependency
> detached method - a method that has not been associated with an object via 
> Object.defineMethod

What in the world would "defineMethod" do?

The confusing nature of the word "method" seems not to be cleared up by this. 
How about "bound" and "unbound" functions? Their iterability might bump them 
into "method" category if bound, but I think that's still just going to confuse 
non-JS folk.

> FunctionDeclarations and FunctionExpressions may be used to define either 
> methods or functions.
> Arrow Function expression only define functions
> Concise method definitions in object literals and class definitions may 
> define either methods or functions
> 
> It's messy, but emphasizes that the important thing is what the function 
> depends upon rather than which syntactic form was used to define it.
> 
> Allen
> 
> 
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

--
Alex Russell
slightly...@google.com
slightly...@chromium.org
a...@dojotoolkit.org BE03 E88D EABB 2116 CC49 8259 CF78 E242 59C3 9723

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-10 Thread Axel Rauschmayer
Or, if we could somehow express that a “non-method” has no dynamic dependencies 
and e.g. call it “static function” or “lexical function”.

> However, in JS we have:
> 
>  callableObject instanceof Function
> 
> Thus, how about the following:
> 
> - Function: a callable object
> - Method: A function that has a dynamic this (or super) dependency.
> - Callback: A function that does not have a dynamic this dependency.

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-10 Thread Axel Rauschmayer
On Apr 11, 2012, at 2:02 , Allen Wirfs-Brock wrote:

> On Apr 10, 2012, at 4:01 PM, Axel Rauschmayer wrote:
> 
>> What is a good term for functions that don’t have/use dynamic `this`? 
>> “Non-method function” defines them by what they aren’t, I would like a 
>> positive definition. I’ve considered the term “pure function”, but the 
>> adjective “pure” is already heavily overloaded, especially in functional 
>> programming.
>> 
>> Any ideas?
> 
> How about:
> 
> procedure - call "callable" object
> method - a procedure that has a dynamic this (or super) dependency
> function - a procedure that does not have a dynamic this dependency
> detached method - a method that has not been associated with an object via 
> Object.defineMethod


I like it. If it wasn’t JavaScript, “function” would clearly be the best name 
for “a procedure that does not have a dynamic this dependency”. However, in JS 
we have:

 callableObject instanceof Function

Thus, how about the following:

- Function: a callable object
- Method: A function that has a dynamic this (or super) dependency.
- Callback: A function that does not have a dynamic this dependency.

Not ideal (and in some ways, not as precise), but possibly less confusing.

Interestingly, that would make Math.* (etc.) callbacks, not methods. That 
works, because Math is just a namespace.

> FunctionDeclarations and FunctionExpressions may be used to define either 
> methods or functions.
> Arrow Function expression only define functions

The following is the messy one:

> Concise method definitions in object literals and class definitions may 
> define either methods or functions

Clearly, one’s‚ intention is to define a method. But we may have to live with 
that, because it’s probably better to categorize callable objects according to 
some trait of theirs and not according to how they are used at the moment. (I’m 
not 100% sure, though.) Definitions using the latter approach would be “a 
function that is the value of a property” or “a function-valued property”.

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-10 Thread Axel Rauschmayer
Endophoric? It would make linguists happy. ;-)

On Apr 11, 2012, at 1:48 , Mark S. Miller wrote:

> "Non-exophoric" is probably too obscure ;)
> 
> On Tue, Apr 10, 2012 at 4:01 PM, Axel Rauschmayer  wrote:
> What is a good term for functions that don’t have/use dynamic `this`? 
> “Non-method function” defines them by what they aren’t, I would like a 
> positive definition. I’ve considered the term “pure function”, but the 
> adjective “pure” is already heavily overloaded, especially in functional 
> programming.
> 
> Any ideas?
> 
> Thanks!
> 
> Axel
> 
> -- 
> Dr. Axel Rauschmayer
> a...@rauschma.de
> 
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
> 
> 
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> 
> 
> 
> 
> -- 
> Cheers,
> --MarkM

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-10 Thread Allen Wirfs-Brock
On Apr 10, 2012, at 4:01 PM, Axel Rauschmayer wrote:

> What is a good term for functions that don’t have/use dynamic `this`? 
> “Non-method function” defines them by what they aren’t, I would like a 
> positive definition. I’ve considered the term “pure function”, but the 
> adjective “pure” is already heavily overloaded, especially in functional 
> programming.
> 
> Any ideas?

How about:

procedure - call "callable" object
method - a procedure that has a dynamic this (or super) dependency
function - a procedure that does not have a dynamic this dependency
detached method - a method that has not been associated with an object via 
Object.defineMethod

FunctionDeclarations and FunctionExpressions may be used to define either 
methods or functions.
Arrow Function expression only define functions
Concise method definitions in object literals and class definitions may define 
either methods or functions

It's messy, but emphasizes that the important thing is what the function 
depends upon rather than which syntactic form was used to define it.

Allen


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Terminology: “non-method function”

2012-04-10 Thread Mark S. Miller
"Non-exophoric" is probably too obscure ;)

On Tue, Apr 10, 2012 at 4:01 PM, Axel Rauschmayer  wrote:

> What is a good term for functions that don’t have/use dynamic `this`?
> “Non-method function” defines them by what they aren’t, I would like a
> positive definition. I’ve considered the term “pure function”, but the
> adjective “pure” is already heavily overloaded, especially in functional
> programming.
>
> Any ideas?
>
> Thanks!
>
> Axel
>
> --
> Dr. Axel Rauschmayer
> a...@rauschma.de
>
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
>
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Terminology: “non-method function”

2012-04-10 Thread Axel Rauschmayer
What is a good term for functions that don’t have/use dynamic `this`? 
“Non-method function” defines them by what they aren’t, I would like a positive 
definition. I’ve considered the term “pure function”, but the adjective “pure” 
is already heavily overloaded, especially in functional programming.

Any ideas?

Thanks!

Axel

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss