Pharen is a Lisp that compiles to PHP, with macros, lexical closures, and more parentheses.
(fn greet-person (name)
(. "Hello " name "!"))
(prn (greet-person "visitor"))
; => Hello visitor!pharen.repl> (map (* 2) [1 2 3 4])
[2 4 6 8](fn factorial (n)
(if (zero? n)
1
(* n (factorial (dec n)))))pharen.repl> ({:foo "bar" 123 :456} "foo")
"bar"Get it
Download Pharen
Features (click to expand)
Macros
Lisp-style macros allow manipulation of code as lists at compile time, enabling the creation of new special forms.
(defmacro when (condition &body)
'(if ~condition
(do
~@body)
NULL))Closures
Everything is lexically scoped, unlike in PHP there is no `use` keyword and manual management of captured variables.
(fn make-greeter (greeting)
(lambda (name)
(. greeting " " name)))
((make-greeter "Hello") "World!")
; => Hello World!OOP and Namespace Integration
Work with or create new objects and namespaces, making integration into existing codebases possible. Here is an example derived from the Laravel docs.
(ns laravel-app.pharen)
(->
(:: Route (get "user/{name}"
(lambda ()
"Users!")))
(where "name" "[A-Za-z]+")