6 ms·
Phel: A language inspired by Clojure that compiles to PHP
- jetti 6y agoI'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.
- rcarmo 6y agoI 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).
- Zababa 6y agoPHP 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.php https://www.php.net/manual/en/language.namespaces.rationale.... [2]: https://phel-lang.org/documentation/namespaces/ https://phel-lang.org/documentation/namespaces/
- cutler 6y agoDisagree. It breaks the Clojure idiom. Please reconsider.
- Zelphyr 6y agoIsn'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.
- jenshaase 6y agoCreator 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.
- progre 6y agoIs there a way to drop out to the REPL from a running script? Kinda like settrace in Python
- jenshaase 6y agoNo, 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"
- progre 6y agoNice, 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.
- progre 6y agoIs 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.
- jenshaase 6y agoPhel 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.
- tasubotadas 6y agoWhy?
- 6y ago
- slifin 6y agoAs 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
- jenshaase 6y agoCreator 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.
- DNied 6y agoVery 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.
- progre 6y agoI'm no lisper but I think arguments are always defined in an array?
- capableweb 6y agoClearly 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.
- progre 6y agoAlways 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)
- richeyryan 6y agoIt's a Clojure-ism. The arguments are passed as a vector. https://clojure.org/guides/learn/functions https://clojure.org/guides/learn/functions
- prionassembly 6y agoObligatory reference to Hy, a language sort of inspired by Clojure that compiles to Python.
- soheil 6y agoIs compile the right word here? Is this not an interpreter?
- valw 6y agoCompiling 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.
- soheil 6y agoSo as someone who has mastered those notions is this compiling, interpreting or neither?
- ezrast 6y agoPhel 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)
- lambdaba 6y agoBit tangential but there's a way to run Clojure code as CGI scripts with Babashka (Clojure for shell scripting): https://eccentric-j.com/blog/clojure-like-its-php.html https://eccentric-j.com/blog/clojure-like-its-php.html
- dalu 6y agoWhy? PHP? Of all scripting languages. Does not compute. Does not compute.
- yogthos 6y agoPHP 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.