Re:JavaScript Isn't Scheme (2013)
by drablyechoes on Thursday April 26, 2018 @09:01AM
(#16931454)
Heh, I have been writing "crappy scheme" in Perl (and more recently JS) for years. Perl is actually kind of nice to use as a functional programming language, once you get used to thinking of it as such.
"Higher Order Perl" is a great book and I still refer to it as a general reference for FP concepts and techniques.
I'd suggest using Kotlin then. It has tail call optimization, and nice functional programming constructs. It can also be compiled to javascript: http://the-cogitator.com/2018/04/25/going-beyond-android-kot...
Re:JavaScript Isn't Scheme (2013)
by chriswarbo on Friday April 27, 2018 @07:16AM
(#16939856)
> I'd suggest using Kotlin then
I gave the caveat of "whenever I'm using JS" since I only use JS when I have to, and that's not very often (as I say, I don't have much love for the language).
I think it's a bit inappropriate to throw out random suggestions like Kotlin when the discussion is about Javascript and Scheme. I spend most of my time in Haskell, which (like seemingly every language these days) can also be compiled to JS, and I'd wager is 'even more functional' than Kotlin. I didn't mention it because the discussion was about JS and Scheme ;)
When I'm writing JS in this way, my mental model is basically "a crappy Scheme", i.e. I'll tend to come up with implementations which are similar to what I'd do in Scheme (pure functions and closures), except I have to consciously avoid boilerplate (since there are no macros to tame it) and unbounded recursion (since there's no tail-call elimination), hence the "crappy".
Maybe it helps that none of my Scheme code has used continuations, outside of examples/playing, so there's less of a disconnect there?