{"id":15643205,"url":"https://github.com/borkdude/deflet","last_synced_at":"2025-07-08T01:35:09.575Z","repository":{"id":98585990,"uuid":"608765239","full_name":"borkdude/deflet","owner":"borkdude","description":"Make let-expressions REPL-friendly!","archived":false,"fork":false,"pushed_at":"2025-04-11T15:05:44.000Z","size":29,"stargazers_count":70,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-19T01:32:03.937Z","etag":null,"topics":["babashka","clojure","clojurescript","nbb"],"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/borkdude.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},"funding":{"github":"borkdude"}},"created_at":"2023-03-02T17:32:56.000Z","updated_at":"2025-04-11T15:05:48.000Z","dependencies_parsed_at":"2023-05-25T00:15:31.301Z","dependency_job_id":null,"html_url":"https://github.com/borkdude/deflet","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/borkdude%2Fdeflet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borkdude%2Fdeflet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borkdude%2Fdeflet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borkdude%2Fdeflet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/borkdude","download_url":"https://codeload.github.com/borkdude/deflet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251691657,"owners_count":21628366,"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":["babashka","clojure","clojurescript","nbb"],"created_at":"2024-10-03T11:59:27.669Z","updated_at":"2025-04-30T11:33:34.130Z","avatar_url":"https://github.com/borkdude.png","language":"Clojure","readme":"# deflet\n\n[![Clojars Project](https://img.shields.io/clojars/v/io.github.borkdude/deflet.svg)](https://clojars.org/io.github.borkdude/deflet)\n\nMake let-expressions REPL-friendly!\n\n\u003e Let them have their inline-def and eat it too.\n\n## Usage\n\n``` clojure\n(require '[borkdude.deflet :refer [deflet]])\n```\n\nWrite inline-defs like you would in a Rich comment form, so you can evaluate\nthings expression by expression as you go:\n\n``` clojure\n(comment\n  (def x 10) ;; =\u003e #'x\n  (def y (inc x)) ;;=\u003e #'y\n  y ;;=\u003e 11\n)\n```\n\nbut now without polluting the global environment in production / library code,\nwhile still having the ability to evaluate expressions in the REPL:\n\n``` clojure\n(deflet\n  ;; evaluation still works for individual forms in a REPL-connected editor:\n  (def x 10) ;;=\u003e #'x\n  (def y (inc x)) ;;=\u003e #'y\n  ;; but the whole expression is compiled into a let-expression which returns the last value:\n  y) ;;=\u003e 11\n```\n\nThe above `deflet` form expands into:\n\n``` clojure\n(let [x 10]\n  (let [y (inc x)]\n    y)) ;;=\u003e 11\n```\n\nI find the inline-def style particularly helpful when exploring code in the REPL, e.g. when writing tests:\n\n``` clojure\n(deftest deflet-test\n  (deflet\n    (def x 10)\n    (is (= 10 x))))\n```\n\nIn constrast to writing inline defs without deflet, type hints actually work the\nway you'd expect and you can still run your tests in parallel.\n\n## Nbb\n\nThis library also contains an [nbb](https://github.com/babashka/nbb) REPL-friendly variant, called `defletp` which works in concert with [promesa](https://github.com/funcool/promesa):\n\n``` clojure\n(require '[borkdude.deflet :refer [defletp defp]]\n         '[cljs.test :refer [deftest async is]]\n         '[promesa.core :as p])\n\n(deftest defletp-test\n  (async\n   done\n   (-\u003e (defletp\n         (defp x (p/delay 100 :result))\n         (is (= :result x)))\n       (p/finally done))))\n```\n\nThe `defp` works like `def` but wraps the result with `nbb.core/await` to await\ntop level promises. So when evaluating `(defp x (p/delay 100 :result))` in the\nnbb REPL, you'll get a var `x` bound to `100` instead of a promise. But the\n`defletp` macro expands this into a `promesa.core/let` expression.\n\n[Here](examples/playwright) is a demo of how you can use deflet with nbb and playwright tests.\n\n\u003cimg src=\"https://user-images.githubusercontent.com/284934/222552490-439cb704-d0b0-4650-b0fc-0e18f49423eb.png\"\u003e\n","funding_links":["https://github.com/sponsors/borkdude"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborkdude%2Fdeflet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborkdude%2Fdeflet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborkdude%2Fdeflet/lists"}