{"id":19917190,"url":"https://github.com/athos/syntactic-closure","last_synced_at":"2025-05-03T06:30:44.955Z","repository":{"id":2958289,"uuid":"3972613","full_name":"athos/syntactic-closure","owner":"athos","description":"syntactic closures built on top of Clojure's macro system","archived":false,"fork":false,"pushed_at":"2012-08-08T14:27:43.000Z","size":144,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T11:51:28.296Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Clojure","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/athos.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}},"created_at":"2012-04-09T14:59:44.000Z","updated_at":"2022-11-25T17:06:08.000Z","dependencies_parsed_at":"2022-08-31T04:20:30.209Z","dependency_job_id":null,"html_url":"https://github.com/athos/syntactic-closure","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athos%2Fsyntactic-closure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athos%2Fsyntactic-closure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athos%2Fsyntactic-closure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athos%2Fsyntactic-closure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/athos","download_url":"https://codeload.github.com/athos/syntactic-closure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252154732,"owners_count":21702982,"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-11-12T21:49:06.183Z","updated_at":"2025-05-03T06:30:44.728Z","avatar_url":"https://github.com/athos.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# syntactic-closure\n\n`syntactic-closure` is a Clojure library that provides some facilities\nto define hygienic macros with syntactic closures.\nIt aims to implement a hygienic macro system interoperable with Clojure's\nmacro system.\n\nFor details about syntactic closures, see [Syntactic Closures](ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-1049.pdf) or [Chicken Scheme's wiki page](http://wiki.call-cc.org/eggref/3/syntactic-closures).\n\n**Note**: `syntactic-closure` is still of alpha quality.\n\n## Usage\n\nAdd the following to your project.clj dependencies:\n\n```clojure\n[syntactic-closure \"0.1.0\"]\n```\n\nUse via:\n\n```clojure\n(use 'syntactic-closure.core)\n```\n\nor, for the shorthand, use via:\n\n```clojure\n(use 'syntactic-closure)\n```\n\n## About\n\nAs on some Scheme implementations, you can define hygienic macros\nusing syntactic closures, like this:\n\n```clojure\n(use 'syntactic-closure.core)\n\n(define-syntax let1 [name init \u0026 body]\n  (sc-macro-transformer\n    (fn [env]\n      (quasiquote\n        (let [~name ~(make-syntactic-closure env nil init)]\n          ~@(map #(make-syntactic-closure env [name] %) body))))))\n\n(let1 x 10 (* x x))\n```\n\nIn this case, the input name `x` is automatically renamed.\n\n```clojure\n(macroexpand '(let1 x 10 (* x x)))\n;=\u003e (let* [x403 10] (clojure.core/* x403 x403))\n```\n\nUsing syntactic closures, you can also define anaphoric macros.\n\n```clojure\n(define-syntax aif [test then else]\n  (sc-macro-transformer\n    (fn [env]\n      (let [it ~(make-syntactic-closure env nil test)]\n        (if it\n          ~(make-syntactic-closure env '[it] then)\n          ~(make-syntactic-closure env nil else))))))\n```\n\n\nSince Scheme-like interfaces are somehow verbose, `syntactic-closure`\nnamespace provides a simple shorthand for them (, though it is subject to change).\n\n```clojure\n(use 'syntactic-closure)\n\n(defsyntax let1 [name init \u0026 body]\n  (qq (let [~name ~^:? init]\n        ~@^{:? name} body)))\n\n(defsyntax aif [test then else]\n  (qq (let [it ~^:? test]\n        (if it\n          ~^{:? 'it} then\n          ~^:? else))))\n```\n\nFor details about the shorthand, see Shorthand section below.\n\nFor more examples, see example code in the `/examples` directory.\nEach example includes both verbose and concise versions of code.\n\n## Shorthand\n`syntactic-closure` namespace provides `qq` macro, which is almost the same\nas `quasiquote` except that in `qq` form, the following shorthand can be used.\n\n* `~^:? foo` is equivalent to `~(make-syntactic-closure *env* nil foo)`\n* For any symbol `id`, `~^{:? id} foo` is equivalent to `~(make-syntactic-closure *env* [id] foo)`\n* For any list of symbols `ids`, `~^{:? ids} foo` is equivalent to `~(make-syntactic-closure *env* ids foo)`\n* `~@^:? foo` is equivalent to `~@(map (bound-fn [x#] (make-syntactic-closure *env* nil x#)) foo)`\n* For any symbol `id`, `~@^{:? id} foo` is equivalent to `~@(map (bound-fn [x#] (make-syntactic-closure *env* [id] x#)) foo)`\n* For any list of symbols `ids`, `~@{:? ids} foo` is equivalent to `~@(map (bound-fn [x#] (make-syntactic-closure *env* ids x#)) foo)`\n\n## Resources\n\n* [Syntactic Closures](ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-1049.pdf)\n* [A Syntactic Closures Macro Facility](http://groups.csail.mit.edu/mac/ftpdir/scheme-reports/synclo.ps)\n\n## License\n\nCopyright (C) 2012 OHTA Shogo\n\nDistributed under the Eclipse Public License, the same as Clojure.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathos%2Fsyntactic-closure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fathos%2Fsyntactic-closure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathos%2Fsyntactic-closure/lists"}