Talk:Call a function: Difference between revisions

Content added Content deleted
(→‎Operators: yes, you can redefine any p6 operator in a lexical scope)
m (Wow! Excellent. I am looking forward to learning this.)
Line 28: Line 28:
:::Hey, I found some notes entitled "Metaoperators", that explains this operator/function stuff. Cheers all. [[User:Markhobley|Markhobley]] 06:42, 18 July 2011 (UTC)
:::Hey, I found some notes entitled "Metaoperators", that explains this operator/function stuff. Cheers all. [[User:Markhobley|Markhobley]] 06:42, 18 July 2011 (UTC)
::Yes, that's one of the nice things about treating operators as functions: they end up lexically scoped just like functions, and obey the same shadowing and/or multiple-dispatch rules. So if you define your own <tt>infix:<+></tt> it can either override or cooperate with any outer definitions of that operator. And even the metaoperators are just calls to higher-order functions underneath. These translations happen very early in the compilation; in a sense, all operators in Perl 6 are just convenient macros that rewrite the AST to a purer FP and/or OO form, and then either the early-binding lexical rules or the late-binding inheritance rules control which function gets called. We're pretty happy with how simple this foundation turned out, given everything we're trying to build on top of it.
::Yes, that's one of the nice things about treating operators as functions: they end up lexically scoped just like functions, and obey the same shadowing and/or multiple-dispatch rules. So if you define your own <tt>infix:<+></tt> it can either override or cooperate with any outer definitions of that operator. And even the metaoperators are just calls to higher-order functions underneath. These translations happen very early in the compilation; in a sense, all operators in Perl 6 are just convenient macros that rewrite the AST to a purer FP and/or OO form, and then either the early-binding lexical rules or the late-binding inheritance rules control which function gets called. We're pretty happy with how simple this foundation turned out, given everything we're trying to build on top of it.
:::Wow! Excellent. I am looking forward to learning this. Cheers. [[User:Markhobley|Markhobley]] 16:50, 18 July 2011 (UTC)