{"action":"created","issue":{"url":"https://api.github.com/repos/myst-lang/myst/issues/189","repository_url":"https://api.github.com/repos/myst-lang/myst","labels_url":"https://api.github.com/repos/myst-lang/myst/issues/189/labels{/name}","comments_url":"https://api.github.com/repos/myst-lang/myst/issues/189/comments","events_url":"https://api.github.com/repos/myst-lang/myst/issues/189/events","html_url":"https://github.com/myst-lang/myst/issues/189","id":316515901,"number":189,"title":"[RFC] Consider adding `callinfo` for introspecting method calls","user":{"login":"faultyserver","id":783733,"avatar_url":"https://avatars1.githubusercontent.com/u/783733?v=4","gravatar_id":"","url":"https://api.github.com/users/faultyserver","html_url":"https://github.com/faultyserver","followers_url":"https://api.github.com/users/faultyserver/followers","following_url":"https://api.github.com/users/faultyserver/following{/other_user}","gists_url":"https://api.github.com/users/faultyserver/gists{/gist_id}","starred_url":"https://api.github.com/users/faultyserver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/faultyserver/subscriptions","organizations_url":"https://api.github.com/users/faultyserver/orgs","repos_url":"https://api.github.com/users/faultyserver/repos","events_url":"https://api.github.com/users/faultyserver/events{/privacy}","received_events_url":"https://api.github.com/users/faultyserver/received_events","type":"User","site_admin":false},"labels":[{"id":740675612,"url":"https://api.github.com/repos/myst-lang/myst/labels/feature-request","name":"feature-request","color":"75e5cf","default":false},{"id":635501034,"url":"https://api.github.com/repos/myst-lang/myst/labels/syntax","name":"syntax","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-21T18:57:12Z","updated_at":"2018-04-23T07:26:20Z","closed_at":null,"author_association":"OWNER","body":"`callinfo` would be a language-managed variable, similar to `self`, that provides some introspective information about the caller of a method. As a language variable, `callinfo` would also be added as a new keyword.\r\n\r\nHaving access to meta information about the caller of a method is primarily helpful for debugging and tooling inside of Myst. The most obvious usecases are the `Spec` and `Assert` libraries.\r\n\r\nMost spec libraries provide location information about failing specs to help users locate them quickly and easily. In Myst, this isn't a practical possibility yet, because the library has no way of accessing that location information without requiring the user to pass in `__FILE__` and `__LINE__` values for every `it` block.\r\n\r\nAdding `callinfo` would provide that location information to these modules automatically, without any burden on the user. It would also avoid having conditional semantics for the magic constants, which I've never particularly liked.\r\n\r\n\r\n## Semantics\r\n\r\nReferencing `callinfo` outside of a method definition will always return `nil`.\r\n\r\n\r\nInside of a method definition, `callinfo` returns a Map with these entries:\r\n  - `:file`: the file containing the call to this method.\r\n  - `:line`: the line number of the call to this method.\r\n  - `:dir`: the directory containing the file with the call to this method.\r\n\r\nFor simplicity, this Map is newly-created every time `callinfo` is invoked. This ensures both \"psuedo-immutability\", and that the values are accurate for the current call.\r\n\r\n\r\n## Example usage\r\n\r\nRetrieving the location information of a Call using `callinfo` could look something like this:\r\n\r\n```myst\r\ndef foo(a, b, c)\r\n  {line: line, file: file} = callinfo\r\n  STDOUT.puts(\"line <(line)>, file <(file)>\")\r\nend\r\n\r\nfoo(1, 2, 3) #=> line 6, file /Users/.../foo.mt\r\n```"},"comment":{"url":"https://api.github.com/repos/myst-lang/myst/issues/comments/383479979","html_url":"https://github.com/myst-lang/myst/issues/189#issuecomment-383479979","issue_url":"https://api.github.com/repos/myst-lang/myst/issues/189","id":383479979,"user":{"login":"Jens0512","id":32913789,"avatar_url":"https://avatars1.githubusercontent.com/u/32913789?v=4","gravatar_id":"","url":"https://api.github.com/users/Jens0512","html_url":"https://github.com/Jens0512","followers_url":"https://api.github.com/users/Jens0512/followers","following_url":"https://api.github.com/users/Jens0512/following{/other_user}","gists_url":"https://api.github.com/users/Jens0512/gists{/gist_id}","starred_url":"https://api.github.com/users/Jens0512/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jens0512/subscriptions","organizations_url":"https://api.github.com/users/Jens0512/orgs","repos_url":"https://api.github.com/users/Jens0512/repos","events_url":"https://api.github.com/users/Jens0512/events{/privacy}","received_events_url":"https://api.github.com/users/Jens0512/received_events","type":"User","site_admin":false},"created_at":"2018-04-23T07:26:20Z","updated_at":"2018-04-23T07:26:20Z","author_association":"MEMBER","body":"In Crystal, you can define methods using things like this, like this:\r\n```crystal\r\nput_line\r\ndef put_line(line=__LINE__)\r\n    puts \"Called from line #{line}\"\r\nend\r\n```\r\nWhich outputs: `Called from line 1` (https://play.crystal-lang.org/#/r/3xak). \r\nIs this not possible in Myst? If it is not, making it so, seems sufficient, and much more effective, to me. \r\n\r\nI mean, this `callinfo` proposed is just a helper for defining methods like in the example, if this `callinfo` needs to be set for every call (which it has if I am not mistaken), I think we should be very careful. \r\nTake a recursive method like `factorial`, if the method calls itself a thousand times, wouldn't the stack have a thousand and one `callinfo`s? `factorial` doesn't even need any callinfo. \r\n\r\nI have by no means any proper proof that this will have a practical effect on performance, but I think that we must be careful about this kind of thing, and that there is no need for calls to contain this kind of callinfo without it being explicitly stated like in the examlpe."}}
{"actor":{"display_login":"Jens0512"}}