{"id":13800785,"url":"https://github.com/brandonbloom/metaclj","last_synced_at":"2025-09-09T18:36:18.810Z","repository":{"id":138800549,"uuid":"21364795","full_name":"brandonbloom/metaclj","owner":"brandonbloom","description":"Staged compilation for Clojure through environment \u0026 special-form aware syntax-quoting.","archived":false,"fork":false,"pushed_at":"2021-10-29T00:14:50.000Z","size":35,"stargazers_count":81,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-22T15:50:50.135Z","etag":null,"topics":["clojure","metaprogramming","staging"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brandonbloom.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}},"created_at":"2014-06-30T20:23:35.000Z","updated_at":"2024-06-29T09:52:33.000Z","dependencies_parsed_at":"2024-01-07T21:54:23.467Z","dependency_job_id":"c8781a87-aa84-469a-817b-8e293aae3e8a","html_url":"https://github.com/brandonbloom/metaclj","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brandonbloom/metaclj","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonbloom%2Fmetaclj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonbloom%2Fmetaclj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonbloom%2Fmetaclj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonbloom%2Fmetaclj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brandonbloom","download_url":"https://codeload.github.com/brandonbloom/metaclj/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonbloom%2Fmetaclj/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274340921,"owners_count":25267297,"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-09T02:00:10.223Z","response_time":80,"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":["clojure","metaprogramming","staging"],"created_at":"2024-08-04T00:01:16.240Z","updated_at":"2025-09-09T18:36:18.771Z","avatar_url":"https://github.com/brandonbloom.png","language":"Clojure","funding_links":[],"categories":["Awesome macros usage"],"sub_categories":[],"readme":"# Meta-Clojure\n\n\n## Overview\n\nMeta-Clojure provides staged compilation for Clojure. It includes a form of\nsyntax quoting that is aware of both local environments and special-forms.\nAmong other things, this makes many macros easier to write. Perhaps more\nimportantly, it simplifies control over when code gets evaluated or compiled.\n\n## Usage\n\n```clojure\n(require '[metaclj.core :refer [defmeta defbn syntax] :as meta])\n```\n\n### Meta-Macros\n\nThe `defmeta` form is analogous to `defmacro`, but is expected to return\nSyntax objects (forms plus their environments) instead of plain forms.\n\n```clojure\n(defmeta my-if [test then else]\n  (syntax (if test then else)))\n```\n\nNote that you don't need to unquote any of the parameters to `if`, since the\n`syntax` form is aware of the meta-macro's environment.\n\n### Call-By-Name\n\nSince it's common for macros to have a body that always templates code with\na syntax-quoter, the convenience macro `defbn` provides a way to create\n\"call-by-name\" macros:\n\n```clojure\n(defbn my-if [test then else]\n  (if test then else))\n```\n\nBoth versions of `my-if` have correct \"lazy\" behavior: they will only evaluate\none arm of the conditional.\n\n### Staged Compilation\n\nThe `meta/do` macro will perform meta-quoting on zero or more forms, then\nevaluate each of them:\n\n```clojure\n(meta/do 1 2 3)\n;;=\u003e 3\n```\n\nCombined with unquoting, this enables you to perform arbitrary computation at\ncompile time:\n\n```clojure\n(let [x 2 y 4]\n  (meta/do ~(+ x y)))\n;;=\u003e 6\n```\n\nUnquoting is syntax aware and provides automatic splicing:\n\n```clojure\n(let [args (syntax 2 4)]\n  (meta/do ~(+ args)))\n;;=\u003e 6\n```\n\nYou can use function expressions to defer computation. Note that the unquoted\nexpression will still be evaluated at compile time:\n\n```clojure\n(let [x 2 y 4]\n  (meta/do (fn [] ~(+ x y))))\n;=\u003e #\u003cFn@32b2ad39 user/eval15784$fn__15788\u003e\n```\n\nYou can prove this to yourself by using `meta/translate`, which is a cousin\nof `macroexpand-all`:\n\n```clojure\n(let [x 2 y 4]\n  (meta/translate (fn [] ~(+ x y))))\n=\u003e ((fn* ([] 6)))\n```\n\nNote that the returned value is wrapped in a seq, since Meta-Clojure uniformly\nsupports multiple expressions with implicit splicing:\n\n```clojure\n(let [x (syntax 2 3)]\n  (meta/translate 1 x 4))\n;=\u003e (1 2 3 4)\n```\n\n\n## Status\n\n- The comments at the bottom of [core.clj](./src/metaclj/core.clj) and\n  the code in [core_test.clj](./test/metaclj/core_test.clj) form my testbed.\n- Many known bugs and incomplete behavior.\n- Some special forms not yet supported: `case`, `deftype`, and `reify`.\n- No progress yet on [Exotypes][5]\n- Use of `clojure.core/eval` is unavoidable at the top level, but it could\n  be compiled away for more interior forms.\n- Maybe someday I'll revive [EClj][4] and build its compiler on Meta-Clojure.\n\n\n## References\n\n- [Multi-stage Programming][1]\n- [Terralang][2]\n- [MetaOCaml][3]\n- [EClj][4]\n- [Exotypes][5]\n\n\n## License\n\nCopyright © 2016 Brandon Bloom\n\nDistributed under the Eclipse Public License either version 1.0 or (at\nyour option) any later version.\n\n\n[1]: https://www.cs.rice.edu/~taha/MSP/\n[2]: http://terralang.org/\n[3]: http://okmij.org/ftp/ML/MetaOCaml.html\n[4]: https://github.com/brandonbloom/eclj\n[5]: http://terralang.org/pldi083-devito.pdf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonbloom%2Fmetaclj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrandonbloom%2Fmetaclj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonbloom%2Fmetaclj/lists"}