{"id":20089948,"url":"https://github.com/bugadani/expresso","last_synced_at":"2026-05-12T17:41:30.540Z","repository":{"id":77144872,"uuid":"46563630","full_name":"bugadani/Expresso","owner":"bugadani","description":null,"archived":false,"fork":false,"pushed_at":"2016-06-03T19:30:22.000Z","size":616,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T02:43:18.212Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bugadani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-20T13:30:32.000Z","updated_at":"2016-09-15T14:20:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"ef0381b7-6e16-43f5-8275-3d6d3988b8f5","html_url":"https://github.com/bugadani/Expresso","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FExpresso","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FExpresso/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FExpresso/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FExpresso/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bugadani","download_url":"https://codeload.github.com/bugadani/Expresso/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241525427,"owners_count":19976709,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T16:20:58.401Z","updated_at":"2026-05-12T17:41:25.515Z","avatar_url":"https://github.com/bugadani.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Expresso\n==============\n\nExpresso is an expression evaluation and compiler engine written in PHP. It's main goal is to enable evaluating\nboth simple and complicated expressions, given as strings.\n\nExpresso is also an extensible language framework.\n\nUsage\n-------------\n\n    $expresso = new Expresso();\n    $expresso-\u003eaddExtension(new Core());\n    $expresso-\u003eaddExtension(new Lambda());\n\n    $expresso-\u003eexecute('a ^ 5', ['a' =\u003e 2]);     // returns 32\n\n    $compiled = $expresso-\u003ecompile('2 ^ a');\n    $compiled(['a' =\u003e 6]);                       // 64\n\nThe Core extension\n-------------\nCore implements the base language used by Expresso. It contains the basic syntax, like operators, function calls, collection\ndefinitions and defines some functions that can be used in expressions.\n\n### Available operators\n - Arithmetic operators\n   - `x + y`\n   - `x - y`\n   - `x * y`\n   - `x / y`\n   - `-x`\n   - `x div y`: integer divison, divides `x` by `y` and rounds towards 0.\n   - `x ^ y`: exponential operator, computes `x` to the `y`-th power\n   - `x % y`: returns the remainder of `x` / `y`, where the result has the sign of `x` (i.e. `-2 % 5 = -2`)\n   - `x mod y`: returns the  remainder of `x` / `y`, where the result is always positive (i.e. `-2 mod 5 = 3`)\n - Bitwise operators\n   - `x b-and y`\n   - `x b-or y`\n   - `x b-xor y`\n   - `x \u003c\u003c y`: shifts `x` to the left by `y` bits\n   - `x \u003e\u003e y`: shifts `x` to the right by `y` bits, while keeping the sign of `x`\n   - `~x`: inverts `x`\n - Comparison operators\n   - `x == y`\n   - `x != y`\n   - `x === y`\n   - `x !== y`\n   - `x \u003c y`\n   - `x \u003c= y`\n   - `x \u003e y`\n   - `x \u003e= y`\n - Logical operators\n   - `x \u0026\u0026 y`\n   - `x || y`\n   - `x xor y`\n   - `!x`\n - Test operators\n   - `x is divisible by y`\n   - `x is not divisible by y`\n   - `x is even`\n   - `x is odd`\n   - `x is set`\n   - `x is not set`\n - Other operators\n   - `x ~`: Concatenates two strings\n   - `[x...y]`: Creates a collection of numbers between `x` and `y`, including both `x` and `y`\n   - `[x...]`: Creates an infinite collection of numbers starting with `x`\n   - `x()`\n   - `x|y`\n   - `x|y()`\n   - `x.y`\n   - `x?.y`\n   - `x.y()`\n   - `x?.y()`\n   - `x[y]`\n   - `x ?: y`\n   - `x ? y : z`\n\n### Available functions\n - `count(c)`\n - `join(c, g)`\n - `skip(c, n)`\n - `replace(s, x, y)`\n - `replace(s, c)`\n - `reverse(s)`\n - `take(c, n)`\n\nExpresso supports partial function application. Example that creates a function to return the first N natural numbers:\n\n    f := take([1...])\n    f(5)|join(', ') # this prints 1, 2, 3, 4, 5\n\nThe Lambda extension\n-------------\nThe Lambda extension adds the ability to define lambda expressions and adds some higher order functions.\n\nA lambda expression is defined with the following syntax: `\\\u003carguments\u003e -\u003e \u003cexpression\u003e`\n\n    $expresso-\u003eevaluate('[1...5]|map(\\x -\u003e 2*x)|join(\", \")');    //returns \"2, 4, 6, 8, 10\"\n\n### Available functions\n - `all`: returns true if all members of a collection match the given predicate\n - `any`: returns true if any member of a collection match the given predicate\n - `filter`: filters elements of a collection using a callback function\n - `first`: takes the first element of a collection\n - `fold`: reduces a collection to a single value using a callback function\n - `map`: maps every element of a collection to the return value of a function\n\n### Other uses\n - Chaining lambda expressions. In this example, `someValue` will be 27.\n\n     someValue = 5 | \\_ -\u003e (_ * 5)\n                   | \\_ -\u003e (_ * 2)\n\nThe Generator extension\n-------------\nThe extension defines list comprehension expressions or generators in short.\nGenerators follow the common notation used in mathematics to define lists or sets.\n\nAn example generator, that generates the list of square numbers:\n\n    [ x^2 for x \u003c- [1...]]\n\nMultiple branches can be defined which will be run in parallel (e.g. sources are iterated at the same time).\nExample to generate the list of even numbers:\n\n    [ x + y for x \u003c- [1...]; y \u003c- [1...]]\n\nA branch may define multiple arguments that will be evaluated from left to right.\nAn example that generates the list of numbers between 0 and 99:\n\n    [ x * 10 + y for x \u003c- [0...9]; y \u003c- [1...9]]\n\nBranches may also have guard expressions which are specified using the keyword 'where'.\nThe following example creates a list of even numbers using guard expressions:\n\n    [ x for x \u003c- [1...] where x is even ]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugadani%2Fexpresso","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbugadani%2Fexpresso","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugadani%2Fexpresso/lists"}