{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/9508","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/9508/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/9508/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/9508/events","html_url":"https://github.com/JuliaLang/julia/pull/9508","id":53153099,"number":9508,"title":"Default values function arguments vs Python","user":{"login":"bkamins","id":6187170,"avatar_url":"https://avatars.githubusercontent.com/u/6187170?v=3","gravatar_id":"","url":"https://api.github.com/users/bkamins","html_url":"https://github.com/bkamins","followers_url":"https://api.github.com/users/bkamins/followers","following_url":"https://api.github.com/users/bkamins/following{/other_user}","gists_url":"https://api.github.com/users/bkamins/gists{/gist_id}","starred_url":"https://api.github.com/users/bkamins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bkamins/subscriptions","organizations_url":"https://api.github.com/users/bkamins/orgs","repos_url":"https://api.github.com/users/bkamins/repos","events_url":"https://api.github.com/users/bkamins/events{/privacy}","received_events_url":"https://api.github.com/users/bkamins/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-12-30T22:35:40Z","updated_at":"2015-01-01T07:30:32Z","closed_at":"2014-12-31T03:39:33Z","pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/9508","html_url":"https://github.com/JuliaLang/julia/pull/9508","diff_url":"https://github.com/JuliaLang/julia/pull/9508.diff","patch_url":"https://github.com/JuliaLang/julia/pull/9508.patch"},"body":"Julia and Python handle default values of function arguments differently. Julia evaluates them every time the function is called and in python they are evaluated only once when the function is defined. This is an important difference in behavior for people migrating to Julia from Python."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/68481914","html_url":"https://github.com/JuliaLang/julia/pull/9508#issuecomment-68481914","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/9508","id":68481914,"user":{"login":"bkamins","id":6187170,"avatar_url":"https://avatars.githubusercontent.com/u/6187170?v=3","gravatar_id":"","url":"https://api.github.com/users/bkamins","html_url":"https://github.com/bkamins","followers_url":"https://api.github.com/users/bkamins/followers","following_url":"https://api.github.com/users/bkamins/following{/other_user}","gists_url":"https://api.github.com/users/bkamins/gists{/gist_id}","starred_url":"https://api.github.com/users/bkamins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bkamins/subscriptions","organizations_url":"https://api.github.com/users/bkamins/orgs","repos_url":"https://api.github.com/users/bkamins/repos","events_url":"https://api.github.com/users/bkamins/events{/privacy}","received_events_url":"https://api.github.com/users/bkamins/received_events","type":"User","site_admin":false},"created_at":"2015-01-01T07:30:32Z","updated_at":"2015-01-01T07:30:32Z","body":"This is true, but I felt that In \"Noteworthy differences from Python\" section the explanation should be simple and show the difference from what Python programmer would expect.\r\n\r\nExplaining all the mechanics how Julia handles functions in this section would be too complex in my opinion (it is covered in section \"Note on Optional and keyword Arguments\").\r\n\r\nIn particular notice that keyword arguments case exhibits similar (but not exactly identical) behavior but is implemented differently as statement `f(;x=rand(),y=x) = x+y` creates only one generic function.\r\n\r\nIt is worth to mention that R also evaluates its arguments every time the function is called but uses different mechanism to ensure this functionality. In particular this means that:\r\n\r\n* in R `f <- function(x=y, y=runif(1)) x+y)` when called as `f()` will return different result every time and is valid;\r\n* Julia would throw error when `f(x=y, y=runif()) = x+y` is called as `f()` unless `y` is defined in outer scope;\r\n* Julia would throw error when `f(;x=y, y=runif()) = x+y` is called as `f()` even if is `y` is defined in outer scope."}}