News for hackers. Stuff that matters.
Re:What Elm and Haskell are teaching mainstream JS [video] by marrs on Tuesday December 01, 2015 @10:32AM (#10656043)
It's nice that JS devs are continuing to discover functional programming techniques, but it irks me a little that this is considered to be some sort of new development. JS has always attracted SICP-inspired programmers because of its strong resemblance to Scheme.

Doug Crockford popularised prototypical inheritance and function programming techniques in JS on his blog nearly 10 years ago.

KnockoutJS has been around for a similar amount of time and data flow was a big part of its design. React and Elm are evolutions of design that has been a part of front-end dev for a long time.

Re:What Elm and Haskell are teaching mainstream JS [video] by jahewson on Tuesday December 01, 2015 @10:36AM (#10656084)
First class functions are only one aspect of functional programming. Immutaility is a core feature which has only recently seen popular adoption in JS, with projects such as immutable.js. Out of the box JS doesn't offer the data structures necessary to code naturally in a Scheme-like manner.

Couple this with the new concept of Virtual DOM as pioneered in React and you get purely functional UI on the web, a radical departure from the status quo of just a few years ago. Defintely a new development for JS. Indeed, React Native suggests that this could be an important development for UI in general.

Re:What Elm and Haskell are teaching mainstream JS [video] by kyllo on Tuesday December 01, 2015 @11:31AM (#10656628)
Exactly. Vanilla JS (and JQuery and friends) have the semantics of mutating a tree (the DOM) in-place. A key differentiator of these functional libraries is the immutable data structure semantics.
Re:What Elm and Haskell are teaching mainstream JS [video] by rprospero on Tuesday December 01, 2015 @12:12PM (#10657028)
As a recovering schemer, I often heard how Javascript is very closely related to Scheme, but I've never really seen the resemblance. Granted, both languages possess:

* Dynamic Typing * Garbage Collection * First Class Functions

However, Python also meets those requirements. Now, looking at it from the Scheme perspective, Python is missing

* Tail Recursion * Macros * Continuations * Concise Language Spec

However, Javascript is also missing those same factors (though I might be wrong about the tail recursion). Yet, I rarely hear of Python described as an infix version of Scheme, yet I often hear that remark about Javascript.

I really want to like Javascript and I already do like Scheme, so I have a vested interest in seeing the connection, but I'm still missing something. What's the strong resemblance between Scheme and Javascript?

Re:What Elm and Haskell are teaching mainstream JS [video] by zipfle on Tuesday December 01, 2015 @02:56PM (#10658263)
JavaScript's scoping is much friendlier for creating closures than Python's:

    def why_is_scoping_hard():
        n = 4
        def print_n():
            print n
        def modify_n(new_value):
            n = new_value
            print n
        return [print_n, modify_n]

    >>> print_n, modify_n = why_is_scoping_hard()
    >>> print_n()
    4
    >>> modify_n(7)
    7
    >>> print_n()
    4
When you assign to a variable it is automatically created in the local scope, shadowing a variable with the same name from an outer scope. If you don't assign to it, you get the value from the outer scope. If you try to print it, but then assign to it later, the print call raises an error.
Re:What Elm and Haskell are teaching mainstream JS [video] by sophacles on Tuesday December 01, 2015 @04:35PM (#10658976)
Note - in python3 variable shadowing is much more controllable - in your example having modify_n look like:

    def modify_n(new_value):
       nonlocal n
(and of course the print x -> print(x) changes), will result in 4,7,7
Re:What Elm and Haskell are teaching mainstream JS [video] by thinkpad20 on Tuesday December 01, 2015 @02:08PM (#10657904)
First-class functions (esp. anonymous functions) see relatively little use in python, due to the hobbled syntax. For example, you can't use `print` in a lambda, raise exceptions, or define any variables. In JavaScript, using an anonymous function is no different than any other function, and not surprisingly they are ubiquitous. I'd wager that this is the primary reason that JavaScript is compared to LISP so much more often than Python is. There's also the fact that JavaScript functions are all variadic, which also is similar to LISP. Also Python encourages OOP much more than JavaScript. So yeah the "look and feel" of python is quite a bit different from JS and from scheme as well.
Re:What Elm and Haskell are teaching mainstream JS [video] by davexunit on Tuesday December 01, 2015 @12:18PM (#10657099)
Lexical scope and first-class functions are about as far as the similarities go. JavaScript has nothing on Scheme.
Re:What Elm and Haskell are teaching mainstream JS [video] by agumonkey on Tuesday December 01, 2015 @09:14PM (#10660437)
Doesn't have to have anything `on`, simply coming from is enough.
Re:What Elm and Haskell are teaching mainstream JS [video] by numlocked on Tuesday December 01, 2015 @12:52PM (#10657344)
ECMAScript 6+ has tail call recursion optimization, but prior versions do not.
Re:What Elm and Haskell are teaching mainstream JS [video] by anentropic on Tuesday December 01, 2015 @12:35PM (#10657234)
maybe more an 'inspiration' than related in concrete ways...

Scheme gets mentioned re Javascript because: https://brendaneich.com/tag/history/