{"id":13787715,"url":"https://github.com/zesterer/atto","last_synced_at":"2025-03-17T07:31:07.727Z","repository":{"id":66134577,"uuid":"173033915","full_name":"zesterer/atto","owner":"zesterer","description":"An insanely simple self-hosted functional programming language","archived":false,"fork":false,"pushed_at":"2019-08-02T11:37:06.000Z","size":77,"stargazers_count":152,"open_issues_count":4,"forks_count":6,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-02-27T19:36:21.949Z","etag":null,"topics":["functional","interpreter","language","recursion","rust","self-hosted"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/zesterer.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-28T03:25:36.000Z","updated_at":"2024-11-20T05:40:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"ebd7626a-a0c3-4cde-a520-65b39cbd2e38","html_url":"https://github.com/zesterer/atto","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/zesterer%2Fatto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zesterer%2Fatto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zesterer%2Fatto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zesterer%2Fatto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zesterer","download_url":"https://codeload.github.com/zesterer/atto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243848124,"owners_count":20357494,"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":["functional","interpreter","language","recursion","rust","self-hosted"],"created_at":"2024-08-03T21:00:28.290Z","updated_at":"2025-03-17T07:31:07.457Z","avatar_url":"https://github.com/zesterer.png","language":"Rust","readme":"# Atto\n\nAtto is an insanely simple functional programming language.\n\nIt features a syntax driven entirely by polish notation and no delimiters to speak of (it ignores all non-separating whitespace).\nWhat do you get for this simplicity? Well... an insanely simple language with a ~200 line self-hosted interpreter.\n\nDespite these design limitations, it's actually possible to write quite pleasing code in Atto.\nThat, combined with the extraordinarily extendable syntax (you can define your own operators, or overload those defined in the `core` library) make it\nideal for solving a whole class of programming problems that are normally awkward to solve in more imperative languages.\n\n## Design\n\nAtto's design is stupidly simple. There are two kinds of structure:\n\nFunctions: `fn \u003cname\u003e [args] is \u003cexpr\u003e`\n\nExpressions: `\u003cliteral\u003e [expr]`\n\nThat's it. Expressions, function calls, literals and operations are all considered to be the same thing.\n\nI leave you with a quick factorial calculation example demonstrating the compact expressiveness of Atto at work.\n\n```\nfn f n is\n  if = n 0\n    1\n  * n f - n 1\n```\n\nYes, that's it.\n\n## Atto Interpreter Written In Atto\n\nIn `examples/self-hosted.at`, I've written a fully-functioning REPL-based interpreter for Atto.\nIt supports function declaration, function calling, and all of the evaluation operators that Atto does, including I/O.\nIt has a minor issues, such as behaving unpredictably with invalid input. However, it should be able to successfully run any valid Atto program (provided your stack is big enough).\n\nWhich reminds me: I need to use a non-recursive interpretation algorithm in the Rust interpreter. Also, tail-call optimisation would be nice.\n\n## Core Library\n\nAtto comes with a `core` library. It provides a series of non-intrinsic functions and utilities that are themselves written in Atto.\nIn addition, it provides all of the operators common to Atto usage.\nThe Atto interpreter implicitly inserts the `core` library above whatever you run, similar in nature to C's `#include`.\n\n- `# x y`: Ignore the first value, evaluate to only the second (useful for comments)\n- `@ x y`: Ignore the second value, evaluate to only the first\n- `! x`: Negate a boolean\n- `wrap x`: Wrap a value in a list\n- `empty`: Produces the empty list\n- `debug_enabled`: Can be overriden to enable debugging utilities\n- `debug i x`: Display the value of `x` with the information tag `x`\n- `assert i x`: Assert that `x` is true\n- `assert_eq x y`: Assert that `x` and `y` are equivalent\n- `is_atom x`: Determine whether a value is atomic (i.e: null, bool or a number)\n- `is_str x`: Determine whether a value is a string\n- `is_list x`: Determine whether `x` is a list\n- `is_bool x`: Determine whether `x` is a bool\n- `is_num x`: Determine whether `x` is a number\n- `is_null x`: Determine whether `x` is null\n- `len l`: Determine the length of a list\n- `skip n l`: Skip the first `n` values in a list\n- `nth n l`: Get the `n`th item in a list\n- `in x l`: Determine whether `x` is in a list\n- `split i l`: Split a list into two separate lists at the `i`th index\n\nYou can check `src/atto/core.at` for full documentation about what `core` provides.\n\n## Tutorial\n\n### Basic numeric operators:\n\n```\nfn main is\n\t+ 5 7\n```\n\nYields: `12`\n\n```\nfn main is\n\t- * 3 3 5\n```\n\nYields: `4`\n\n### Printing values to the console:\n\n```\nfn main is\n\tprint \"Hello, world!\"\n```\n\n```\nfn main is\n\tprint str 1337\n```\n\n### Receiving inputs from the user and converting them to a value:\n\n```\nfn main is\n    print + \"Product = \" str\n    \t* litr input \"second: \"\n          litr input \"first: \"\n```\n\n### Pairing values together into a two-component list:\n\n```\nfn main is\n\tpair 3 17\n```\n\nYields `[3, 17]`\n\n### Fusing lists together:\n\n```\nfn main is\n\tfuse pair 3 17 pair 5 8\n```\n\nYields: `[3, 17, 5, 8]`\n\n### Conditional expressions:\n\n```\nfn main is\n\tif true\n\t\t10\n\t\t5\n```\n\nYields: `10`\n\n```\nfn main is\n\tif false\n\t\t10\n\t\t5\n```\n\nYields: `5`\n\n### Selecting the first value in a list:\n\n```\nfn main is\n\thead pair 3 17\n```\n\nYields: `3`\n\n### Selecting values trailing after the head of a list:\n\n```\nfn main is\n\ttail fuse 3 fuse 17 9\n```\n\nYields: `[17, 9]`\n\n### Converting a string into a value:\n\n```\nfn main is\n\t- 7 litr \"3\"\n```\n\nYields: `4`\n\n```\nfn main is\n\t+ 7 litr \"8.5\"\n```\n\nYields: `15.5`\n\n```\nfn main is\n\t= null litr \"null\"\n```\n\nYields: `true`\n\n### Defining a function with parameters:\n\n```\nfn add x y is\n\t+ x y\n\nfn main is\n\tadd 5 3\n```\n\nYields: `8`\n\n### Recursion to find the size of a list:\n\n```\nfn size l is\n\tif = null head\n\t\t0\n\t\t+ 1 size tail l\nfn main is\n\tsize fuse 1 fuse 2 3\n```\n\nYields: `3`\n\n## Optimisation\n\nCurrently, Atto's Rust interpreter performs virtually no optimisations. Despite that, I'll attempt to talk below about some ideas I've had that seem promising.\n\nAtto's design does not permit the realiasing of values within a function, nor does it permit mutation. This, and the fact that the syntax is incredibly\nquick to parse, makes it an extremely good potential target for a lot of optimisations. Inlining, constant propagation, CSE detection and tail call\noptimisations are naturally easy to implement on top of Atto's design.\n\nThe lack of realiasing also means that Atto has an affine type system *by design*, without ever requiring compiler\nsupport for move semantic analysis or anything like that.\n\nThe only real obstacles to some really impressive optimisation is its dynamic type system. However,\nin a significant number of cases it's likely that types can be inferred at compile-time with specialized machine code emitted for each function depending on\nthe types passed to it.\n\nI'm also working on ideas for a statically-typed version of Atto. However, I've yet to settle on a design that is sufficiently simple as to compliment the\ncurrent design.\n","funding_links":[],"categories":["Uncategorized","Functional"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzesterer%2Fatto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzesterer%2Fatto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzesterer%2Fatto/lists"}