{"id":13607962,"url":"https://github.com/kgabis/ape","last_synced_at":"2025-09-02T04:05:08.399Z","repository":{"id":146704009,"uuid":"250485722","full_name":"kgabis/ape","owner":"kgabis","description":"Ape Programming Language","archived":false,"fork":false,"pushed_at":"2023-04-06T07:27:18.000Z","size":150,"stargazers_count":268,"open_issues_count":3,"forks_count":20,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-07-20T22:22:57.761Z","etag":null,"topics":["ape","c","compiler","language","monkey-language","vm"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kgabis.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["kgabis"]}},"created_at":"2020-03-27T08:55:38.000Z","updated_at":"2025-06-29T19:35:50.000Z","dependencies_parsed_at":"2023-04-03T10:31:00.142Z","dependency_job_id":"d90d2d30-9b47-4b2b-a7b6-8b9e10431fe9","html_url":"https://github.com/kgabis/ape","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kgabis/ape","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgabis%2Fape","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgabis%2Fape/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgabis%2Fape/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgabis%2Fape/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kgabis","download_url":"https://codeload.github.com/kgabis/ape/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgabis%2Fape/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273227970,"owners_count":25067691,"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-09-02T02:00:09.530Z","response_time":77,"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":["ape","c","compiler","language","monkey-language","vm"],"created_at":"2024-08-01T19:01:23.149Z","updated_at":"2025-09-02T04:05:08.379Z","avatar_url":"https://github.com/kgabis.png","language":"C","readme":"# The Ape Programming Language\n\n## Try Ape in your browser on [Ape Playground](https://kgabis.github.io/apeplay/).\n\n## About\nApe is an easy to use programming language and library written in C. It's an offspring of [Monkey](https://monkeylang.org) language (from [Writing An Interpreter In Go](https://interpreterbook.com) and [Writing A Compiler In Go](https://compilerbook.com) books by [Thorsten Ball](https://thorstenball.com)), but it evolved to be more procedural with variables, loops, operator overloading, modules, and more.\n\n## Current state\nIt's under development so everything in the language and the api might change.\n\n## Example\n```javascript\nfn contains_item(to_find, items) {\n    for (item in items) {\n        if (item == to_find) {\n            return true\n        }\n    }\n    return false\n}\n\nconst cities = [\"Warszawa\", \"Rabka\", \"Szczecin\"]\nconst city = \"Warszawa\"\nif (contains_item(city, cities)) {\n    println(`found ${city}!`)\n}\n```\n\n## Embedding\nAdd ape.h and ape.c to your project and compile ape.c with a C compiler before linking.\n\n```c\n#include \"ape.h\"\n\nint main() {\n    ape_t *ape = ape_make();\n    ape_execute(ape, \"println(\\\"hello world\\\")\");\n    ape_destroy(ape);\n    return 0;\n}\n```\n\nAn example that shows how to call Ape functions from C code and vice versa can be found [here](examples/api.c).\n\n## Language\n\nApe is a dynamically typed language with mark and sweep garbage collection. It's compiled to bytecode and executed on internal VM. It's fairly fast for simple numeric operations and not very heavy on allocations (custom allocators can be configured). More documentation can be found [here](documentation.md).\n\n### Basic types\n```bool```, ```string```, ```number``` (double precision float), ```array```, ```map```, ```function```, ```error```\n\n### Operators\n```\nMath:\n+ - * / %\n\nBinary:\n^ | \u0026 \u003c\u003c \u003e\u003e\n\nLogical:\n! \u003c \u003e \u003c= \u003e= == != \u0026\u0026 ||\n\nAssignment:\n= += -= *= /= %= ^= |= \u0026= \u003c\u003c= \u003e\u003e=\n```\n\n### Defining constants and variables\n```javascript\nconst constant = 2\nconstant = 1 // fail\nvar variable = 3\nvariable = 7 // ok\n```\n\n## Strings\n```javascript\nconst str1 = \"a string\"\nconst str2 = 'also a string'\nconst str3 = `a template string, it can contain expressions: ${2 + 2}, ${str1}`\n```\n\n### Arrays\n```javascript\nconst arr = [1, 2, 3]\narr[0] // -\u003e 1\n```\n\n### Maps\n```javascript\nconst map = {\"lorem\": 1, 'ipsum': 2, dolor: 3}\nmap.lorem // -\u003e 1, dot is a syntactic sugar for [\"\"]\nmap[\"ipsum\"] // -\u003e 2\nmap['dolor'] // -\u003e 3\n```\n\n### Conditional statements\n```javascript\nif (a) {\n    // a\n} else if (b) {\n    // b\n} else {\n    // c\n}\n```\n\n### Loops\n```javascript\nwhile (true) {\n    // body\n}\n\nvar items = [1, 2, 3]\nfor (item in items) {\n    if (item == 2) {\n        break\n    } else {\n        continue\n    }\n}\n\nfor (var i = 0; i \u003c 10; i++) {\n    // body\n}\n```\n\n### Functions\n```javascript\nconst add_1 = fn(a, b) { return a + b }\n\nfn add_2(a, b) {\n    return a + b\n}\n\nfn map_items(items, map_fn) {\n    const res = []\n    for (item in items) {\n        append(res, map_fn(item))\n    }\n    return res\n}\n\nmap_items([1, 2, 3], fn(x){ return x + 1 })\n\nfn make_person(name) {\n    return {\n        name: name,\n        greet: fn() {\n            println(`Hello, I'm ${this.name}`)\n        },\n    }\n}\n```\n\n### Errors\n```javascript\nconst err = error(\"something bad happened\")\nif (is_error(err)) {\n    println(err)\n}\n\nfn() {\n    recover (e) { // e is a runtime error wrapped in error\n        return null\n    }\n    crash(\"something bad happened\") // crashes are recovered with \"recover\" statement\n}\n```\n\n### Modules\n```javascript\nimport \"foo\" // import \"foo.ape\" and load global symbols prefixed with foo::\n\nfoo::bar()\n\nimport \"bar/baz\" // import \"bar/baz.ape\" and load global symbols prefixed with baz::\nbaz::foo()\n```\n\n### Operator overloading\n```javascript\nfn vec2(x, y) {\n    return {\n        x: x,\n        y: y,\n        __operator_add__: fn(a, b) { return vec2(a.x + b.x, a.y + b.y)},\n        __operator_sub__: fn(a, b) { return vec2(a.x - b.x, a.y - b.y)},\n        __operator_minus__: fn(a) { return vec2(-a.x, -a.y) },\n        __operator_mul__: fn(a, b) {\n            if (is_number(a)) {\n                return vec2(b.x * a, b.y * a)\n            } else if (is_number(b)) {\n                return vec2(a.x * b, a.y * b)\n            } else {\n                return vec2(a.x * b.x, a.y * b.y)\n            }\n        },\n    }\n}\n```\n\n## Splitting and joining\n\nape.c can be split into separate files by running utils/split.py:\n\n```\npython3 utils/split.py --input ape.c --output-path ape\n```\n\nIt can be joined back into a single file with utils/join.py:\n\n```\npython3 utils/join.py --template utils/ape.c.templ --path ape --output ape.c\n```\n\n## Visual Studio Code extension\n\nA Visual Studio Code extension can be found [here](https://marketplace.visualstudio.com/items?itemName=KrzysztofGabis.apelang).\n\n## My other projects\n* [parson](https://github.com/kgabis/parson) - JSON library\n* [kgflags](https://github.com/kgabis/kgflags) - command-line flag parsing library   \n* [agnes](https://github.com/kgabis/agnes) - header-only NES emulation library\n\n## License\n[The MIT License (MIT)](http://opensource.org/licenses/mit-license.php)\n","funding_links":["https://github.com/sponsors/kgabis"],"categories":["C","Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgabis%2Fape","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkgabis%2Fape","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgabis%2Fape/lists"}