r/functionalprogramming • • Apr 29 '25
Question Is Lisp Functional?
Do you guys consider lisp languages (CL in particular) to be functional? Of course they can be used functionally, but they also have some OOP qualities. Do you CALL them functional or multi-paradigm?
39
Upvotes
View all comments
Show parent comment
2
u/WittyStick May 01 '25 edited May 01 '25
Avoid syntax sugar. In particular things like
(define (foo x y) ...)instead of(define foo (lambda (x y) ...)).defineitself is effectful - it mutates the environment, so we can scrap it, which leaves use needing to write out(lambda (x y) ...)anyway. With nodefine, we're basically left with various forms ofletto make bindings. In particular,letrec,letrec*or some equivalent will be necessary to do anything practical.We would need make the environments immutable. This basically means the evaluator goes from being
(expr env) -> exprto(expr, env) -> (expr, env). We consume the current environment and return a new environment that the next expression uses for its evaluation. We could then reintroduce an alternativedefinewhich instead of mutating the environment, returns a new one which the next expression is evaluated in.This raises difficulty with defining recursive functions. If we try:
(define fact (lambda (n) (if (< n 1) 1 (* n (fact (- n 1)))))), then it has the issue that the bindingfactdoes not exist in the environment of the lambda - it only exists in the new environment produced bydefine, which only exists after the lambda is defined, so we need to useletrec, or something more primitive like(define fact (label fact (lambda ....))).