{"id":13735736,"url":"https://github.com/zevv/with","last_synced_at":"2025-04-04T15:14:22.268Z","repository":{"id":64501994,"uuid":"167852143","full_name":"zevv/with","owner":"zevv","description":"with macro for Nim","archived":false,"fork":false,"pushed_at":"2023-01-29T14:41:09.000Z","size":459,"stargazers_count":86,"open_issues_count":2,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-10T00:43:39.228Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Nim","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/zevv.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":"2019-01-27T19:58:19.000Z","updated_at":"2025-01-25T00:00:39.000Z","dependencies_parsed_at":"2023-02-15T23:10:16.632Z","dependency_job_id":null,"html_url":"https://github.com/zevv/with","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zevv%2Fwith","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zevv%2Fwith/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zevv%2Fwith/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zevv%2Fwith/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zevv","download_url":"https://codeload.github.com/zevv/with/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198466,"owners_count":20900081,"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-08-03T03:01:10.501Z","updated_at":"2025-04-04T15:14:22.230Z","avatar_url":"https://github.com/zevv.png","language":"Nim","funding_links":[],"categories":["Language Features"],"sub_categories":["Macros"],"readme":"\n\u003e _`with` is fun, but as its own project it should have a splash image like \"Inspired by a forbidden(TM) JavaScript feature!\"_\n\u003e -jrfondren\n\n`with` is a simple macro to replace the deprecated ``{.with.}`` pragma in Nim.\nThis macro allow you to access fields of an object or tuple without having to\nrepeatedly type its name. It works by creating tiny templates with the same\nname as the field that expand to access to the field in the object.\n\nExample:\n\n\n```nim\ntype Foo = ref object\n  first: int\n  second: string\n  third: float\n\nvar foo = Foo(first: 1, second: \"two\", third: 3.0)\n\nwith foo:\n  echo first\n  if true:\n    third = float(first)\n  echo second\n```\n\n\n``with`` also works with named tuples:\n\n```nim\nvar foo = (first: 1, second: \"two\")\nwith foo:\n  first = 3\n  second = \"six\"\n```\n\n\nFields from the object can be shadowed by new declarations in the scope where\nthe new declaration is made. The object field can still be accessed by using its\nfull dot-expression notation:\n\n\n```nim\nvar foo = (first: 1, second: \"two\")\nwith foo:\n  assert first == 1\n  if true:\n    let first = \"dragons\"\n    assert first == \"dragons\" \n    assert foo.first == 1\n  assert first == 1\n  assert foo.first == 1\n```\n\n\nFor the brave, ``with`` blocks can be nested, or multiple objects can be passed\nin a tuple constructor. Make sure that field names are unique in the nested\nobjects:\n\n```nim\nvar foo = (first: 1, second: \"two\")\nvar bar = (alpha: 42)\n\nwith foo:\n  with bar:\n    first = alpha\n\nwith (foo,bar):\n  first = alpha\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzevv%2Fwith","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzevv%2Fwith","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzevv%2Fwith/lists"}