r/functionalprogramming • u/Frere_de_la_Quote • Feb 04 '26
FP Doing AI outside of Python
Machine Learning in Python
What I'm going to write here could get me banished from hundreds of forums all over the place. I know I take terrible risks but people need to know: Python sucks at ML.
I said it...
Programming in Python is like claiming you are doing the Tour de France, but you're cycling on a fixed bike on top of a truck. Worse, your aerodynamic drag is so bad that you prevent the truck from going full speed... Not sure your pedaling adds anything to the whole system.
This is exactly what is going on. You think you're implementing stuff in Python, but you're just sucking out some fresh blood from underlying libraries in C or in Rust... Most of the time, Python sits idle while waiting for the big boys to do the actual work, because when you are using numpy or PyTorch, everything happens outside the VM.
AI
I want to join the happy few who are doing stuff in AI. I want to be part of the churn. But really, Python? People claim that it is such an easy language... You read it as if it was written in English... Ok.. Why do I need to read the doc over and over again to understand what **kwargs do?
What is that:
mlx.core.multiply(out_glu, mlx.core.add(x_linear_clamped, mlx.core.array(1.0)))
It seems that Lisp stabbed Python in the back...
What can I do?
LispE
My name is not Frankenstein, but LispE is still my creature, a chimera made out of flesh torn off Haskell and APL, a monstrosity that does not respect the true linked lists, which are so dear to real lispians.
LispE is implemented with arrays, which not only enables APL-style vectorized operations but also plays nicely with functional patterns like map/filter/take/drop without the overhead of list traversal. There is full documentation about the language here.
By the way, the Python thing can now be implemented in LispE directly:
(mlx_multiply out_glu . mlx_add x_linear_clamped . mlx_array 1.0)The last argument of each function can be inserted with a . to get rid of some parentheses.
Note: LispE is fully Open Source with a BSD-3 license, which is very permissive. My only interest here is to provide something a bit different, my personal take on Lisp, but my true reward is the joy of seeing people use my tools. It is a little more than a pet project, but it is far from being a corporate thingy.
Libs
Now, I have to present you the real McCoy, I mean the real stuff that I have been implementing for LispE. Cling to your chair, because I have worked very hard at making Claude Code sweat over these libraries:
- lispe_torch: based on the remarkable libtorch library — the C++ engine that powers PyTorch under the hood. It exposes more than 200 functions, including SentencePiece.
- lispe_tiktoken: the OpenAI tokenizer, which is used now by a lot of models.
- lispe_mlx: the Apple framework for AI on their GPUs. Thanks to MLX's unified memory, no data cloning needed.
- lispe_gguf: the encapsulation of llama.cpp that powers Ollama.
It's still evolving, but it's production-ready for real AI work. Furthermore, it's fully compatible with PyTorch and models from HuggingFace, Ollama, or LM-Studio. You can fine-tune a model with LispE and save it in PyTorch format. You won't be stranded on an island here.
Plenty of docs and examples
You'll find plenty of examples and documentation in each of these directories.
For instance, there is a chat example with lispe_gguf, which is fun and contains only a few lines of code. You will also discover that inference can be faster with these libraries. LoRA fine-tuning is 35% faster than the equivalent Python code on my M4 Max...
Everything can be recompiled and tailored to your needs. Even the C++ code is friendly here...
Note that I already provide binaries for Mac OS.
If you have any questions or any problems, please feel free to ask me, or drop an issue on my GitHub.
View all comments
Show parent comment
3
u/Inconstant_Moo Feb 05 '26 edited Feb 05 '26
Perhaps you should try explaining the actual differences between your project and Python then.
I've been looking at the docs, and they're all jumbled up, there's no sense to their arrangement. For example you have an introduction to lists containing implementation details of interest only to yourself, then you have an essay on tail-call recursion which starts off by explaining at length what a Lisp is. Then we move on to a comparison of LispE and Python for speed, and then we get to learn about hashmaps. Mostly again about their internals.
"Maybe a full Wiki page is also a bit too much to describe an instruction as simple and obvious as extract", you write in your 1,000+ word essay on a single string-handing function which begins with your reminiscences of learning Python in the early '00s and ends with you in equally reminiscent mood about another language you once invented. Yes, that's a bit too much.
However, I've been struggling through all this and the project strikes me as too big and too redundant. You have all those built-in functions. Then you have APL-style built-in functions, except you still have to write them with Lispian parentheses, and they aren't point-free, so it's not really like APL at all, it sacrifices all the virtues of the language but gives you its weird symbols as operators:
(defun gol8(⍵) ((λ(⍺) (| (& (== ⍺ 4) r) (== ⍺ 3))) (⌿ '+ (⌿ '+ (° (λ (x ⍺) (⊖ ⍺ x)) '(1 0 -1) (↑ (λ (x) (⌽ ⍵ x)) '(1 0 -1))))))).That was your version of the Game of Life. Here it is in actual APL:
life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵}.Then you have Haskell-style built-in functions which are fake because you don't actually have lazy lists, so you have to make people write stuff like:
(take 10 (repeat 5))with a footnote saying that you must userepeatwithtake. Because you can't actually make a functionrepeatwhich returns an infinite list but you've kludged the syntax so that people can kinda pretend that one exists. Sometimes, under certain special circumstances.You have your own non-standard version of Prolog as part of your core language apparently for people who are fatigued by writing
elifand would like a change.When you make an ontology a built-in type, or even a standard library, you're committing to something where the users may well mostly want to use a different library because it has different features or a better API or because people discover better ways to do ontologies or whatever.
Some things in the core should be standard libraries. Why am I writing
file_closeand notfile.close? It's not more concise, it just clutters things up if I have a tool that depends on looking at the namespace.And I've only looked at a fraction of it. There's this huge proliferation of largely useless or positively harmful features in the core language that belong in libraries, and many of them not even standard libraries, because most people would never want to use them for anything.
Bizarrely, the E in ListE stands for elémentaire, and the README explicitly boasts that the language is "compact". It has a Prolog in it. It has around 400 built-in functions. (Mine has 40. 11 are basic arithmetic and 16 are to construct values or convert them from type to type.)
There were some things I couldn't find. What's your nearest approach to offering me a good old-fashioned
forloop? And what do I need to do if I want to wrap a C or C++ library myself?There seems to be a decent idea here, but it's obscured by a language bloated with misfeatures, and documents loaded with unnecessary details and some extremely ill-judged attempts at humor.
I suggest:
At that point it might interest the sort of people who are interested in that kind of thing. Until then, you seem rather to be standing in your own light. Try and know your audience. What do they want from a language, and what do they want to know about it?