34 comments

[ 5.4 ms ] story [ 71.6 ms ] thread
I'm definitely going to check this out. I was looking for a Lisp that compiles to PHP after using, and enjoying, Clojure at work. I was going to actually try and make one myself but then got distracted and moved on to something else.
I like the idea, but (and this is a minor niggle) the use of a backslash for namespacing completely breaks my visual parser. I keep expecting it to be an escape (or a Windows path, which I never see even though I am working on a PC most of the time because it was mostly eradicated from the GUI and I work in WSL).
PHP already uses the backlash for namespacing [1]. Since the language is built on top of PHP, it makes sense to have namespaces look like PHP namespaces. It also avoid using a different syntax for importing PHP code [2].

[1]: https://www.php.net/manual/en/language.namespaces.rationale....

[2]: https://phel-lang.org/documentation/namespaces/

Disagree. It breaks the Clojure idiom. Please reconsider.
Isn't the whole point of Phel to provide Clojure-like syntax? in which case, the dot operator should be used for namespaces. If I recall, the backslash for namespacing was the lesser evil even when PHP implemented it at the time.
As a frequent user of each of these languages this appears quite cool

The thing putting me off is both PHP and Clojure have mature/maturing tooling that I suspect would be unusable here

On the PHP side there's LSP servers, xdebug 3, PHPStorm (the only reliable client for xdebug I've found) xhprof, phan etc

On the Clojure side there's Cider, Cursive, Structural editing tools, Clj-kondo, Clojure-lsp

I love dynamic languages but I wouldn't use a new one without a few good static analysers and deep debuggers

Creator here: That's a problem of all new languages. There is not much in terms of libraries, tools or documentation. I started Phel last year and published a first version recently. I have a few plans to build some good tooling around Phel but that takes times.
Very interesting! Maybe preprocessors really are the way to go for PHP, even if it were just for ironing out its inconsistencies (not to mention implementing a whole new language on top of it, as in this case).

But why those square brackets for argument lists? That seems unnecessary.

I'm no lisper but I think arguments are always defined in an array?
Clearly not a lisper :D But no worries.

No, it's not a array, it's a vector.

And no it's not always defined as a vector, it's a particular trait of Clojure. In Common Lisp you'd use a list "(my arguments)" instead, for example.

Always happy to learn, thank you! Clojure is my only real venture in to lisp land (I know some don't consider Clojure lispy enough to be a real lisp)
Creator here: I didn't expected this to be linked here.

Feel free to asked any questions about the project and I try to answer them.

Is there a way to drop out to the REPL from a running script? Kinda like settrace in Python
No, this is not possible. However, with a better editor support it could be possible to send expression from the editor to the REPL. That way you can do "REPL Driven Development"
Nice, should be easy in emacs. I'll try it! I'm currently on step 7 (quotes) of the MAL guide and my implementation lang is PHP, so this project hits close to home for me.
Is the Phel code actually compiled to PHP? From the example in the "Getting started section" it looks like the generated php is a wrapper that loads the interpreter.
Phel code is compiled to PHP code (in terms of a string, not bytecode). However, the PHP Code is than interpreted by PHP using PHP's eval function.
Why?
I know it's fashion to hate and question anything related to PHP. But the answer to this particular question is on the website that got linked in this submission. Here it is again:

> Why Phel?

> Phel is a result of my failed attempts to do functional programming in PHP. Basically I wanted:

> - A LISP-inspired

> - functional programming language

> - that runs on cheap hosting providers

> - and is easy to write and debug

I'm a long term PHP developer and I always liked functional programming. However, PHP is not so good in it [1].

I think in general, PHP's shared nothing architecture is a very good fit for functional programming. You get a HTTP Request and return a HTTP Response.

[1] https://phel-lang.org/blog/functional-programming-in-php/

The cheap hosting provider is possible by PHP only being loaded into memory when needed to run. So you can have tons code ready to run on disk with no performance impact.

So it is definitely nice to see other languages compiled to PHP to make use of the cheap shared hosts.

I don't know Clojure or PHP completely fluently, so sorry if it's a stupid question, but why did you want to create a new language inspired by Clojure rather than a dialect of Clojure itself for PHP (in the same way as there is ClojureScript for JS and Clojure.NET for .NET)?
I'm working on building a good language to target the PHP environment. There are a lot of feature that I can borrow from Clojure but not all of them are need. At some points I even go in another direction. I want to keep this freedom in order to build the best language that targets PHP.
This is very cool. My two favorite languages are Clojure and PHP.

Do you implement persistent data structures? (totally cool if not, just curious)

Is Phel a subset/superset of Clojure? Perhaps a list of "differences from Clojure" vs "implemented features" would be useful for people looking at Phel.

I currently working on persistent data structures. If I can make them fast enough they will be added.
Obligatory reference to Hy, a language sort of inspired by Clojure that compiles to Python.
Is compile the right word here? Is this not an interpreter?
Compiling means translating a program from one representation to another. Executing a program always involves a combination of compilation and interpretation (example: Java usually runs by compiling it to Java bytecode, which is then interpreted by a Java Virtual Machine).

The widespread belief that compilation and interpretation are mutually exclusive is unfortunate, as is the artificial distinction between 'compiling' and 'transpiling' we sometimes hear, because these misconceptions show that programmers today are a bit confused about the essence of how programs actually run. It's a pity we don't have more cultural interest in such things, because mastering those notions can really improve software engineering.

So as someone who has mastered those notions is this compiling, interpreting or neither?
Phel is a compiler, because its output is code. PHP is an interpreter, because its "output" is the effects of executing code.

(edit: to the GP's point, PHP does contain a compiler within it, because it translates source to bytecode as part of execution, but that's an implementation detail. As a product it is strictly an interpreter)

Why? PHP? Of all scripting languages. Does not compute. Does not compute.
PHP is just a compile target here. The value it provides is that there is a lot of cheap hosting available. So, you can leverage these hosting options while using a sensible language.