Giter VIP home page Giter VIP logo

pharen's People

Contributors

cpressey avatar francescoagati avatar igorw avatar jcmoyer avatar jeromebaum avatar morpheusthewhite avatar pizzorni avatar scriptor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pharen's Issues

Function argument types

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?

Unquoting doesn't work on list/dictionary indexing

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.

test.php, required by examples/test files, does not exist

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 lambda in macro i get error

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 ()))
)

Support for oop

Should be nice create macro from oop ( classes, interfaces, instance creation).

(load file) is broken for more than one level (load file 1(load file 2 (load file 3))) for a once off compile

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.

Reader Macros?

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?

problem with macro that create a function as in documentation

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

Can't use more than one statement inside 'do'

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.

Deploying Pharen to a server

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)

Passing anonymous function (php 5.3)

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.

splatten in macro don't compile

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$

Missing "use" keyword for Plambdas

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)

macro with function generation doesnt compile

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

Defining namespaces break compilation inside macros

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?

chain operator -> don't expand macro on object chain

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 ->

problem with multi lambda in hash

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);

macro doesnt capture locale scope variable with define e let

(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

handle support for namespace in php 5.3

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

test func_calls not pass

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
        );

problem with macro generating a method in class

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

Form handling - example from Quick Tutorial

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();

TCO'd loops not returning when inside let binding

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().

literal notation of dictionary is not translated correctly inside a macro

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));


Compile errors

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

'Lexical' definition never included in (any) compiled output

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!

Problem with WHEN macro

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.

Lexical::init_closure(naming) is unexpected when (load file) is used

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))

problem with array (Update: discussion on vectors)

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)));

Don't parse macro arguments

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.

Compiler sometimes generates "return" inside TCO'ed "while" loops

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.)

Bad OR behaviours

(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")).

Compiling to a class

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?

macro example with makelist doesn't compile

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

macros

should be nice having support for macro reader and for macro igienic con symbol generator like in clojure with character #

PHP Files Have Incorrect Includes

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.

passing array create inside a macro to code expression

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])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.