Hacker News new | ask | show | jobs
by Warwolt 1459 days ago
Eh, isn't it a bit of a stretch to claim you can program functionally in C? You can mimic it, but without easy closures you can't follow _any_ functional programming patterns that are built on composing functions into new ones in expressions (e.g. binding the operation argument to a fold)

C is great, and it would be cool to see something that is similarly close to the instruction set but has functions as values

2 comments

There is a book about it [0], you can download it here [1]. It uses SML to teach FP. I did the exercises on the train in Termux and Vim.

[0] https://www.semanticscholar.org/paper/Functional-C-Hartel-Mu...

[1] https://ris.utwente.nl/ws/portalfiles/portal/5128727/book.pd...

(edit) add download link and background.

A functional programming language is a programming language in which functions are first class citizens. C is such a language.

Of course there are many programming patterns that are in more acceptable functional programming languages than C. Whether a programming language is considered functional is not the same as which patterns are supported in the language.

Your idea of what FP means is completely nonstandard.

For the record, there is not one accepted definition, but we can get close by saying that FP languages are those based on lambda calculus as their semantics core. And the primary mechanism in lambda calculus is variable capture (as done in closures).

C is based on the Von-Neumann model and has absolutely nothing to do with the lambda calculus. No reasonable PL expert considers it functional.