{"id":17954450,"url":"https://github.com/sayanarijit/yamlfun","last_synced_at":"2025-03-25T00:32:00.712Z","repository":{"id":37652949,"uuid":"433338710","full_name":"sayanarijit/yamlfun","owner":"sayanarijit","description":"[Proof of Concept] Embedded functional scripting language with YAML ¯\\_(ツ)_/¯","archived":true,"fork":false,"pushed_at":"2021-12-08T08:02:33.000Z","size":248,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-14T06:46:33.935Z","etag":null,"topics":["functional-programming","rust","yaml"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sayanarijit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-30T07:44:03.000Z","updated_at":"2024-10-07T13:45:26.000Z","dependencies_parsed_at":"2022-09-04T20:13:54.240Z","dependency_job_id":null,"html_url":"https://github.com/sayanarijit/yamlfun","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/sayanarijit%2Fyamlfun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayanarijit%2Fyamlfun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayanarijit%2Fyamlfun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayanarijit%2Fyamlfun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sayanarijit","download_url":"https://codeload.github.com/sayanarijit/yamlfun/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245377921,"owners_count":20605374,"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-programming","rust","yaml"],"created_at":"2024-10-29T10:16:35.802Z","updated_at":"2025-03-25T00:31:59.896Z","avatar_url":"https://github.com/sayanarijit.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [YAML, fun]\n\nJust an experimental project implementing embedded functional scripting language based on YAML syntax.\n\nAPI docs for the standard library: [src/Yaml](https://github.com/sayanarijit/yamlfun/tree/main/src/Yaml).\n\n## Why?\n\nBeing fully compatible with YAML syntax means that, it will be very easy to\nimplement the runtime in a language that can parse YAML, because most of the\nparsing logic will be taken care of by the YAML parser. So, we can expect\nyamlfun code to be runnable in a wide range of platforms.\n\nYAML has a rich ecosystem of tooling. So, if a formatter can format YAML code,\nit can also format yamlfun code.\n\nYAML is widely popular. So, the learning curve of yamlfun syntax will be lower.\n\nThe script can be embedded into plain YAML, without losing all the benefits of\npure YAML code. Which makes it a great alternative configuration language.\n\nYAML syntax is surprisingly good at expressing functional programming\nlogic. Anyone familiar with Elm, Haskell, Nix or Lisp should be able to read\nthe code without much effort investment.\n\nBut most important of all, it's fun.\n\n## Concept\n\nExample:\n\n```yaml\n:let:\n  (++):\n    :lambda: [a, b]\n    :do:\n      :++: [a, b]\n\n  Cons:\n    :rec:\n      new:\n        :lambda: [a, b, op]\n        :do: [op, a, b]\n\n      car:\n        :lambda: [cons]\n        :do:\n          - cons\n          - :lambda: [a, b]\n            :do: a\n\n      cdr:\n        :lambda: [cons]\n        :do:\n          - cons\n          - :lambda: [a, b]\n            :do: b\n\n  cons: [Cons.new, { :: 1 }, { :: 2 }]\n  foobar:\n    - (++)\n    - { :: foo }\n    - { :: bar }\n\n  things:\n    - List.append\n    - :list:\n        - foobar\n        - cons\n        - Maybe\n        - [Cons.car, cons]\n    - :: [1, 1.2, -9, null, bar]\n:in:\n  :rec:\n    a:\n      :|\u003e:\n        - [Maybe.just, { :: 10 }]\n        - [Maybe.map, [add, { :: 1 }]]\n        - [Maybe.map, [add, { :: 1 }]]\n        - [Maybe.withDefault, { :: 0 }]\n\n    b: [Cons.car, cons]\n    c: [Cons.cdr, cons]\n    d:\n      - [Maybe.withDefault, null_]\n      - - [List.head, things]\n    e:\n      :|\u003e:\n        - [List.tail, things]\n        - List.head\n        - [Maybe.withDefault, null_]\n        - Cons.car\n```\n\nRun:\n\n```\ncargo run --bin yamlfun concept.yml\n```\n\nResult:\n\n```\n{a: 12, b: 1, c: 2, d: \"foobar\", e: 1}\n```\n\n## Things that (probably) work\n\n### Constant\n\n```yaml\n:: foo\n```\n\n### Variable\n\n```yaml\nfoo\n```\n\n### Function\n\n```yaml\n:lambda: [num1, num2]\n:do: [(+), num1, num2]\n```\n\n### Function Call\n\n```yaml\n[func, arg1, arg2]\n```\n\n### Chaining\n\n```yaml\n:|\u003e:\n  - { :: 1 }\n  - [(+), { :: 5 }]\n  - [(+), { :: 4 }]\n```\n\n### Record\n\n```yaml\n:rec:\n  a:\n    :rec:\n      b: { :: { 1: bar, true: baz } }\n      '10': { :: foo }\n  e: { :: { y: z } }\n```\n\n### Record Field Access\n\n```yaml\nfoo.a.10\n```\n\n```yaml\nfoo.a.b.$1\n```\n\n```yaml\n[Rec.get, { :: a.b.$1 }, foo]\n```\n\n### Record Field Update\n\n```yaml\n:update: foo\n:set:\n  a: { :: bar }\n  oldFoo: foo\n:unset: [e]\n```\n\n### List\n\n```yaml\n:list:\n  - { :: a }\n  - { :: 1 }\n  - { :: 1.1 }\n  - { :: -1 }\n  - { :: true }\n  - :list:\n      - { :: nested }\n```\n\n### If Else\n\n```yaml\n:if:\n  :==: [:: 2, :: 2]\n:then: { :: yes }\n:else: { :: no }\n```\n\n### Let In\n\n```yaml\n:let:\n  a: { :: foo }\n  b: a\n:in: b\n```\n\n### With\n\n```yaml\n:let:\n  args1:\n    :rec:\n      first: { :: 10 }\n      second: { :: 20 }\n  args2:\n    ::\n      third: 30\n:in:\n  :with: [args1, args2]\n  :do:\n    :+: [first, second, third]\n```\n\n### Case Of\n\n```yaml\n:let:\n  handle:\n    :lambda: [var]\n    :do:\n      :case: var\n      :of:\n        :==:\n          1: { :: this is one }\n          []: { :: this is empty list }\n          bar: { :: this is bar }\n          null: { :: this is null }\n          true: { :: this is true }\n          false: { :: this is false }\n        :int:\n          :as: n\n          :do: { :: this is an int }\n        :float:\n          :as: f\n          :do: { :: this is a float }\n        :string:\n          :as: [first, rest]\n          :do: first\n        :function:\n          :as: f\n          :do: { :: this is a function }\n        :list:\n          :as: [head, tail]\n          :do: head\n        :rec:\n          :as: { foo_: { :: foo } }\n          :do: foo_\n        :_:\n          :as: wtf\n          :do: { :: wtf?? }\n:in:\n  :list:\n    - [handle, { :: null }]\n    - [handle, { :: true }]\n    - [handle, { :: false }]\n    - [handle, { :: 1 }]\n    - [handle, { :: 2 }]\n    - [handle, { :: 1.1 }]\n    - [handle, { :: foo }]\n    - [handle, { :: bar }]\n    - [handle, handle]\n    - [handle, { :: [] }]\n    - [handle, { :: [a, b] }]\n    - [handle, { :: { foo: bar } }]\n```\n\n### Platform Call\n\n```yaml\n:platform: import\n:arg: { :: ./concept.yml }\n```\n\n```rust\nstruct MyPlatform(DefaultPlatform);\n\nimpl Platform for MyPlatform { ... }\n\nfn main() {\n    let vm = Vm::new(MyPlatform(DefaultPlatform)).unwrap();\n    ...\n}\n```\n\n## Embed into Rust\n\n[Here's how](https://github.com/sayanarijit/yamlfun/tree/main/examples)\n\n## Contribute\n\nSee [CONTRIBUTING.md](https://github.com/sayanarijit/yamlfun/tree/main/CONTRIBUTING.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayanarijit%2Fyamlfun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsayanarijit%2Fyamlfun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayanarijit%2Fyamlfun/lists"}