{"id":13610650,"url":"https://github.com/rzbin/libra","last_synced_at":"2026-02-26T21:49:16.922Z","repository":{"id":144016472,"uuid":"415315033","full_name":"rzbin/libra","owner":"rzbin","description":"♎️ Libra is a basic stack-based programming language simulated through Haskell.","archived":false,"fork":false,"pushed_at":"2021-10-14T08:49:39.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-07T17:44:21.255Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Haskell","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/rzbin.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-10-09T13:20:37.000Z","updated_at":"2023-02-02T14:38:23.000Z","dependencies_parsed_at":"2024-01-24T16:15:18.126Z","dependency_job_id":"e2f59330-b87f-4316-bcde-64f686d216e9","html_url":"https://github.com/rzbin/libra","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/rzbin%2Flibra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzbin%2Flibra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzbin%2Flibra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzbin%2Flibra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rzbin","download_url":"https://codeload.github.com/rzbin/libra/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650554,"owners_count":21139670,"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-08-01T19:01:46.704Z","updated_at":"2026-02-26T21:49:16.875Z","avatar_url":"https://github.com/rzbin.png","language":"Haskell","readme":"# Libra ♎️\n\nLibra is a basic stack-based programming language simulated through Haskell.\nHeavily inspired by [Porth](https://github.com/tsoding/porth) and [Forth](\u003chttps://en.wikipedia.org/wiki/Forth_(programming_language)\u003e)\n\nGoals:\n- [x] Basic integer operations\n- [x] Data types \"String\" and \"Boolean\"\n- [x] While loops\n- [x] If statements\n- [x] Function macros\n- [x] Simple memory\n- [x] Turing completeness (Runs [Rule110](https://en.wikipedia.org/wiki/Rule_110), see [`examples/rule110.♎️`](./examples/rule110.♎️))\n\n## Example\nPrint numbers and words:\n```pascal\n123 456 + print\n\"Hello World!\" print\n```\nyields\n```\n579\nHello World!\n```\nPrint even numbers between 0 and 10\n```pascal\n10 0 while 2dup \u003c run\n  \"Number: \" put dup print\n  2 +\nend\n```\nyields\n```\nNumber: 0\nNumber: 2\nNumber: 4\nNumber: 6\nNumber: 8\n```\n\n## Usage\n\nLibra programs are simulated in Haskell, best done through the interactive shell started by running\n```bash\n$ ghci run.hs\n```\nRun programs by running\n```bash\nλ\u003e run \"file.♎️\"\n```\n\n## Language\n\n### Data types\n\nCurrently supported data types are integers, strings, and booleans. Pushed onto the stack as follows:\n```pascal\n123 \"Hello World!\" False\n```\n\n### Control flow\n\n#### If statements\n\n`if \u003cbody\u003e end`\n\nIf checks if the top stack element is True, if so it executes the body, else it skips to end.\n\n`if \u003ctrue_body\u003e else \u003cfalse_body\u003e end`\n\nIf checks if the top stack element is True, if so it executes the true body and after skips to the end, else it will execute the else body.\n\n#### While loops\n\n`while \u003ccond\u003e run \u003cbody\u003e end`\n\nWhile checks if a certain condition is true, if so it runs the body and returns to the while, if not, it skips to end.\n\n### Manipulation words\n\n#### Integer arithmetic\n\n- `+` : Sum the two top stack elements\n```pascal\n1 2 + print\n```\nyields `3`\n\n- `-` : Subtract the two top stack elements\n```pascal\n10 2 - print\n```\nyields `8`\n\n- `*` : Multiply the two top stack elements\n```pascal\n3 4 * print\n```\nyields `12`\n\n- `/` : Integer divide the two top stack elements\n```pascal\n10 3 / print\n```\nyields `3`\n\n- `%` : Mod divide the two top stack elements\n```pascal\n10 3 % print\n```\nyields `1`\n\n#### Stack editing\n- `dup` : Duplicate the top stack element\n```pascal\n\"Hello\" dup print print\n```\nyields `Hello Hello`\n\n- `drop` : Drop the top stack element\n```pascal\n\"Hello\" \"World\" drop print\n```\nyields `Hello`\n\n- `2dup` : Duplicate the two top stack element\n```pascal\n10 2 2dup + print / print\n```\nyields `12 5`\n\n- `2drop` : Drop the two top stack element\n```pascal\n\"Hello\" 10 \"World\" 2drop print\n```\nyields `Hello`\n\n- `swap` : Swap the two top stack element\n```pascal\n\"Bottom\" \"Top\" swap print print\n```\nyields `Bottom Top`\n\n- `over` : Copies the element second on the stack\n```pascal\n\"Hello\" \"World\" over print print print\n```\nyields `Hello World Hello`\n\n#### Output\n- `print` : Print the top stack element followed by newline\n```pascal\n\"Hello\" print \"World\" print\n```\nyields\n```\nHello\nWorld\n```\n\n- `put` : Print the top stack element without a newline\n```pascal\n\"Hello\" put \"World\" put\n```\nyields\n```\nHelloWorld\n```\n\n#### Logic\n- `!` : Negates the top stack element\n```pascal\nFalse ! print\n```\nyields `True`\n\n- `|` : Logical OR's the top two stack elements\n```pascal\nTrue False | print\n```\nyields `True`\n\n- `\u0026` : Logical AND's the top two stack elements\n```pascal\nTrue False \u0026 print\n```\nyields `False`\n\n#### Comparison\n- `=` : Tests equality on the top two stack elements\n```pascal\nTrue False = print\n```\nyields `False`\n\n- `\u003c` : Tests if the second stack element is smaller than the top stack element\n```pascal\n2 5 \u003c print\n```\nyields `True`\n\n- `\u003c` : Tests if the second stack element is greater than the top stack element\n```pascal\n2 5 \u003e print\n```\nyields `False`\n\n- `\u003c=` : Tests if the second stack element is smaller than or equal to the top stack element\n```pascal\n2 5 \u003c= print\n```\nyields `True`\n\n- `\u003c=` : Tests if the second stack element is greater than or equal to the top stack element\n```pascal\n2 5 \u003e= print\n```\nyields `False`\n\n#### Memory\nMemory works using a memory pointer which can be increased and decreased.\n\n- `#` : Push the memory pointer to the stack\n- `s` : Store a token to a pointer\n- `r` : Read from a stack pointer\n```pascal\n# 4 s\n# 5 + \"String\" s\n# r print\n# 5 + r print\n```\nyields `4 \"String\"`\n\n### Comments\n- `~` : Ignores the rest of the line\n```pascal\n123 123 + ~ Add the numbers together\n```\n\n### Function macros\n\n`$ \u003cname\u003e [\u003cbody\u003e]`\n\nExpands name to body when used in code\n```pascal\n$ incr [1 +]\n10 incr print\n```\nyields `11`","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzbin%2Flibra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frzbin%2Flibra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzbin%2Flibra/lists"}