[HN Gopher] Phel: A language inspired by Clojure that compiles t...
       ___________________________________________________________________
        
       Phel: A language inspired by Clojure that compiles to PHP
        
       Author : yogthos
       Score  : 75 points
       Date   : 2021-02-18 19:04 UTC (1 days ago)
        
 (HTM) web link (phel-lang.org)
 (TXT) w3m dump (phel-lang.org)
        
       | soheil wrote:
       | Is compile the right word here? Is this not an interpreter?
        
         | valw wrote:
         | 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.
        
           | soheil wrote:
           | So as someone who has mastered those notions is this
           | compiling, interpreting or neither?
        
             | ezrast wrote:
             | 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)
        
       | DNied wrote:
       | 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.
        
         | progre wrote:
         | I'm no lisper but I think arguments are always defined in an
         | array?
        
           | capableweb wrote:
           | 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.
        
             | progre wrote:
             | 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)
        
         | richeyryan wrote:
         | It's a Clojure-ism. The arguments are passed as a vector.
         | 
         | https://clojure.org/guides/learn/functions
        
       | slifin wrote:
       | 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
        
         | jenshaase wrote:
         | 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.
        
       | jetti wrote:
       | 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.
        
       | rcarmo wrote:
       | 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).
        
         | Zababa wrote:
         | 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/
        
           | Zelphyr wrote:
           | 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.
        
           | cutler wrote:
           | Disagree. It breaks the Clojure idiom. Please reconsider.
        
       | prionassembly wrote:
       | Obligatory reference to Hy, a language sort of inspired by
       | Clojure that compiles to Python.
        
       | jenshaase wrote:
       | 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.
        
         | raspasov wrote:
         | 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.
        
         | progre wrote:
         | 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.
        
           | jenshaase wrote:
           | 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.
        
         | tasubotadas wrote:
         | Why?
        
           | capableweb wrote:
           | 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
        
           | jenshaase wrote:
           | 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/
        
           | trizic wrote:
           | 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.
        
         | uDontKnowMe wrote:
         | 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)?
        
           | jenshaase wrote:
           | 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.
        
         | progre wrote:
         | Is there a way to drop out to the REPL from a running script?
         | Kinda like settrace in Python
        
           | jenshaase wrote:
           | 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"
        
             | progre wrote:
             | 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.
        
       | lambdaba wrote:
       | Bit 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
        
       ___________________________________________________________________
       (page generated 2021-02-19 23:02 UTC)