我想用命名的可选参数定义函数,并将这些参数限制为具有特定头的表达式。使用未命名的可选参数很容易做到这一点。例如:
succ1[n_Integer: 0] := n + 1
succ1[]
succ1[4]
succ1[a]
给出
1
5
succ1[a]
作为所需的输出。但是,我无法弄清楚如何使用命名参数实现相同的目标:
Options[succ2] = {n -> 0}
succ2[OptionsPattern[]] := OptionValue[n] + 1
succ2[]
succ2[n -> 4]
succ2[n -> a]
之前的代码将1 + a
作为succ2[n -> a]
的输出。我希望将可选参数限制为n -> _Integer
(Rule[n, _Integer]
),以便n -> a
保持无评价。有没有办法做到这一点?
答案 0 :(得分:2)
@Ajax.ActionLink("OrderDetails", "OrderDetails","Orders",
new {id = @item.OrderId},
ajaxOptions: new AjaxOptions() { HttpMethod = "GET", AllowCache = false, InsertionMode = InsertionMode.Replace, UpdateTargetId = "Content_"+ @counter },
htmlAttributes: new { @class = "btn btn-primary", role="button", data_toggle="collapse" , href="#Panel_"+@counter ,aria_expanded="false", aria_controls="collapseExample" })
1
5
succ2 [n - > A]