{"action":"created","issue":{"url":"https://api.github.com/repos/trizen/sidef/issues/54","repository_url":"https://api.github.com/repos/trizen/sidef","labels_url":"https://api.github.com/repos/trizen/sidef/issues/54/labels{/name}","comments_url":"https://api.github.com/repos/trizen/sidef/issues/54/comments","events_url":"https://api.github.com/repos/trizen/sidef/issues/54/events","html_url":"https://github.com/trizen/sidef/issues/54","id":377987916,"node_id":"MDU6SXNzdWUzNzc5ODc5MTY=","number":54,"title":"Del / delete a variable name","user":{"login":"catb0t","id":3238748,"node_id":"MDQ6VXNlcjMyMzg3NDg=","avatar_url":"https://avatars2.githubusercontent.com/u/3238748?v=4","gravatar_id":"","url":"https://api.github.com/users/catb0t","html_url":"https://github.com/catb0t","followers_url":"https://api.github.com/users/catb0t/followers","following_url":"https://api.github.com/users/catb0t/following{/other_user}","gists_url":"https://api.github.com/users/catb0t/gists{/gist_id}","starred_url":"https://api.github.com/users/catb0t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/catb0t/subscriptions","organizations_url":"https://api.github.com/users/catb0t/orgs","repos_url":"https://api.github.com/users/catb0t/repos","events_url":"https://api.github.com/users/catb0t/events{/privacy}","received_events_url":"https://api.github.com/users/catb0t/received_events","type":"User","site_admin":false},"labels":[{"id":1118341890,"node_id":"MDU6TGFiZWwxMTE4MzQxODkw","url":"https://api.github.com/repos/trizen/sidef/labels/feature","name":"feature","color":"e485f7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-06T18:57:56Z","updated_at":"2018-11-06T20:04:49Z","closed_at":null,"author_association":"COLLABORATOR","body":"(Sorry if this already exists, I can't find it)\r\n\r\nI think that in Perl there is no such thing as an \"undefined name\", all names are simply `undef` until you give them a value, or `use strict`.\r\n\r\nIn Sidef we very obviously have a difference between\r\n```ruby\r\nsay x   # compiler error \r\n\r\nvar x\r\nsay x   # nil\r\n```\r\n\r\nfor which we are thankful, no more sneaky typos. So in Perl to \"delete\" a name it's sufficient to make it `undef` as it was before it was defined, but in Sidef a variable name can simultaneously be declared and un-defined.\r\n\r\nIn Python, which requires you to assign to a name before using it, you can `del x` to get rid of that name, then it is completely removed from the current scope. \r\n\r\nIn Python (and Perl) you can also `del(?:ete)? hash[x]` to remove a key and value from a hash, which is technically unnecessary in Sidef since nonexistent keys are `nil` anyway, and you can just set it to `nil` and make it look undefined (until you dump the hash). \r\n\r\nThe ability to delete keys from a Sidef hash would be an optimisation for large numbers of keys though. \r\n\r\nActually I think instead of a `del` keyword, having `var a = 1; *a = null` (or nil, or something...) work to unscope the name would be nice, since we already have references."},"comment":{"url":"https://api.github.com/repos/trizen/sidef/issues/comments/436389932","html_url":"https://github.com/trizen/sidef/issues/54#issuecomment-436389932","issue_url":"https://api.github.com/repos/trizen/sidef/issues/54","id":436389932,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNjM4OTkzMg==","user":{"login":"trizen","id":614513,"node_id":"MDQ6VXNlcjYxNDUxMw==","avatar_url":"https://avatars3.githubusercontent.com/u/614513?v=4","gravatar_id":"","url":"https://api.github.com/users/trizen","html_url":"https://github.com/trizen","followers_url":"https://api.github.com/users/trizen/followers","following_url":"https://api.github.com/users/trizen/following{/other_user}","gists_url":"https://api.github.com/users/trizen/gists{/gist_id}","starred_url":"https://api.github.com/users/trizen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trizen/subscriptions","organizations_url":"https://api.github.com/users/trizen/orgs","repos_url":"https://api.github.com/users/trizen/repos","events_url":"https://api.github.com/users/trizen/events{/privacy}","received_events_url":"https://api.github.com/users/trizen/received_events","type":"User","site_admin":false},"created_at":"2018-11-06T20:04:49Z","updated_at":"2018-11-06T20:04:49Z","author_association":"OWNER","body":"Deleting a variable from the current scope it's an interesting idea. I think it should be possible to add the `del x` or `unvar x` syntax to removing `x` from the current scope (at parse-time). I'll think about it.\r\n\r\nAssigning `nil` to a variable it's possible. That would behave exactly like in Perl when `undef` is assigned to a variable. However, the variable itself still exists in the current scope and can be accessed, just that it's not defined (only declared).\r\n\r\nDeleting keys from an Hash it's already possible using the `delete` Hash method:\r\n\r\n```ruby\r\nvar h = Hash(a => 1, b => 2, c => 3)\r\n\r\nsay h.delete(:a)            #=> 1\r\nsay [h.delete(:b, :c)]      #=> [2, 3]\r\n\r\nsay h                       #=> Hash()\r\n```"}}
{"actor":{"display_login":"trizen"}}