http://www.perlmonks.org?node_id=854355

LanX has asked for the wisdom of the Perl Monks concerning the following question:

Hi

Douglas Crockford claims in his book "JavaScript The good parts" and in some of his talks (minute -27) that "JavaScript is the first lambda language to go mainstream" because one can pass anonymous functions around.

There is nothing in JS which couldn't equally be done in Perl with anonymous subs and coderefs.

Isn't Perl5 older?

Is it pure Perl5 or did it refs to anonymous functions already exist in Perl4?

Cheers Rolf

UPDATE: Strange I posted this under meditations...(?)
  • Comment on The first lambda language to go mainstream ?

Replies are listed 'Best First'.
Re: The first lambda language to go mainstream ?
by CountZero (Bishop) on Aug 11, 2010 at 14:20 UTC
    Mark Jason Dominus' "Higher Order Perl" was published in March 2005, so almost THREE years before Crockford's book and it already deals with the functional programming style in Perl.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: The first lambda language to go mainstream ?
by morgon (Priest) on Aug 11, 2010 at 15:06 UTC
    There is nothing in JS which couldn't equally be done in Perl with anonymous subs and coderefs. Isn't Perl5 older?

    And does not C have function-pointers and is it not even older then Perl?

    Who cares?

    For me to call JavaScript a "lambda language" is just as ridiculous as calling Perl a "lambda language".

    Apart from that Douglas Crockford's book is good though...

      Some searching leads one to the detail that C doesn't have true first-class functions because they aren't nestable, although GCC supports them as an extension, and also because pointer-defined functions don't close over their free variables.

        You can argue that C does not have first-class functions and I would agree - that was not my point.

        The point I was trying to make above is that (in my opinion) having first-class functions is not enough for a language to be called a "lambda language" (meaning functional language).

        Otherwise practically every current language would be a "lambda language" and the term would not be very useful.

        And so I would argue that the statement about JS being the first mainsteam lambda langues is simply wrong and the question weather it was predated by Perl irrelevant.

Re: The first lambda language to go mainstream ?
by JavaFan (Canon) on Aug 11, 2010 at 16:01 UTC
    Uhm, "passing anonymous functions around" was something LISP already did, didn't it? As it's only the second high level programming language to be created (1958; after Fortran (1957), but before COBOL (1959)), it would be hard to say it never was mainstream.

    But then, is there anything worthwhile that LISP doesn't do already?

    That's a rhetorical question.

      But then, is there anything worthwhile that LISP doesn't do already?†

      Um. oO( "format readably" )

      That's a rhetorical answer :)

      Yes the claim is LISP and Perl aren't mainstream while JS is.

      I was surprised to see LISP on position 16 in the TIOBE index, but that should be related to the actual hype around Clojure.

      Personally I only learned and used LISP to script emacs (but never repented, since I learned a lot about the concepts Larry had in mind when designing Perl)

      Well and to read and understand Clojure books ;)

      UPDATE: Actually Perl for sure influenced JS in many aspects, but it seem that for many people Perl is something like the strange boy in the neighborhood everybody met, but nobody cares to know.

      Cheers Rolf

Re: The first lambda language to go mainstream ?
by Fox (Pilgrim) on Aug 11, 2010 at 13:19 UTC
    According to wikipedia, perl5 was released in 1994 while javascript only started appering in 1995, so perl is older.

    But I think his point is in the "to go mainstream" part, I don't think perl reached that point yet, perl6 could do it perhaps.
      > According to wikipedia, perl5 was released in 1994 while javascript only started appering in 1995, so perl is older.

      Well the question was also about Perl4 and having references, IIRC the old typeglob mechanism to pass functions around is a legacy of Perl4

      JS OTOH only introduced full functional mechanisms with version 1.2 in June 1997.

      > But I think his point is in the "to go mainstream" part, I don't think perl reached that point yet, perl6 could do it perhaps.

      hehe flaming potential! :)

      IIRC both JS and Perl are listed in the top 10 of most used languages, and Perl was much earlier popular than JS.

      But Crockford seems to be an ex-Java programmer who first learned scripting with JS.

      For instance he gives some horrible advices in his book, no Saint of the monastery would ever give!

      (like using || to assign undefined values a default value! Hei JS does like Perl type casting mapping 0 and "" to false !!!)

      Cheers Rolf

        It all depends on what 'mainstream' means.

        JS got a lot more attention because you simply can't use any other language to script sites.
      Perl 6 will definitely rule the world,let alone JS. But the only problem is spec complete, Perl 5 equivalent production quality interpreter, Unless that happens its basically building palaces in thin air.
Re: The first lambda language to go mainstream ?
by CountZero (Bishop) on Aug 11, 2010 at 17:14 UTC
    Actually I seem to remember that there is no real and fundamental difference between imperative and functional programming and that they are actually "two sides of the same coin".

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      there is no real and fundamental difference between imperative and functional programming
      "two sides of the same coin"

      What would count for you as a "real and fundamental difference"?

      The logical programming paradigm (e.g. Prolog) for you is probably then the 3rd side of the same coin...

      Of course all programming paradigms are equivalent in the sense that you can have turing-complete languages for all of them but to equate equivalence with "no fundamental difference" is not giving any new insights for me.

      I am sorry but I probably don't get your point.

        What I meant was that one can "translate" any functional program into an imperative program and vice versa, hence they are the "same" or "equivalent".

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James