{"id":25344833,"url":"https://github.com/vasyl-bodnar/forthish","last_synced_at":"2025-09-01T20:35:50.802Z","repository":{"id":197686265,"uuid":"699111364","full_name":"Vasyl-Bodnar/forthish","owner":"Vasyl-Bodnar","description":"Forthish Language Interpreter","archived":false,"fork":false,"pushed_at":"2024-12-11T19:23:39.000Z","size":11735,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-14T11:54:47.969Z","etag":null,"topics":["forth-like","interpreter","language"],"latest_commit_sha":null,"homepage":"https://vasyl-bodnar.github.io/forthish/","language":"OCaml","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/Vasyl-Bodnar.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":"2023-10-02T00:04:10.000Z","updated_at":"2024-12-11T19:23:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"18e64beb-dc61-4d1d-bd50-fe763feaaca6","html_url":"https://github.com/Vasyl-Bodnar/forthish","commit_stats":null,"previous_names":["vasyl-bodnar/forthish"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vasyl-Bodnar%2Fforthish","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vasyl-Bodnar%2Fforthish/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vasyl-Bodnar%2Fforthish/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vasyl-Bodnar%2Fforthish/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vasyl-Bodnar","download_url":"https://codeload.github.com/Vasyl-Bodnar/forthish/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247873749,"owners_count":21010523,"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":["forth-like","interpreter","language"],"created_at":"2025-02-14T11:52:22.230Z","updated_at":"2025-04-08T15:43:00.851Z","avatar_url":"https://github.com/Vasyl-Bodnar.png","language":"OCaml","readme":"# forthish\n\nObjective Caml interpreter for my custom Forthish language.\n\n## Details\n\nForthish is a stack-based, functional concatenative programming language inspired by Forth and Factor.\n\n### Language\n\n- Words are defined using the `: ;` notation from Forth, so `: fun 1 1 + ;` defines fun to putting two 1s and adding them.\n- Alternatively `bind` can be used to bind a word to a quotation, so `[ fun 1 1 + ] bind` is equivalent to the above.\n  Note that that both of them are lexically scoped. If you want to bind a word in outer scope, you will have to return a quote and open it.\n- You can define variables inside functions using a powerful `take` word. \n  For example `: x take ;` will 'take' the variable on top of the stack and associate it with x at runtime.\n- Modules can be defined using the same `: ;`, as in `Module: ( Words and Definitions ) ;`. \n  This will define a module with the given name and the words inside it and bring it into scope.\n- Quotations are enclosed in square brackets `[ ]` like in Factor. \n  They are quite powerful, and can be used for anonymious functions and laziness, or Lisp style.\n- Literals can be Integers (-35 or 21), Strings (`\"Hello\"`), or Boolean values (`true` or `false`).\n- Comments are enclosed in parentheses `( )` as is traditional in Forth.\n\nYou can find a tree-sitter grammar for this language [here](https://github.com/Vasyl-Bodnar/tree-sitter-forthish).\n\n### Built-in Words\n\nCertain words are already predefined as core for various uses:\n\n- Stack manipulation: `dup`, `pop`, `swap`, `over`, `rot`\n- Control flow: `if`, `open` (opens and evaluates quotes as though they were words),\n- List operations: `hd`, `tl`, `shd`, `stl`, `chars`, `concat`, `quote`, `+quote`\n- Arithmetic operations: `+`, `-`, `*`, `**`, `/`, `%`\n- Comparison operations: `=`, `\u003c\u003e`, `\u003e`, `\u003c`\n- Boolean operations: `and`, `or`, `not`\n- I/O operations: `.` (print top), `,` (read input line) \n- File: `infile` (read entire file), `outfile` (write string to file)\n- Modules: `use` (bring module into scope), `useup` (merge module into current scope)\n- Meta: `describe` (definitions), `len` (stack size), \n        `eval` (arbitrary code execution), `del` (remove definition), \n        `bind`, `take`, `exit`\n\n### Modules\n\nFiles are considered modules, and can be imported using the `use` or `useup` word. \n\nFor example, `\"file.fthish\" use` will import the file level module in `file.fthish` from same directory. \nThis module will be available as `File` in this case. \n\nAlternatively, `\"file.fthish\" useup` will merge the file level module into the current scope, so that the words are available directly.\n\nYou can also define modules directly using the `SomeModule: ( Some Words and Definitions ) ;` syntax. \nIt would be evaluated the same way as a file and brought into scope in the way of `use`.\n\nCurrently there are two modules available in the standard library: \n`list` and `util`, that provide many list operations and a couple of utility functions.\nThese can be imported in the same way as above files, but if using `dune install`, \nthese should be preinstalled in a place that the interpreter can find them from anywhere.\n\n### Examples\n\nHere are some simple examples of Forthish code:\n\n```forth\n\"list\" use\n( Usual function implementations )\n\n: fact 1 swap List:.. List:prod ;\n: sum [ + ] List:rreduce ;\n: fib dup 2 \u003e [ dup 1 - fib swap 2 - fib + ] [ pop 1 ] if ;\n\n5 fact .\n[ 5 6 7 8 ] sum .\n8 fib .\n( Prints\n120 26 21\n)\n```\n\n```forth\n\"list\" useup\n( Modules example )\n\nIngrdt: [ Onion Oil Salt Pepper ] enum! open ;\n\nRecipe: \n  : nl \"\\n\" . ;\n  : drizzle Ingrdt:Oil = [ \"Drizzle Oil\" . ] [] if ;\n  : chop desc \"Chop \" swap + . ;\n  : fry \"Fry it for\" . . \"seconds\" . ;\n  : add [\n      [\"Salt to taste\" [Ingrdt:Salt =]]\n      [\"Grind some Pepper\" [Ingrdt:Pepper =]]\n      [\"Add Onion\" [Ingrdt:Onion =]]\n    ] matchw open . ; \n  : finish \"Finished\" . ; ;\n\n: nl Recipe:nl ;\n\nIngrdt:Oil Recipe:drizzle nl\nIngrdt:Onion Recipe:chop nl\nIngrdt:Onion Recipe:add nl\n180 Recipe:fry nl\nIngrdt:Salt Recipe:add nl\nIngrdt:Pepper Recipe:add nl\nRecipe:finish\n```\n\n### Building\n\nThere are three components here, the REPL and file interpreter in `bin/`, the parser and core interpreter in `lib/`, and web interface in `web/`.\n\nYou can build them using dune, simply by running `dune build` for binary and library, and `dune build @default` for the web interface.\n\nThere are dependencies on `js_of_ocaml`, `dune-site` and `ocamline`, so you may need to install them with `opam`.\n\n### Usage\n\n`forthish` binary has a few modes:\n- `forthish` will start the REPL environment.\n- `forthish file.fthish` will interpret the file.\n- `forthish -e \"code\"` will interpret the code string.\n- `forthish -i \u003cfile\u003e arg1 arg2` will run the interpreter on a file and provide bash style arguments ($0 is the file name string, $1 is the first argument string, etc).\n  Note that this is meant for shebang style usage, and the first line of the file will be ignored.\n- `forthish [-]-help` will show the help message.\n\nThe web interface can be run locally in the `_build/default/web` directory using `python3 -m http.server` or similar.\nThe web interface is a simple REPL that can be used to run Forthish code in the browser.\nIt automatically imports the standard library modules, so you can use them directly.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvasyl-bodnar%2Fforthish","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvasyl-bodnar%2Fforthish","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvasyl-bodnar%2Fforthish/lists"}