PHP code example of webgraphe / phlip
1. Go to this page and download the library: Download webgraphe/phlip library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webgraphe / phlip example snippets
use Webgraphe\Phlip\Phlipy;
use Webgraphe\Phlip\Program;
// Tokenize and parse code into a program
$program = Program::parse('(lambda (x) (* x x))');
// Bootstrap a new scope with different level of Phlipy dialects
$scope = Phlipy::basic()->getScope();
// Execute program within said scope
$square = $program->execute($scope);
// In this case, return value is an anonymous function - a lambda - calculating the square of a number
// as per source code "(* x x)"
var_dump($square(M_PI)); // (double)9.8696044010894