【发布时间】:2019-12-13 06:33:54
【问题描述】:
您好,我正在尝试使用 Erlang 中的记录语法将变量绑定到封闭记录及其字段之一,但我不断收到此错误:
d:/Erlang/AeRlang/rec.erl:19: 之前的语法错误:子
d:/Erlang/AeRlang/rec.erl:17: 函数 isMale/1 未定义
d:/Erlang/AeRlang/rec.erl:17: 警告:函数 maleChildren/1 是 未使用
-module(rec).
-export([makeFam/0]).
-record(man,{name,
age,
children=[]}).
-record(child,{
name,
age,
sex
}).
makeFam()->
#man{name="Adrian",
age=33,
children=[#child{name="Daniel",age=33,sex="Male"},
#child{name="Chris" ,sex="Male"},
#child{name="Anne",age=33,sex="Female"}]
}.
fatherAndSons(Man#man{children=Ch})->{Man,[Elem|| Elem<-Ch,isMale(Elem)]}.
isMale(C#child{_,_,Y})->
case Y of
"Male"->true;
_ ->false
end.
我的isMale 方法有什么问题。我将封闭结构#child 绑定到变量C,并且我也在对其字段进行模式匹配。有什么问题?
P.S:这是否与在isMale 方法中我没有指定绑定变量Y 的字段的名称有关?
【问题讨论】:
标签: erlang pattern-matching record