<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title>Chemaclass - phel</title><subtitle>Tech Lead sharing practical insights on software craftsmanship, TDD, leadership, Bitcoin, and AI. Blog posts, book summaries, and conference talks.</subtitle><link rel="self" type="application/atom+xml" href="https://chemaclass.com/tags/phel/atom.xml"/><link rel="alternate" type="text/html" href="https://chemaclass.com"/><generator uri="https://www.getzola.org/">Zola</generator><updated>2021-02-01T00:00:00+00:00</updated><id>https://chemaclass.com/tags/phel/atom.xml</id><entry xml:lang="en"><title>Phel: The Lisp That Compiles to PHP</title><subtitle>A new functional language with full interoperability with PHP</subtitle><category term="phel" scheme="https://chemaclass.com/tags/phel/" label="Phel"/><category term="php" scheme="https://chemaclass.com/tags/php/" label="Php"/><category term="open-source" scheme="https://chemaclass.com/tags/open-source/" label="Open Source"/><category term="software-design" scheme="https://chemaclass.com/tags/software-design/" label="Software Design"/><published>2021-02-01T00:00:00+00:00</published><updated>2021-02-01T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/phel-first-release/"/><id>https://chemaclass.com/blog/phel-first-release/</id><summary type="html">The new Functional Programming language build-in for PHP.</summary><content type="html">&lt;p>A new Functional Programming language built-in on the PHP ecosystem.&lt;/p>
&lt;span id="continue-reading">&lt;/span>&lt;h2 id="the-phel-language">The Phel Language
&lt;a class="heading-anchor" href="#the-phel-language" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Phel is a Functional Programming (&lt;a rel="external" href="https://en.wikipedia.org/wiki/Functional_programming">FP&lt;/a>) language that compiles to PHP. It is a dialect of &lt;a rel="external" href="https://en.wikipedia.org/wiki/Lisp_(programming_language)">Lisp&lt;/a> inspired by Clojure and Janet.&lt;/p>
&lt;h2 id="features">Features
&lt;a class="heading-anchor" href="#features" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>Built on PHP’s ecosystem&lt;/li>
&lt;li>Good error reporting&lt;/li>
&lt;li>Different Datastructures (Arrays, Tables, and Tuples)&lt;/li>
&lt;li>Macros&lt;/li>
&lt;li>Recursive functions&lt;/li>
&lt;li>Powerful but simple Syntax&lt;/li>
&lt;li>REPL&lt;/li>
&lt;/ul>
&lt;h2 id="why-phel">Why Phel?
&lt;a class="heading-anchor" href="#why-phel" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Phel is a creation of Jens Haase, and as he mentions on the website, “it is the result of many &lt;a rel="external" href="https://phel-lang.org/blog/functional-programming-in-php">failed attempts to do functional programming in PHP&lt;/a>”. He was looking for something with these characteristics:&lt;/p>
&lt;ul>
&lt;li>A LISP-inspired&lt;/li>
&lt;li>Functional Programming language&lt;/li>
&lt;li>That runs on cheap hosting providers&lt;/li>
&lt;li>It is easy to write and debug&lt;/li>
&lt;/ul>
&lt;p>From my point, it was ending May 2020 when I finished the
book &lt;a href="/readings/7-languages-in-7-weeks/">Seven Languages in Seven Weeks&lt;/a>, in which I learned the basics of Prolog, Erlang,
Clojure, Haskell… I even created a &lt;a rel="external" href="https://github.com/Chemaclass/7LangIn7Weeks">repository in GitHub&lt;/a> to store my
progress over the weeks with these learnings.&lt;/p>
&lt;p>Suddenly, one day beginning of June 2020, I saw a post in Reddit’s PHP official channel, with a message of someone
mentioning this “&lt;strong>Phel&lt;/strong>” project, claiming to be a &lt;strong>“functional programming language” written in PHP&lt;/strong>!&lt;/p>
&lt;p>I’ve worked 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 &lt;strong>PHP 7.4&lt;/strong> sounded really exciting. I decided to take a look at it. I wanted to see the code.&lt;/p>
&lt;p>The fresh readings from &lt;a rel="external" href="https://x.com/matthiasnoback">Mathias NoBack&lt;/a> books such
as &lt;a href="/readings/object-design-style-guide">Object Design Style Guide&lt;/a>,
and &lt;a href="/readings/advance-web-application-architecture/">Advanced Web Application Architecture&lt;/a>, 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.&lt;/p>
&lt;p>My first commit was done on 6 June 2020, and since then I’ve been dedicating a little time each day during my free
hours to its development.
It helps me to learn more about FP, languages’ internal design, and best practices on testing and software design
architecture in general.&lt;/p>
&lt;p>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.&lt;/p>
&lt;h2 id="example-of-phel-code">Example of Phel code
&lt;a class="heading-anchor" href="#example-of-phel-code" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>The following example gives a short impression of how Phel looks like:&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="plain">&lt;span class="giallo-l">&lt;span># Define a namespace&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>(ns my\example)&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span># Define a variable with name &amp;quot;my-name&amp;quot; and value &amp;quot;world&amp;quot;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>(def my-name &amp;quot;world&amp;quot;)&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span># Define a func with name &amp;quot;print-name&amp;quot; and one argument&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>(defn print-name [your-name]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> (print &amp;quot;hello&amp;quot; your-name))&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span># Call the function&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>(print-name my-name)&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;h2 id="current-status-of-phel">Current status of Phel
&lt;a class="heading-anchor" href="#current-status-of-phel" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>We prepared an easy &lt;a rel="external" href="https://phel-lang.org/documentation/getting-started/">Getting Started Guide&lt;/a>&lt;/li>
&lt;li>We prepared an easy GitHub Repository with a &lt;a rel="external" href="https://github.com/phel-lang/phel-scaffolding">Phel Scaffolding Template&lt;/a>&lt;/li>
&lt;li>We just released the first official version: &lt;a rel="external" href="https://github.com/phel-lang/phel-lang/tags">0.1.0&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>Check out the official website with all documentation: &lt;a rel="external" href="https://phel-lang.org/">https://phel-lang.org/&lt;/a>&lt;/p>
&lt;hr />
&lt;h3 id="also-recommended">Also recommended
&lt;a class="heading-anchor" href="#also-recommended" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>&lt;a rel="external" href="https://jesusvalera.dev/functional-programming-with-phel/">Functional Programming with Phel - JesusValera&lt;/a>&lt;/li>
&lt;/ul></content></entry></feed>