4 ms·
FP with dynamic scoping? Lisp is not a FP language anymore than C.
by rightbyte 5y ago
FP with dynamic scoping?
Lisp is not a FP language anymore than C.
- Jtsummers 5y agoSure it is. Using the "Appeal to Wikipedia Fallacy": https://en.wikipedia.org/wiki/Lisp_(programming_language) https://en.wikipedia.org/wiki/Lisp_(programming_language) Most Lisps are multiparadigm, covering at least the functional and procedural paradigms. Going to Common Lisp you can add OO to the mix. It is a severely constrained notion of FP that manages to exclude the first functional programming language from its definition.
- erik_seaberg 5y agoLisp is very old; it started out competing with languages lacking even reentrant function calls. Lisp had a lot of good ideas and a few poor ones from that era. As compilers improve, it becomes feasible for languages to only provide pure functions, lazy evaluation, and immutable data structures even on the same old imperative CPU cores.
- Jtsummers 5y agoDoes that make Lisp somehow not a functional programming language? That other languages have been developed to provide features that most lisps do not does not remove them from the group of functional programming languages. It just means they're part of a different branch of the same paradigm.
- erik_seaberg 5y agoIt’s pretty easy to write Lisp “functions” that are not actually functions because they invisibly depend on each others’ side effects. The goal of FP is to prevent that.
- theCodeStig 5y agoLISP is a family of languages. Some LISPs are functional (Scheme languages), some are not (Common Lisp).
- Jtsummers 5y agoIn what way is Common Lisp not a functional language?
- foldr 5y agoIt depends on how broadly you define 'functional'. Back in the day just having closures and anonymous functions was probably enough to qualify. But nowadays Javascript and any other number of scripting languages have those features too. I can't think of any respect in which Common Lisp encourages or requires a functional style to a greater extent than, say, Javascript. It's also worth mentioning that the Common Lisp standard does not require implementations to implement tail call elimination. The pervasive use of a functional style in CL would therefore give rise to programs with performance characteristics that could, at least in principle, vary greatly between implementations. (I'm aware that most popular CL implementations do optimize away tail calls in practice.)
- kazinator 5y agoCommon Lisp programs can mutate variables, function bindings, and slots of various objects such as cons cells, arrays, structures and CLOS objects. Programs can execute sequences of forms as if they were statements, for the sake of their side effects, and can conditionally and repeatedly execute such statements. There is a form called tagbody which can contain labeled statements that can freely branch to each other using go. Common Lisp doesn't require implementations to provide tail call support, so functional programs that express iteration using recursion may be severely limited in the inputs that they can handle; they would typically be ported to Common Lisp by a rewrite using iteration.
- lispm 5y agoLisp only has dynamic scoping? C comes with first class function objects, closures, ... ?
- jhgb 5y agoNot all Lisps even allow dynamic scoping. Not to mention that beginners are commonly taught Scheme, which is an example of a Lisp that doesn't allow it.