scriptor / pharen Goto Github PK
View Code? Open in Web Editor NEWLisp to PHP Compiler
Home Page: http://pharen.org
License: BSD 3-Clause "New" or "Revised" License
Lisp to PHP Compiler
Home Page: http://pharen.org
License: BSD 3-Clause "New" or "Revised" License
i try to work for support of namespace php 5.3. there is a problem with actual code generation. At the top of file php generated is make require this code:
require_once('/Users/Francesco/github_projects/pharen/lang.php');
Lexical::$scopes['prova'] = array();
for using namespace the definition of the namespace should be before this commands. but this nedd to modify the code of pharen in compile function
i get this error
Fatal error: Cannot redeclare prova__lambdafunc8() (previously declared in /Users/Francesco/Downloads/pharen/pharen.php(1183) : eval()'d code:2) in /Users/Francesco/Downloads/pharen/pharen.php(1183) : eval()'d code on line 2
in file prova.phn with this macro that has a map and lambda
(defmacro respond-to (&condx)
(map (lambda (el) (print-r el)) condx)
'(+ 1 1)
)
(respond-to
(json (lambda ()))
(xml (lambda ())
(html (lambda ()))
)
Currently when a macro call is evaluated it is passed the syntax tree of its arguments. This should be fixed so that parsing is only done when the code is about to be evaluated. Macros should take regular lists as their arguments.
when i try this macro
(defmacro new-fn (name)
'(fn ~-name (print "Hello, world!")))
(new-fn "print-hello")
i obtain this as return in php:
<?php
require_once('/Users/Francesco/php/pharen/lang.php');
Lexical::$scopes['pharen_tests'] = array();
function print-hello($echo){
}
;
this is the version of php on my macosx:
PHP 5.2.8 (cli) (built: Feb 5 2009 21:21:13)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
Reference project: https://github.com/thinkadoo/lispy
What I expect to see when compiling lispy.phn is [$ pharen lispy.phn]
$__scope_id = Lexical::init_closure("_Users_nomad_Projects_lispy", 204);
$__scope_id = Lexical::init_closure("_Users_nomad_Projects_lispyerrorview", 204);
errorview is a rerefence to a (load file) from here
(fn IndexView (name path routes)
(load indexview)
(:done))
(fn BlogView (name path routes)
(load blogview)
(:done))
(fn CodeView (name path routes)
(load codeview)
(:done))
(fn ErrorView (name path routes)
(load errorview)
(:done))
make a file for every class node and make loading it dinamically
I didn't realize the IF statement requires two expressions and when I did, I changed to a WHEN. After I did this, I kept getting a segmentation fault when running pharen. I changed the code back to using IFs and I still ended up getting segmentation faults.
i have try to create a macro that returning a method with public access.
This is the example code in phn
(defmacro public_var (nm value)
'(access public (local ~nm ~value )))
(defmacro protected_var (nm value)
'(access protected (local ~nm ~value )))
(defmacro public-fn (nm args &body)
'(access public (fn ~-nm ~args
~@body
FALSE
)))
(class-extends Controller_Hello (Controller)
(public_var template "site")
(protected_var template2 "site")
(public-fn action_index ()
(local (-> this template message) "ciao")
)
)
and how result i get this php
<?php
require_once('/Users/Francesco/pharen2/pharen/lang.php');
Lexical::$scopes['oop'] = array();
class Controller_Hello extends Controller{
public $template = "site";
protected $template2 = "site";
public function action_index(){
$this->template->message = $ciao;
return FALSE;
}
;
}
the error is Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /Users/Francesco/pharen2/pharen/examples/test/tests/oop.php on line 11
when the macro create the function it add a ; to the end of function that can't be put inside the body of class after the function, but in a normal function can be used
Hey, loving Pharen, and I'm currently working on a routing and templating engine written in Pharen FOR pharen, inspired by Slim.
What I want to know is the best way to deploy Pharen to a server. What needs to be where? Is there a way to "statically link" the pharen libraries into the compiled files, so the compiled PHP is the only thing that needs to be copied to the server to deploy?
Or, is it better to install Pharen in /var/ and access it through /var/www/ instead (what I'm doing locally now)
with this macro
(defmacro fn-generator-test (nm value)
'(fn ~-nm ()
(def stuff "foo")
(. stuff ~value)))
(fn-generator-test "generated_test_fn" "bar")
i have this error
Warning: Invalid argument supplied for foreach() in /Users/Francesco/Downloads/Scriptor-pharen-1266893/pharen.php on line 604
Notice: Trying to get property of non-object in /Users/Francesco/Downloads/Scriptor-pharen-1266893/pharen.php on line 2055
Notice: Trying to get property of non-object in /Users/Francesco/Downloads/Scriptor-pharen-1266893/pharen.php on line 2016
Notice: Trying to get property of non-object in /Users/Francesco/Downloads/Scriptor-pharen-1266893/pharen.php on line 2018
Warning: get_class() expects parameter 1 to be object, string given in /Users/Francesco/Downloads/Scriptor-pharen-1266893/pharen.php on line 2043
Notice: Trying to get property of non-object in /Users/Francesco/Downloads/Scriptor-pharen-1266893/pharen.php on line 2055
Notice: Trying to get property of non-object in /Users/Francesco/Downloads/Scriptor-pharen-1266893/pharen.php on line 2016
Notice: Trying to get property of non-object in /Users/Francesco/Downloads/Scriptor-pharen-1266893/pharen.php on line 2018
ltei
I found this while trying to play with repl.phn
-- it doesn't actually loop (so I guess it's just a REP
, not a REPL
...) Looking at the generated code, the problem is evident: in the middle of the while
loop that was generated, the compiler also generated the line
return fwrite(STDOUT, (evaluate($code) . "\n"));
which breaks out of the loop.
Conceptually, if an expression is only being evaluated for its side-effects, it shouldn't try to return
, at least not inside code that is subject to tail-call optimization. I'm not entirely sure of a good way to address this yet, but one idea would be to assign the result of evaluation to a local variable, and not generate return
until the end of the function (at which point you just return that local variable.)
Hello, http://www.pharen.org/repl.html is throwing 404 not found.
I took a look at https://github.com/Scriptor/pharen/tree/gh-pages and there's no repl.markdown
.
See ya!
a support fonr Hygienic macro can avoid error in definition of variable for local scope
I made a basic web site with Pharen and really like using it so far.
I hope to get pointers on how one would do it better.
Here it is https://github.com/thinkadoo/lispy
generate class,interface, methods, multimethods ecc....
Hello again!
I've noticed that lang.php in the root directory, when it comes from the repository, has a hard-coded require_once for lexical.php. However, removing and recompiling lang.php from lang.phn results in it including itself, rather than lexical.php. As a result, no compiled files have access to the static methods of the Lexical class, because it is not defined in any of their scopes (and because lang.php is included by every compiled file [and it includes an include for itself]).
I'm working on resolving this issue, but since Lexical::$scopes is referred to before any of a file's compiled content is written out to the .php file, it'll take a bit more time.
Thanks!
In the lib folder, the included php files have the line:
require_once('/Applications/MAMP/htdocs/pharen/lang.php');
which breaks on non OSX platforms. It seems like you do not want to include these in the repository, but rather have the installer call pharen on the necessary phn files.
(defmacro sum (a b)
(define x 3)
'(echo (+ ~a ~b ~x))
)
(sum 1 2)
return
Notice: Undefined variable: x in /Users/Francesco/php/pharen/pharen.php(1082) : eval()'d code on line 5
nagashima-2:pharen Francesco$ php bin/pharen examples/test/pharen_tests.phn
Notice: Undefined variable: x in /Users/Francesco/php/pharen/pharen.php(1082) : eval()'d code on line 5
I don't currently see a way to specify types to function arguments. Instead of this:
function (MyObject $object, array $myArray)
I can only get this:
function ($object, $myArray)
Am I just missing something, or is this functionality not present?
support for closure in php 5.3 with function
and for namespace
Should be nice create macro from oop ( classes, interfaces, instance creation).
It would be nice if the generated code could inject all of its functions into a class, calling all the methods as $this->fn_name().
The rationale is that the generated class could then be more easily embedded inside another application.
Is this something that would be a huge amount of work?
How do I define optional function arguments that include default values if not passed in?
Also, defining a top level namespace?
should be nice having support for macro reader and for macro igienic con symbol generator like in clojure with character #
Maybe it's just my problem, but in windows 8, php 5.3 pharen doesn't work
Hey there, loving Pharen so far, lots of fun!
I'm trying to tie it to the Slim framework, so far so good, but when defining routes I can use php like this:
$app->get("/", function() {
// Do some stuff here
});
And as far as I can tell, there is no way of doing that in Pharen. If there isn't, that's okay, close this issue, as I can just name the function anyway, but I was curious.
I am trying to use pharen to write a module for the Drupal CMS framework. I am working on writing some macros that will make it easier to write code that follows the proper coding conventions for a Drupal module. One thing that would be nice is if there were some sort of reader macros available. Do you have any plans for this?
The Pharen button in the gh-pages links to the root "Hello World" page, as opposed to /pharen. Also the tutorial link links to http://scriptor.github.io/tutorial.html not http://scriptor.github.io/pharen/tutorial.html
I'll have a look at this later, but basically the root is being defined as http://scriptor.github.io not http://scriptor.github.io/pharen.
with this macro
(defmacro make-list (&args)
'[~@Args])
(make-list 1 2 3 4 5)
i have this error
Fatal error: Call to a member function compile() on a non-object in /Users/Francesco/Downloads/Scriptor-pharen-1266893/pharen.php on line 1418
with array inside a function is returned pharenvector
example
[1 2 3 4 5]
(sum [1 2 3 4 5])
is compiled to
use Pharen\Lexical as Lexical;
Lexical::$scopes['plambda'] = array();
array(1, 2, 3, 4, 5);
sum(\PharenVector::create_from_array(array(1, 2, 3, 4, 5)));
with ths macro
(defmacro when-test (c &body)
'(if ~c
(do
~@Body)
FALSE))
(when-test (== 2 2)
(. "line" 1)
"foobar")
i have this error
Notice: Undefined variable: flatten in /Users/Francesco/Downloads/Scriptor-pharen-452a373 2/pharen.php on line 1337
Warning: array_slice() expects parameter 1 to be array, null given in /Users/Francesco/Downloads/Scriptor-pharen-452a373 2/pharen.php on line 1337
Warning: array_merge(): Argument #2 is not an array in /Users/Francesco/Downloads/Scriptor-pharen-452a373 2/pharen.php on line 1337
Warning: array_shift() expects parameter 1 to be array, null given in /Users/Francesco/Downloads/Scriptor-pharen-452a373 2/pharen.php on line 2092
Fatal error: Class name must be a valid object or a string in /Users/Francesco/Downloads/Scriptor-pharen-452a373 2/pharen.php on line 2095
nagashima-2:Scriptor-pharen-452a373 2 Francesco$
What I am seeing is:
pharen (load file 2 (load file 3)) -- OK
pharen (load file 1(load file 2 )) -- OK
pharen (load file 1(load file 2 (load file 3))) -- BREAK
If I compile the file which in turn loads other files the (load file 1) link is broken
Reference project: https://github.com/thinkadoo/lispy
$pharen index.phn
; index.phn
(load header)
(load lispy)
(load footer)
// index.php
errorview is the last load link from level 2 to level 3 The only way to get around the problem is to remove the level 3 links in the level 2 doc temporarily and then compiling from level 1. Then to enable the level 2 links to level 3 but only compile the level 2 document, which is lispy.phn in this case.if i pass a dictionary to a macro like in this example
(defmacro xxx (dict)
'(do-something ~dict)
)
(xxx {#a 1 #b 2 #c 3})
the dictionary is not translated in array but in this
Lexical::$scopes['maps'] = array();
do_something(a(1, "b", 2, "c", 3));
if i pass the dict macro is correctly
(defmacro xxx (dict)
'(do-something ~dict)
)
(xxx (dict #a 1 #b 2 #c 3))
Lexical::$scopes['maps'] = array();
do_something(array("a" => 1, "b" => 2, "c" => 3));
The following code won't compile:
(defmacro with-database-connected (&body)
"Executes `body' with database connected. Connection is closed after execution."
'(do
(require "open_db.php")
~@body
(require "close_db.php")))
Error is:
Fatal error: Call to a member function compile_statement() on a non-object in [...]/pharen/pharen.php on line 1353
Removing "require"s solves the problem. The only way I can use "do" is to put no more than one statement inside it.
When I clone Pharen and follow the installation process outlined on http://scriptor.github.io/pharen/tutorial.html, I get the following error:
Fatal error: require_once(): Failed opening required '/Users/historium/pharen/lang.php' (include_path=...
This seems to be because the developer compiled the .pha files ahead of time, neglecting that this would only work on the developer's computer.
Hey! Pharen looks interesting, but I'm getting some compile errors:
(defmacro foreach (var args & body)
'(do @~body))
(foreach a b (echo a))
Gives:
Notice: Trying to get property of non-object in pharen.php on line 2620
Parse error: parse error, expecting `"identifier (T_STRING)"' or `'('' in pharen.php(2637) : eval()'d code on line 2
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'foreach' not found or invalid function name in pharen.php on line 1127
(defmacro foreach (var args & body)
'(do ~@body))
(foreach a b (echo a))
Gives: Fatal error: Call to a member function add_child() on a non-object in pharen.php on line 3987
Currently, the compiler can't handle unquoting the indexing syntax. The following Pharen code:
(defmacro foo (d)
'(~:d "foo"))
(print (foo {"foo" "bar"}))
Will generate the following PHP code:
<?php
require_once('/Applications/MAMP/htdocs/pharen/lang.php');
Lexical::$scopes['simple'] = array();
$__tmpfuncname2 = ;
print(is_string($__tmpfuncname2)?$__tmpfuncname2("foo"):$__tmpfuncname2[0]("foo", $__tmpfuncname2[1]));
Instead of recognizing it as indexing, it seems to think it is a non-conventional function call, which is why it's trying to create a temporary variable.
i am try to execute some code inside a macro first of release the expression. If i try to create an array inside the macro and transform that in a sequence for pass to the expression returned i get this error:
Warning: get_class() expects parameter 1 to be object, boolean given in /Users/Francesco/Downloads/Scriptor-pharen-35957ec/pharen.php on line 2278
Notice: Trying to get property of non-object in /Users/Francesco/Downloads/Scriptor-pharen-35957ec/pharen.php on line 2290
Notice: Trying to get property of non-object in /Users/Francesco/Downloads/Scriptor-pharen-35957ec/pharen.php on line 2251
Notice: Trying to get property of non-object in /Users/Francesco/Downloads/Scriptor-pharen-35957ec/pharen.php on line 2253
This is the code i use
(defmacro xxx (lst)
(def lst2 [1 2 3 4 5])
(def lst3 (:: PharenList (create_from_array lst2)))
'(+ ~lst3)
)
(xxx [1 2 3 4 5])
Hey all.
Loving the plambda functionality but I'd like to be able to "use" variables from an outside scope. See below for how it is used currently. It is very handy in PHP 5.3 and the Slim framework relies on it for certain things...
$app->get("/", function () use ($app) {
$app->doSomething();
}
What I propose is a syntax like the following:
(plambda [app] ()
(print-r app))
Where there is a list of variables either before or after the brackets. Or something similar.
I'd love to try and hack this in myself, but I'm struggling to work out how (currently looking at PlambdaDefNode)
the test func_calls.phn not pass.
The problem is for float numbers. This form (check (+ 1 2 3.1) 6.1)
is compiled in check((1 + 2 + 3\1), 6\1);
The code that generate this is here
$char_mappings = array(
'-'=>'_',
'?'=>'__question',
'!'=>'__exclam',
'*'=>'__star',
'.'=>'\\' //this convert 6.1 in 6\1
);
(defmacro x ()
(echo 444)
'(+ 1 2)
)
(defmacro y()
'(x)
)
i get:
with this code
(defmacro viewfactory (view)
'(:: View (factory ~view))
)
(local view (-> (viewfactory "page/3") (bind "content" content)))
(local (-> this request response) (-> view (render)))
is compiled in
Lexical::$scopes['oop'] = array();
$view = viewfactory("page/3")->bind("content", $content);
$this->request->response = $view->render();
macro viewfactory isn't expaned with ->
This example doesn't work on php 5.3 under Ubuntu.
i can compile it to new.php.
But it starts to work only if i comment in html.php
//namespace pharen\html;
//require_once('/home/mrbloom/pharen/lang.php');
//use Pharen\Lexical as Lexical;
//Lexical::$scopes['html'] = array();
Scriptor,
I was making some modifications to the Pharen lexer and wanted to avoid introducing any regression defects, so I checked out the tests in examples/test. However, pharen_tests.phn requires a file named "test.php". However, no such file exists in any directory in the repository.
Perhaps you have the file and simply forgot to add it to the repo? It would be great to have, otherwise I'll try to reverse engineer it and issue a pull request later.
Thanks,
Ryan
with this code:
(defmacro hook (name)
(def namefn (join "_" [ "test" name ]))
'(fn ~-namefn () (print "Hello, world!"))
)
(hook "perepola")
i obtain:
(or FALSE "string") should return "string" but returns 1.
It always returns 0 or 1, but should return 0 (FALSE) or the element that was not FALSE, so to make possible to use something like (print (or variable "default string")).
The following function should result in a PHP function that will exit in the first iteration of the loop generated by tail-recursion optimization.
(fn work ()
(let [foo "foo"]
(if (== foo "foo")
(foo)
(work)
However, the actual generated code is:
function work(){
while(1){
$foo = "foo";
if(($foo == "foo")){
foo();
}
}
}
Where it calls foo()
it should be return foo()
.
With an hash that compile many lambda , pharen compile in php a sequence of function nested, giving error of access of function:
this is the pharen code:
(def functions {
#fn1 (lambda (a b) (+ a b))
#fn2 (lambda (a b) (+ a b))
#fn3 (lambda (a b) (+ a b))
})
and this is the code php
Lexical::$scopes['prova'] = array();
$__scope_id = Lexical::init_closure("prova", 55);
function prova__lambdafunc9($a, $b, $__closure_id){
function prova__lambdafunc8($a, $b, $__closure_id){
function prova__lambdafunc7($a, $b, $__closure_id){
return $a + $b;
}
return $a + $b;
}
return $a + $b;
}
$functions = array("fn1" => array("prova__lambdafunc7", Lexical::get_closure_id("prova", Null)), "fn2" => array("prova__lambdafunc8", Lexical::get_closure_id("prova", Null)), "fn3" => array("prova__lambdafunc9", Lexical::get_closure_id("prova", Null)));
Lexical::bind_lexing("prova", 55, '$functions', $functions);
Hey there.
I'm currently writing a simple project definition and module definition macro in lang.phn
The idea is to encapsulate modules inside their own namespaces (or perhaps as subnamespaces of the Pharen\Module
ns that I'm creating).
The ns
function defined in Pharen.php seemed to be the ticket (along with the load
macro and use
function, however when I define a macro that uses ns
it gives the following error at compile time:
PHP Fatal error: Call to undefined method stdClass::compile() in /var/pharen/pharen.php on line 1089
The macro definition that causes this is as follows:
(defmacro defproject (name version)
'(ns ~name)
)
This macro when compiled (linked using load
macro) generates this PHP:
<?php
namespace ;
require_once('/var/pharen/lang.php');
use Pharen\Lexical as Lexical;
Lexical::$scopes['api'] = array();
I believe it's that empty namespace that is being generated there that is causing the issue.
Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.