【问题标题】:Nemerle OperatorAttribute parametersNemerle Operator属性参数
【发布时间】:2023-03-31 03:32:01
【问题描述】:

我的问题在以下代码的注释中。

namespace TestMacroLib
{
    [assembly: Nemerle.Internal.OperatorAttribute ("TestMacroLib", "multiply", false, 160, 161)] 
    // what does 160 and 161 represent? The parameters are "left" and "right", but that doesn't help.
    public macro multiply(op1, op2)
    {
        <[ ( $op1 * $op2 ) ]>
    }
}

此代码示例来自: Infix format for Nemerle macro

【问题讨论】:

    标签: macros attributes operators nemerle


    【解决方案1】:

    这些数字决定了运算符的优先级和关联性。如果第一个数字较小,则运算符是左结合的,如果第二个是右结合的。具有较大数字的运算符具有较高的优先级。乍一看很不直观,但仔细想想表达式解析的细节,还是有点意思的。

    【讨论】:

    • 我认为数字越大的运算符优先级越高。看看这两个运算符,来自Nemerle's source code[assembly: Nemerle.Internal.OperatorAttribute ("Nemerle.Core", "&amp;&amp;", false, 160, 161)] [assembly: Nemerle.Internal.OperatorAttribute ("Nemerle.Core", "||", false, 150, 151)]
    • 谢谢,我的错。固定。
    猜你喜欢
    • 1970-01-01
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    • 2019-12-16
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    相关资源
    最近更新 更多