Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Function.EMPTY and Function.K
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 44 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Andrew Dupont  
View profile  
 More options Sep 24, 11:20 pm
From: Andrew Dupont <goo...@andrewdupont.net>
Date: Thu, 24 Sep 2009 20:20:06 -0700 (PDT)
Local: Thurs, Sep 24 2009 11:20 pm
Subject: Function.EMPTY and Function.K
Unless anyone has serious objections, or has a better idea, I'm going
to add these as aliases of `Prototype.emptyFunction` and
`Prototype.K`, respectively. They belong better there, since in theory
the `Prototype` namespace is for internal stuff, not for stuff that
has value to end-user developers.

Cheers,
Andrew


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
T.J. Crowder  
View profile  
 More options Sep 25, 2:26 am
From: "T.J. Crowder" <t...@crowdersoftware.com>
Date: Thu, 24 Sep 2009 23:26:44 -0700 (PDT)
Local: Fri, Sep 25 2009 2:26 am
Subject: Re: Function.EMPTY and Function.K
Andrew,

Make sense.  Shouldn't that be Function.empty and Function.k, though,
to follow our naming rules?  And perhaps Function.k should have a more
meaningful name.

-- T.J.

On Sep 25, 4:20 am, Andrew Dupont <goo...@andrewdupont.net> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Quadling  
View profile  
 More options Sep 25, 3:47 am
From: Richard Quadling <rquadl...@googlemail.com>
Date: Fri, 25 Sep 2009 08:47:08 +0100
Local: Fri, Sep 25 2009 3:47 am
Subject: Re: [Prototype-core] Re: Function.EMPTY and Function.K
2009/9/25 T.J. Crowder <t...@crowdersoftware.com>:

As f(x) => x, f is an identity function.

So, maybe

Function.identity(x) { return x; }

Hmm, whilst technically correct, the term "identity" may not be what
people are used to.

Maybe Function.AsIs() ?

--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Higson  
View profile  
 More options Sep 25, 4:06 am
From: Jim Higson <j...@wikizzle.org>
Date: Fri, 25 Sep 2009 09:06:45 +0100
Local: Fri, Sep 25 2009 4:06 am
Subject: Re: [Prototype-core] Function.EMPTY and Function.K
On Friday 25 September 2009 04:20:06 Andrew Dupont wrote:

> Unless anyone has serious objections, or has a better idea, I'm going
> to add these as aliases of `Prototype.emptyFunction` and
> `Prototype.K`, respectively. They belong better there, since in theory
> the `Prototype` namespace is for internal stuff, not for stuff that
> has value to end-user developers.

That's quite odd actually, on the bus from London to Oxford this morning I was
wondering if they should be named this way in Prototype. But, yes, I have been
doing it this way for quite some time in my own projects. I think it is much
more intuitive.

I would probably use Function.IDENTITY rather than Function.K because probably
more people are familiar with 'the identity function' than 'k'.

--
Jim
my wiki ajaxification thing: http://wikizzle.org
my blog: http://jimhigson.blogspot.com/


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
T.J. Crowder  
View profile  
 More options Sep 25, 6:22 am
From: "T.J. Crowder" <t...@crowdersoftware.com>
Date: Fri, 25 Sep 2009 03:22:57 -0700 (PDT)
Local: Fri, Sep 25 2009 6:22 am
Subject: Re: Function.EMPTY and Function.K

> Hmm, whilst technically correct, the term "identity" may not be what
> people are used to.

Good point about it being an identity function, but agreed about
confusion.

"passThrough"?

-- T.J.

On Sep 25, 8:47 am, Richard Quadling <rquadl...@googlemail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Allen Madsen  
View profile  
 More options Sep 25, 7:42 am
From: Allen Madsen <bla...@gmail.com>
Date: Fri, 25 Sep 2009 07:42:51 -0400
Local: Fri, Sep 25 2009 7:42 am
Subject: Re: [Prototype-core] Re: Function.EMPTY and Function.K
I think Function.identity is fine. If somebody is unsure of what it it
they can check the docs.

Allen Madsen
http://www.allenmadsen.com


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rick Waldron  
View profile  
 More options Sep 25, 8:08 am
From: Rick Waldron <waldron.r...@gmail.com>
Date: Fri, 25 Sep 2009 08:08:57 -0400
Local: Fri, Sep 25 2009 8:08 am
Subject: Re: [Prototype-core] Re: Function.EMPTY and Function.K

On the subject of end developer confusion, I'd like to make a suggestion
regarding the naming...

Function.emptyFn
Function.returnFn

Because they say exactly what they are. This is how I've named (almost...
$.function.emptyFn() and $.function.returnFn() ) the exact same
functionality in the Pollen.JS library (for use within a new Worker() )

Rick


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Higson  
View profile  
 More options Sep 25, 8:29 am
From: Jim Higson <j...@wikizzle.org>
Date: Fri, 25 Sep 2009 13:29:15 +0100
Local: Fri, Sep 25 2009 8:29 am
Subject: Re: [Prototype-core] Re: Function.EMPTY and Function.K
On Friday 25 September 2009 13:08:57 Rick Waldron wrote:

> On the subject of end developer confusion, I'd like to make a suggestion
> regarding the naming...

> Function.emptyFn
> Function.returnFn

> Because they say exactly what they are. This is how I've named (almost...
> $.function.emptyFn() and $.function.returnFn() ) the exact same
> functionality in the Pollen.JS library (for use within a new Worker() )

I'd say returnFn sounds like a function which returns a function.

--
Jim
my wiki ajaxification thing: http://wikizzle.org
my blog: http://jimhigson.blogspot.com/


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
T.J. Crowder  
View profile  
 More options Sep 25, 9:19 am
From: "T.J. Crowder" <t...@crowdersoftware.com>
Date: Fri, 25 Sep 2009 06:19:38 -0700 (PDT)
Local: Fri, Sep 25 2009 9:19 am
Subject: Re: Function.EMPTY and Function.K
We could _so_ overcomplicate this... ;-)

On Sep 25, 1:29 pm, Jim Higson <j...@wikizzle.org> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Kieffer  
View profile  
 More options Sep 25, 10:11 am
From: Robert Kieffer <bro...@gmail.com>
Date: Fri, 25 Sep 2009 07:11:12 -0700
Local: Fri, Sep 25 2009 10:11 am
Subject: Re: [Prototype-core] Re: Function.EMPTY and Function.K

Function.empty and Function.identity get my vote.

However, does this mean Prototype.EMPTY and Prototype.K are being
deprecated?  I ask because I generally dislike aliases in APIs.  Unless they
are used as part of the deprecation process, they are usually more trouble
than they're worth.  They make code harder to read and share, developers get
into silly quibbles as to which is better, etc.  In short, they're annoying
- it's better if the framework developers make it clear what the preferred
name is, and eventually deprecate the non-preferred ones.

My $.02.

- rwk

On Fri, Sep 25, 2009 at 6:19 AM, T.J. Crowder <t...@crowdersoftware.com>wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
T.J. Crowder  
View profile  
 More options Sep 25, 2:23 pm
From: "T.J. Crowder" <t...@crowdersoftware.com>
Date: Fri, 25 Sep 2009 11:23:54 -0700 (PDT)
Local: Fri, Sep 25 2009 2:23 pm
Subject: Re: Function.EMPTY and Function.K
Well, technically they aren't part of the API because the Prototype
namespace isn't public (in theory), but:

+1 to the new ones
+1 to deprecating and ultimately removing the old ones

-- T.J.

On Sep 25, 3:11 pm, Robert Kieffer <bro...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joran  
View profile  
 More options Sep 25, 4:40 pm
From: Joran <jorangr...@gmail.com>
Date: Fri, 25 Sep 2009 13:40:30 -0700 (PDT)
Local: Fri, Sep 25 2009 4:40 pm
Subject: Re: Function.EMPTY and Function.K
+1 to Function.identity
+1 to deprecating Prototype.emptyFunction and Prototype.K

I prefer Function.reference to Function.empty. String.empty already
exists but not as reference to an empty string. Function.reference
describes the intent.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kangax  
View profile  
 More options Sep 25, 11:04 pm
From: kangax <kan...@gmail.com>
Date: Fri, 25 Sep 2009 20:04:22 -0700 (PDT)
Local: Fri, Sep 25 2009 11:04 pm
Subject: Re: Function.EMPTY and Function.K
On Sep 24, 11:20 pm, Andrew Dupont <goo...@andrewdupont.net> wrote:

> Unless anyone has serious objections, or has a better idea, I'm going
> to add these as aliases of `Prototype.emptyFunction` and
> `Prototype.K`, respectively. They belong better there, since in theory
> the `Prototype` namespace is for internal stuff, not for stuff that
> has value to end-user developers.

It sure makes more sense to have those on `Function`. I kind of hate
that we're putting yet another (completely made-up) method on yet
another built-in native, but it looks like there's not much that can
be done about it at this point anyway.

As far as naming, I would probably go with `Function.empty` and
`Function.identity` (`Function.K` looks neat but it would then make
sense to uppercase `EMPTY` too, and I like lowercase version more).

Now that we're on this subject, we can also add so often useful
`Function.false` (i.e. `function(){ return false; }`). I use it all
the time for things like preventing events -
`someElement.onselectstart = Prototype.falseFunction;`, etc.

Is anyone else using something like that?

--
kangax


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Radoslav Stankov  
View profile  
 More options Sep 26, 6:00 am
From: Radoslav Stankov <rstan...@gmail.com>
Date: Sat, 26 Sep 2009 03:00:01 -0700 (PDT)
Local: Sat, Sep 26 2009 6:00 am
Subject: Re: Function.EMPTY and Function.K
Actually I use Function.preventDefault = function(callback, e)
{ callback(e); e.preventDefault() }; witch is excaclly for event
handing, but I think there isn't any chance this could go into core.

As for Fuction.empty / Function.identity +1 ( at first identity
sounded weird, but I could find a better name my self )


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
artemy tregubenko  
View profile  
 More options Sep 26, 6:30 am
From: "artemy tregubenko" <m...@arty.name>
Date: Sat, 26 Sep 2009 14:30:39 +0400
Local: Sat, Sep 26 2009 6:30 am
Subject: Re: [Prototype-core] Re: Function.EMPTY and Function.K
Why don't you use element.onselectstart = Event.stop; ?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kangax  
View profile  
 More options Sep 26, 11:10 am
From: kangax <kan...@gmail.com>
Date: Sat, 26 Sep 2009 08:10:34 -0700 (PDT)
Local: Sat, Sep 26 2009 11:10 am
Subject: Re: Function.EMPTY and Function.K

On Sep 26, 6:30 am, "artemy tregubenko" <m...@arty.name> wrote:

> Why don't you use element.onselectstart = Event.stop; ?

Because `Event.stop` expects first argument to be an event object, and
MSHTML does not supply that argument to event handler attached as a
property of an element. When assigned to a property, `Event.stop` will
try to operate on an undefined value and eventually throw error.

Even if `Event.stop` accounted for IE-proprietary `window.event`, it
would be kind of an overkill to 1) extend event, 2) prevent its
default action, 3) stop propagation, and 4) extend it with "stopped"
property - when all that's needed is plain and simple - `return
false`.

[...]

--
kangax


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
artemy tregubenko  
View profile  
 More options Sep 26, 4:17 pm
From: "artemy tregubenko" <m...@arty.name>
Date: Sun, 27 Sep 2009 00:17:00 +0400
Subject: Re: [Prototype-core] Re: Function.EMPTY and Function.K
Ah, i forgot that i used even more overkilling but working solution:  
element.observe('selectstart', Event.stop);

Anyway i got your point.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Higson  
View profile  
 More options Sep 28, 3:44 am
From: Jim Higson <j...@wikizzle.org>
Date: Mon, 28 Sep 2009 08:44:13 +0100
Local: Mon, Sep 28 2009 3:44 am
Subject: Re: [Prototype-core] Re: Function.EMPTY and Function.K
On Saturday 26 September 2009 04:04:22 kangax wrote:

I have Function.alwaysReturn( val );

So, I'd use Function.alwaysReturn( false ) in that case.

Is good for anywhere a function is expected but you want to insert a value.
Eg, Function.alwaysReturn( 4 );

Function.alwaysReturn =
        function ( val ){
                return (function(){return val});
        };

--
Jim
my wiki ajaxification thing: http://wikizzle.org
my blog: http://jimhigson.blogspot.com/


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kangax  
View profile  
 More options Sep 28, 10:51 am
From: kangax <kan...@gmail.com>
Date: Mon, 28 Sep 2009 07:51:32 -0700 (PDT)
Local: Mon, Sep 28 2009 10:51 am
Subject: Re: Function.EMPTY and Function.K
On Sep 28, 3:44 am, Jim Higson <j...@wikizzle.org> wrote:

I remember seeing this in Dean's base2.js and Oliver Steele's
functional.js under then name - "K":

function K(value){
  return function() {
    return value;
  }

}

It's then easy to define other abstractions with this one function -

Function.empty = K();
Function.false = K(false);
Function.true = K(true);

// etc.

--
kangax


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joran Greef  
View profile  
 More options Sep 29, 1:49 am
From: Joran Greef <jorangr...@gmail.com>
Date: Mon, 28 Sep 2009 22:49:15 -0700 (PDT)
Local: Tues, Sep 29 2009 1:49 am
Subject: Re: Function.EMPTY and Function.K
Prototype's existing String.empty and Array.empty interfaces would
imply that Function.empty return a boolean indicating perhaps that the
function is empty.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Quadling  
View profile  
 More options Sep 29, 3:50 am
From: Richard Quadling <rquadl...@googlemail.com>
Date: Tue, 29 Sep 2009 08:50:24 +0100
Local: Tues, Sep 29 2009 3:50 am
Subject: Re: [Prototype-core] Re: Function.EMPTY and Function.K
2009/9/29 Joran Greef <jorangr...@gmail.com>:

> Prototype's existing String.empty and Array.empty interfaces would
> imply that Function.empty return a boolean indicating perhaps that the
> function is empty.

Numpty brain this morning, but ...

As I understand things, K(x) => x, not K(x) => (fn() => x)

--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Higson  
View profile  
 More options Sep 29, 3:58 am
From: Jim Higson <j...@wikizzle.org>
Date: Tue, 29 Sep 2009 08:58:19 +0100
Local: Tues, Sep 29 2009 3:58 am
Subject: Re: [Prototype-core] Re: Function.EMPTY and Function.K
On Tuesday 29 September 2009 06:49:15 Joran Greef wrote:

> Prototype's existing String.empty and Array.empty interfaces would
> imply that Function.empty return a boolean indicating perhaps that the
> function is empty.

Well, it *could* do:

Function.empty = function(){};
Function.empty.empty = function(){return true};

Of course this doesn't cover other empty functions and I may be not entirely
serious ;-)

Jim

--
Jim
my wiki ajaxification thing: http://wikizzle.org
my blog: http://jimhigson.blogspot.com/


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
T.J. Crowder  
View profile  
 More options Sep 29, 4:22 am
From: "T.J. Crowder" <t...@crowdersoftware.com>
Date: Tue, 29 Sep 2009 01:22:53 -0700 (PDT)
Local: Tues, Sep 29 2009 4:22 am
Subject: Re: Function.EMPTY and Function.K
Being serious for a moment, it sounds like we're all happy (enough)
with Function.empty.

Can't say I *like* Function.identity (I'd prefer "Function.passBack")
but it at least is readily defensible as being derived from
mathematics (like curry) and there are several "yea" vote for it in
this thread.

-- T.J. :-)

On Sep 29, 8:58 am, Jim Higson <j...@wikizzle.org> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joran Greef  
View profile  
 More options Sep 29, 11:49 am
From: Joran Greef <jorangr...@gmail.com>
Date: Tue, 29 Sep 2009 08:49:21 -0700 (PDT)
Local: Tues, Sep 29 2009 11:49 am
Subject: Re: Function.EMPTY and Function.K
Agreed. I like Function.identity as well for the same reason in that
there is in fact a reason. I don't think Function.empty has the same
going for it, apart from it being the legacy terminology. We could do
better.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Dupont  
View profile  
 More options Oct 14, 8:08 pm
From: Andrew Dupont <goo...@andrewdupont.net>
Date: Wed, 14 Oct 2009 19:08:53 -0500
Local: Wed, Oct 14 2009 8:08 pm
Subject: Re: [Prototype-core] Re: Function.EMPTY and Function.K
Weighing in again, decades after starting the thread.

First, I'm fine with calling it Function.IDENTITY instead of Function.K.

On Sep 25, 2009, at 1:26 AM, T.J. Crowder wrote:

> Make sense.  Shouldn't that be Function.empty and Function.k, though,
> to follow our naming rules?  And perhaps Function.k should have a more
> meaningful name.

I'm very much in favor of all-caps, or at least initial caps, to  
indicate that these are constants. We don't do this consistently in  
the framework so far, but I'd like it to match stuff like  
Event.KEY_ESC. I think the capitalization will also help distinguish  
it from String#empty and Array#empty, as was mentioned elsewhere.  
(Aside: I'm also in favor of renaming those methods to `isEmpty` for  
2.0.)

What do people think about the capitalization?

Cheers,
Andrew


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 44   Newer >
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google