Title: in-ns special form oddities · Issue #366 · pixie-lang/pixie · GitHub
Open Graph Title: in-ns special form oddities · Issue #366 · pixie-lang/pixie
X Title: in-ns special form oddities · Issue #366 · pixie-lang/pixie
Description: Imagine you are writing a test that operates on namespaces, but you don't want it to conflict with other tests that operate on namespaces, so you give the namespace a long name nested "within" your test namespace, like pixie.tests.test-s...
Open Graph Description: Imagine you are writing a test that operates on namespaces, but you don't want it to conflict with other tests that operate on namespaces, so you give the namespace a long name nested "within" your...
X Description: Imagine you are writing a test that operates on namespaces, but you don't want it to conflict with other tests that operate on namespaces, so you give the namespace a long name nested "wit...
Opengraph URL: https://github.com/pixie-lang/pixie/issues/366
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"in-ns special form oddities","articleBody":"1) Imagine you are writing a test that operates on namespaces, but you don't want it to conflict with other tests that operate on namespaces, so you give the namespace a long name nested \"within\" your test namespace, like pixie.tests.test-stdlib.foo. Then, because you want to refer to that namespace several times within the test, and you don't want to write it out each time, you assign it to a local, like this.\n\n```\n(let [test-ns :pixie.tests.test-stdlib.foo]\n (in-ns test-ns)\n (def y 3)\n etc. etc.)\n```\n\nExcept the test fails. You expected that y would be created within pixie.tests.test-stdlib.foo, but instead it's created within namespace \"test-ns\". That's because in-ns is a special form at compile time, and it sets the compile-time namespace to \"test-ns\". Then it becomes a function at run time, and it sets the run-time namespace to pixie.tests.test-stdlib.foo, as you would see if you examined `*ns*`. I think that behavior is confusing.\n\n2) In the same vein, in-ns affects the environment even if never executed.\n\n```\nuser =\u003e (defn g [] (in-ns :pixie.tests.test-stdlib))\n\u003cVar user/g\u003e\npixie.tests.test-stdlib =\u003e \n```\n\nSo in this case, even though g was only compiled but not executed, it affected the current namespace. Similar stuff happens with `if` statements -- if you have an if statement in which one branch sets the namespace to :foo and another to :bar, all vars resolved after that will be resolved in the namespace of the second branch, etc.. The only thing that matters is the order in which the compiler encounters in-ns. \n\nI think having the compiler mutate the current namespace as it goes along is confusing, because it requires you to think about order of compilation. It requires non-local reasoning to figure out which var an unqualified symbol refers to -- not just looking at what's lexically-enclosing. This is unlike in clojure, where if you read through a file of function definitions all in one namespace, then you know how every symbol will be resolved simply by looking at its name (okay, with the exception of refers).\n\nWhat advantage does pixie gain by having in-ns be a special form that affects compilation state?\n","author":{"url":"https://github.com/joshua-g","@type":"Person","name":"joshua-g"},"datePublished":"2015-09-01T07:29:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/366/pixie/issues/366"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3d4c1029-af45-46e2-afd3-beea97659944 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCFA:B6892:43CF7D:5A1B7A:6969D2CA |
| html-safe-nonce | 78042844c797a765918c02d0c9d0433d5987552ba9da329c50a836f52b188803 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0ZBOkI2ODkyOjQzQ0Y3RDo1QTFCN0E6Njk2OUQyQ0EiLCJ2aXNpdG9yX2lkIjoiMjIzMzEzMDA4MjI0NDM1MDY2NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 194b4f5d743c73978e0565ca71572b5d29f9f1a0f18acfd78ecfc4057f419773 |
| hovercard-subject-tag | issue:104203923 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pixie-lang/pixie/366/issue_layout |
| twitter:image | https://opengraph.githubassets.com/24ba00da13a809beb4002440fa57f7b76436c5c6902ab1ddcd667107913a899a/pixie-lang/pixie/issues/366 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/24ba00da13a809beb4002440fa57f7b76436c5c6902ab1ddcd667107913a899a/pixie-lang/pixie/issues/366 |
| og:image:alt | Imagine you are writing a test that operates on namespaces, but you don't want it to conflict with other tests that operate on namespaces, so you give the namespace a long name nested "within" your... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | joshua-g |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-preview |
| go-import | github.com/pixie-lang/pixie git https://github.com/pixie-lang/pixie.git |
| octolytics-dimension-user_id | 8930965 |
| octolytics-dimension-user_login | pixie-lang |
| octolytics-dimension-repository_id | 24507006 |
| octolytics-dimension-repository_nwo | pixie-lang/pixie |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24507006 |
| octolytics-dimension-repository_network_root_nwo | pixie-lang/pixie |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width