Phel: the Lisp that compiles to PHP π
Jose Maria Valera Reales
Posted on February 1, 2021
The new functional language. Fully interoperable with PHP π
The Phel Language
Phel is a Functional Programming (FP) language that compiles to PHP. It is a dialect of Lisp inspired by Clojure and Janet.
Features
- Built on PHPβs ecosystem
- Good error reporting
- Different Datastructures (Arrays, Tables, and Tuples)
- Macros
- Recursive functions
- Powerful but simple Syntax
- REPL
Why Phel?
Phel is a creation of Jens Haase, and as he mentions on the website, βit is the result of many failed attempts to do functional programming in PHPβ. He was looking for something with these characteristics:
- A LISP-inspired
- Functional Programming language
- That runs on cheap hosting providers
- And is easy to write and debug
From my point, it was ending May 2020 when I finished the book βSeven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languagesβ, in which I learned a bit of Prolog, Erlang, Clojure, Haskellβ¦ I even created a repository in Github to store my progress over the weeks with these learnings.
Suddenly, one day beginning of June 2020, I saw a post in Reddit's PHP official channel, with a message of someone mentioning this βPhelβ project, claiming to be a βfunctional programming language written in PHPβ! (or something like that).
I work with PHP for around 8 years so far, and I always try to combine OOP with FP as much as possible (because I believe both paradigms are better combined; they are not necessarily exclusive), and a new dialect of Lisp fully written in native PHP 7.4 sounded really exciting. I decided to take a look at it. I wanted to see the code.
The fresh readings from Mathias NoBack books such as Object Design Style Guide, Principles of Package Design, and Advanced Web Application Architecture, gave me the courage to try out what I learned and put it for real in a project. This was (and still is) a beautiful challenge, which helps me to test myself and grow professionally at the same time.
My first commit was done on 6 June 2020, and since then I work on this project a bit (almost) every day in my free time. It helps me to learn more about FP, languages internal design, and best practices on testing and software design architecture in general.
I started applying minor changes until I ended refactoring the whole compiler structure (among other things) in order to make the modules easier to read and understand. Psalm, strict types, good test coverage, unifying code style⦠These were some of my favorite topics.
Example of Phel code
The following example gives a short impression of how Phel looks like:
# Define a namespace
(ns my\example)
# Define a variable with name "my-name" and value "world"
(def my-name "world")
# Define a func with name "print-name" and one argument "your-name"
(defn print-name [your-name]
(print "hello" your-name))
# Call the function
(print-name my-name)
Current status of Phel
- We have an open Gitter Community where we help each other
- We prepared an easy Getting Started Guide
- We prepared an easy Github Repository with a Phel Scaffolding Template
- We just released the first official version: 0.1.0
Check out the official website with all documentation of the Phel Language:
Also recommended
Originally written in https://chemaclass.es/blog/phel-first-release/
Posted on February 1, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.