{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/16985","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/16985/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/16985/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/16985/events","html_url":"https://github.com/JuliaLang/julia/issues/16985","id":160890266,"number":16985,"title":"Custom infix operators","user":{"login":"jamesonquinn","id":372468,"avatar_url":"https://avatars.githubusercontent.com/u/372468?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesonquinn","html_url":"https://github.com/jamesonquinn","followers_url":"https://api.github.com/users/jamesonquinn/followers","following_url":"https://api.github.com/users/jamesonquinn/following{/other_user}","gists_url":"https://api.github.com/users/jamesonquinn/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesonquinn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesonquinn/subscriptions","organizations_url":"https://api.github.com/users/jamesonquinn/orgs","repos_url":"https://api.github.com/users/jamesonquinn/repos","events_url":"https://api.github.com/users/jamesonquinn/events{/privacy}","received_events_url":"https://api.github.com/users/jamesonquinn/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JuliaLang/julia/labels/speculative","name":"speculative","color":"999999"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":46,"created_at":"2016-06-17T13:39:22Z","updated_at":"2016-06-23T11:59:38Z","closed_at":null,"body":"There is a discussion at https://groups.google.com/forum/#!topic/julia-dev/FmvQ3Fj0hHs about creating a syntax for custom infix operators. The proposal that seems to have won out is:\r\n```\r\n    a |>op<| b #evaluates (in the short term) and parses (in the long term) to `op(a,b)`\r\n```\r\n\r\nIn order to have this work, there are only minor changes necessary:\r\n\r\n- Put the precedence of `<|` above that of `|>`, instead of being the same.\r\n- Make `<|` group left-to-right.\r\n- Make the function `<|(a,b...)=(i...)->a(i...,b...)`. (as pointed out in the discussion thread, this would have standalone uses, as well as its use in the above idiom)\r\n\r\nOptional:\r\n- create new functions `>|(a...,b)=(i...)->b(a...,i...)` and `|<(a,b...)=a(b...)` with appropriate precedences and grouping.\r\n    - Pipe first means evaluation, and pipe last maintains it as a function, while the > and < indicate which one is the function.\r\n- create new functions `>>|(a...,b)=(i...)->b(i...,a...)` and `<<|(a,b...)=(i...)->a(b...,i...)` with appropriate precedence and grouping.\r\n- create synonyms `»`, `⁍`, and(/or) `pipe` for `|>`; `«`, `⁌`, and(/or) `rcurry` for `<|`; and(/or) `lcurry` for `<<|`; with the single-character synonyms working as infix operators.\r\n- create an `@infix` macro in base which does the first parser fix below.\r\n\r\nLong term:\r\n- teach the parser to change `a |>op<| b` to `op(a,b)`, so there's no extra overhead involved when running the code, and so that operators can actually be defined in infix position. (This is similar to how the parser currently treats the binary `a:b` and the ternary `a:b:c` differently. For maximum customizability, it should do this for matched synonyms, but not for unmatched synonyms, so that e.g. `a |> b « c` would be still be treated as two binary operators.)\r\n- teach the parser to understand commas and/or spaces so that the ellipses in the above definitions work as expected without extra parentheses.\r\n\r\n(relates to https://github.com/JuliaLang/julia/issues/6946)"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/228028769","html_url":"https://github.com/JuliaLang/julia/issues/16985#issuecomment-228028769","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/16985","id":228028769,"user":{"login":"oxinabox","id":5127634,"avatar_url":"https://avatars.githubusercontent.com/u/5127634?v=3","gravatar_id":"","url":"https://api.github.com/users/oxinabox","html_url":"https://github.com/oxinabox","followers_url":"https://api.github.com/users/oxinabox/followers","following_url":"https://api.github.com/users/oxinabox/following{/other_user}","gists_url":"https://api.github.com/users/oxinabox/gists{/gist_id}","starred_url":"https://api.github.com/users/oxinabox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oxinabox/subscriptions","organizations_url":"https://api.github.com/users/oxinabox/orgs","repos_url":"https://api.github.com/users/oxinabox/repos","events_url":"https://api.github.com/users/oxinabox/events{/privacy}","received_events_url":"https://api.github.com/users/oxinabox/received_events","type":"User","site_admin":false},"created_at":"2016-06-23T11:59:38Z","updated_at":"2016-06-23T11:59:38Z","body":"I'm really not sure on the clarity of `(a f b)`\r\n\r\nHere is a possible use-case:\r\n```select((((:emp_id, :last_name) from employee_tbl) where (:city, = ,'indianapolis')) orderby :emp_id));```\r\n\r\nThis is certainly viable use of infix functions.\r\nThe `select` function is either the identity function, or sends the built query to the database.\r\n\r\nIs this clear code?\r\nI just don't know."}}
{"actor":{"display_login":"oxinabox"}}