{"id":16658785,"url":"https://github.com/nventuro/egglang","last_synced_at":"2025-10-12T03:37:02.629Z","repository":{"id":150232981,"uuid":"118827313","full_name":"nventuro/egglang","owner":"nventuro","description":"A JavaScript implementation of the Egg programming language.","archived":false,"fork":false,"pushed_at":"2018-03-16T18:17:24.000Z","size":309,"stargazers_count":6,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"dev","last_synced_at":"2025-10-12T03:36:58.816Z","etag":null,"topics":["egg-programming-language","programming-language"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nventuro.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":"2018-01-24T21:57:04.000Z","updated_at":"2023-11-11T01:23:28.000Z","dependencies_parsed_at":"2023-06-15T08:30:44.416Z","dependency_job_id":null,"html_url":"https://github.com/nventuro/egglang","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nventuro/egglang","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventuro%2Fegglang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventuro%2Fegglang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventuro%2Fegglang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventuro%2Fegglang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nventuro","download_url":"https://codeload.github.com/nventuro/egglang/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventuro%2Fegglang/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010143,"owners_count":26084692,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["egg-programming-language","programming-language"],"created_at":"2024-10-12T10:06:43.330Z","updated_at":"2025-10-12T03:37:02.612Z","avatar_url":"https://github.com/nventuro.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# egglang: the Egg programming language\n\n[![Build Status](https://travis-ci.org/nventuro/egglang.svg?branch=master)](https://travis-ci.org/nventuro/egglang)\n\nA JavaScript implementation of the Egg programming language, as described by [Marijn Haverbeke](https://marijnhaverbeke.nl/) in [his book](http://eloquentjavascript.net/11_language.html).\n\n## Dependencies\n- [Node.js](https://nodejs.org/en/): v8.9.4.\n- [npm](https://www.npmjs.com/): v5.6.0.\n\nYou can check everything is installed correctly by running the following commands:\n\n```\n$ node --version\nv8.9.4\n\n$ npm --version\n5.6.0\n```\n\n## Build and Test\n\nFirst, make sure that you have all the dependencies listed in the previous section. Then, clone the project repository and enter the root directory:\n\n```\n$ git clone https://github.com/nventuro/egglang.git\n$ cd egglang\n```\n\nNext, build the project dependencies:\n\n`$ npm install`\n\nTo make sure everything is set up correctly, it would be a good idea to run all tests at this point and verify that they finish successfully:\n\n`$ npm test`\n\n## Usage\nRun `egg.sh` to get a REPL, or call it with a `.egg` file to run an Egg program. Sample programs are provided in the [samples directory](https://github.com/nventuro/egglang/tree/dev/samples).\n\n```\n$ ./egg.sh samples/modules.egg\n40\n```\n\n## Language\nEgg is an expression-oriented language, with each program being a single expression, and uses prefix notation (also called Polish notation). Because of this, it looks somewhat different from other popular programming languages.\n\n### Types\nEgg supports integers (both positive and negative), boolean values, and literal strings (escape characters are not allowed though).\n\n### Basic operations\nAll of the basic arithmetic and comparison operands are supported, and can be used by calling a function with their name. These operations can be chained.\n\n```\n\u003e +(1, 2)\n3\n\u003e /(12, -3)\n-4\n\u003e +(*(4, 2), -(5, 3))\n10\n\u003e \u003c(5, 10)\ntrue\n```\n\n### Assignment\nEgg is a dynamically typed language, and as such type declarations are not required when creating new variables. This is done using the `:=` operator.\n\n```\n\u003e :=(a, 2)\n2\n\u003e a\n2\n\u003e +(a, 3)\n5\n```\n\nLike everything else in Egg, `:=` is an expression, and evaluates to the assigned value.\n\n`=` is used to update the value of a `:=`'d variable, and also evaluates to the assigned value.\n\n```\n\u003e :=(a, 2)\n2\n\u003e :=(a, 3)\nReferenceError: Attempting to re-define local variable\n\u003e a\n2\n\n\u003e =(a, 3)\n3\n\u003e a\n3\n```\n\n### Functions\nFunctions are created with the `fun` keyword: its first `n-1` arguments are the function's arguments, with the remaining argument being the function body. A function is evaluated to (returns) its body. Functions can be passed as arguments and returned from them, and closures can be created.\n\n```\n\u003e :=(f, fun(\n    2\n  ))\n\u003e f()\n2\n\n\u003e :=(g, fun(a,\n    a\n  ))\n\u003e g(3)\n3\n\n\u003e :=(h, fun(\n    :=(i, 2)\n  ))\n\u003e h()\n2\n\u003e i\nReferenceError: Undefined variable: i\n\n\u003e :=(adder, fun(a,\n    fun(b,\n      +(a, b)\n    )\n  ))\n\u003e :=(add_5, adder(5))\n\u003e add_5(3)\n8\n```\n\n### Expression grouping\nA program composed of a single expression is quite limiting, but this becomes a non-issue by using the `do` keyword. It evaluates each of its arguments in order, and is evaluated to the value of the last one. This makes it useful for function bodies and flow control, as is shown below.\n\n```\n\u003e do(\n    :=(a, 3),\n    :=(b, 4),\n    +(a, b)\n  )\n7\n```\n\nIf a particular value wants to be 'returned' from a `do` expression (such as at the end of a function), that value can simply be evaluated last.\n\n```\n\u003e :=(f, fun(do(\n    :=(a, 2),\n    :=(b, 3),\n    +(a, b),\n    a\n  )))\n\u003e f()\n2\n```\n\n### Scope\nBoth `fun` and `do` create a local scope, in which new variables can be `:=`'d without having them be created in the outer scope. Outer variables can still be accessed and modified using `=`.\n\n### Conditionals\nThe standard `if` keyword is supported by Egg, but its meaning is slightly different. Since `if` is also an expression, it's actually closer to C's ternary operator (`?:`), and like in C, both the taken and not-taken branches are required. `if` evaluates to the value of the branch that ends up being evaluated.\n\n```\n\u003e if(true,\n    2,\n    3\n  )\n2\n\n\u003e :=(a, 2)\n\u003e if(==(a, 3),\n    :=(a, 4),\n    :=(a, 5)\n  )\n5\n\u003e a\n5\n```\n\n### Flow control\nThe `while` keyword provides the only flow control mechanism, evaluating its body until the condition is false. `do` can be used with `while` to allow more than one expression to be evaluated inside its body.\n\n```\n\u003e :=(i, 0)\n\u003e while(\u003c(i, 10),\n    =(i, +(i, 1))\n  )\n\u003e i\n10\n\n\u003e :=(i, 0)\n\u003e :=(pow, 1)\n\u003e while(\u003c(i, 10), do(\n    =(pow, *(pow, 2)),\n    =(i, +(i, 1))\n  ))\n\u003e pow\n1024\n```\n\n`while` is also an expression, and always evaluates to false.\n\n### Printing\nEgg programs can print to the console by calling `print`, which evaluates to its argument.\n\n### Collections\nThere are two kinds of collections in Egg: arrays and dictionaries. Their interface is similar, but usage differs slightly. Both collections can store any kind of object.\n\n#### Arrays\nArrays are created by calling `array` with the values to be stored in the array (or none for an empty array). These values can then be retrieved by calling `get` with a zero-based index, and new values can be added at the end of the array by calling `push`. The length of the array is returned by `length`.\n\n```\n\u003e :=(arr, array(1, 2, 3))\n[1, 2, 3]\n\u003e arr.get(0)\n1\n\u003e arr.push(\"4\")\n[1, 2, 3, \"4\"]\n\u003e arr\n[1, 2, 3, \"4\"]\n\u003e length(arr)\n4\n```\n\n#### Dictionaries\nDictionaries are created by calling `dict` with an even number of arguments (none for an empty dictionary): even arguments will be keys, and odd arguments will be values. These values can then be retrieved by calling `get` with an appropiate key, and new key-value pairs can be added by calling `push`. The number of key-value pairs is returned by `length`.\n\n```\n\u003e :=(di, dict(1, 2, 3, \"4\"))\n{1: 2, 3: \"4\"}\n\u003e arr.get(1)\n2\n\u003e di.push(\"abc\", 123)\n{1: 2, 3: \"4\", \"abc\": 123}\n\u003e di\n{1: 2, 3: \"4\", \"abc\": 123}\n\u003e length(di)\n3\n```\n\n### Modules\nEgg supports modules in a similar way as Node.js's `require` works. The `import` keyword loads an Egg program (an expression), evaluates it, and returns that value. Therefore, modules typically consist of single functions or dictionaries, which are then stored by the user in a variable. Standard Egg modules are provided in the [modules directory](https://github.com/nventuro/egglang/tree/dev/modules).\n\n```\n# is_even.egg\nfun(x,\n  ==(%(x, 2), 0)\n)\n\n\u003e :=(is_even, import(\"is_even.egg\"))\n\u003e is_even(2)\ntrue\n\n# parity.egg\ndict(\n  \"is_even\", fun(x,\n    ==(%(x, 2), 0)\n  ),\n  \"is_idd\", fun(x,\n    !=(%(x, 2), 0)\n  )\n)\n\n\u003e :=(parity, import(\"parity.egg\"))\n\u003e get(parity, \"is_odd\")(5)\ntrue\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnventuro%2Fegglang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnventuro%2Fegglang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnventuro%2Fegglang/lists"}