Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What subset of functional programming aspects and Lisp-like features does JavaScript provide?

Right to the point, in https://stackoverflow.com/questions/4696618/is-haskell-a-lisp?answertab=votes#tab-top, there is a comment by Kevin Cantu saying:

Yeah, moving beyond the syntax alone, JavaScript is probably more of a Lisp than Haskell. (Originally conceived as a Scheme implementation...)

Also, in Lambda the Ultimate: A Lisp to JavaScript Compiler in 100 Lines, they say:

It's immediately quite clear that JS and Lisp have strong ties at the semantics level [...]

I am familiar with Lisp and functional programming, but not with JavaScript. So these propositions made wonder how powerful is JavaScript. What I've read so far is that it provides lambda expressions and closures. What more functional programming concepts and Lisp-like features does it provide? Does it provide, for instance, tail call recursion, or macros, or ability to manipulate code as data (like Lisp)?

like image 376
Mohammad Alaggan Avatar asked Nov 20 '11 03:11

Mohammad Alaggan


1 Answers

Some things that JavaScript provides that can be considered "Lisp-like":

  • First class functions (inc. lambdas and closures)
  • Dynamic typing
  • Dynamic object model that has some similarities with CLOS
  • A readable data format that matches the source code format (JSON)
  • Run time evaluation with an "eval" function (that can be used in an interactive REPL)

Some things that Javascript doesn't have that are pretty common or central to other Lisps:

  • A homoiconic representation for both code and data (S-expressions)
  • Built in literals for linked lists / sequences
  • Support for immutable data structures in general (especially true for Clojure, where every data structure is persistent and immutable)
  • An extensive macro system for meta-programming
  • Optional static typing for performance optimisation (e.g. type hints in Common Lisp or Clojure)
  • Concurrency support
  • Tail call optimisation
like image 123
mikera Avatar answered Nov 08 '22 19:11

mikera