FUNCTIONAL LANGUAGES
Functional programming is not language specific. However, certain languages have been around in that space for a long time, influencing the evolution of functional programming approaches just as much as they were themselves influenced by those approaches to begin with. The largest parts of this book contain examples only in C#, but it can be useful to have at least an impression of the languages that have been used traditionally for functional programming, or which have evolved since the early days with functional programming as a primary focus.
Here are two simple functions written in LISP:
(defun calcLine (ch col line maxp)
(let
((tch (if (= col (- maxp line)) (cons ch nil) (cons 46 nil))))
(if (= col maxp) tch (append (append tch (calcLine ch (+ col 1) line maxp)) tch))
)
)
(defun calcLines (line maxp)
(let*
((ch (+ line (char-int #\A)))
(l (append (calcLine ch 0 line maxp) (cons 10 nil)))
)
(if (= line maxp) l (append (append l (calcLines (+ line 1) maxp)) l))
)
)
The dialect used here is Common Lisp, one of the main dialects of LISP. It is not important to understand precisely what this code snippet does. A much more interesting aspect of the LISP family of dialects is the structure and the syntactic simplicity exhibited. Arguably, LISP’s Scheme dialects enforce this notion further than Common Lisp, Scheme being an extremely simple language with very strong extensibility features. But the general ideas become ...
Get Functional Programming in C#: Classic Programming Techniques for Modern Projects now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.