繁体   English   中英

无法编译包含地图的模块

[英]Can't compile module containing maps

我正在通过本教程中的erlang学习Erlang

我无法编译地图示例:

-module(color).

-export([new/4, blend/2]).

-define(is_channel(V), (is_float(V) andalso V >= 0.0 andalso V =< 1.0)).

new(R,G,B,A) when ?is_channel(R), ?is_channel(G),
                  ?is_channel(B), ?is_channel(A) ->
    #{red => R, green => G, blue => B, alpha => A}.

blend(Src,Dst) ->
    blend(Src,Dst,alpha(Src,Dst)).

blend(Src,Dst,Alpha) when Alpha > 0.0 ->
    Dst#{
        red   := red(Src,Dst) / Alpha,
        green := green(Src,Dst) / Alpha,
        blue  := blue(Src,Dst) / Alpha,
        alpha := Alpha
    };
blend(_,Dst,_) ->
    Dst#{
        red   := 0.0,
        green := 0.0,
        blue  := 0.0,
        alpha := 0.0
    }.

alpha(#{alpha := SA}, #{alpha := DA}) ->
    SA + DA*(1.0 - SA).

red(#{red := SV, alpha := SA}, #{red := DV, alpha := DA}) ->
    SV*SA + DV*DA*(1.0 - SA).
green(#{green := SV, alpha := SA}, #{green := DV, alpha := DA}) ->
    SV*SA + DV*DA*(1.0 - SA).
blue(#{blue := SV, alpha := SA}, #{blue := DV, alpha := DA}) ->
    SV*SA + DV*DA*(1.0 - SA).

我的环境 是:

-Ubuntu 14.04
-Erlang R16B03 (erts-5.10.4)

执行结果:

1> c(color).
color.erl:9: syntax error before: '{'
color.erl:15: syntax error before: '{'
color.erl:29: syntax error before: '{'
color.erl:32: syntax error before: '{'
color.erl:34: syntax error before: '{'
color.erl:36: syntax error before: '{'
color.erl:3: function new/4 undefined
color.erl:12: function alpha/2 undefined
color.erl:12: function blend/3 undefined
error

读到它可能是文件编码,所以我使用了us-ascii,utf-8,utf-8-unix,结果相同。

语句#{red => R, ...}正在创建Map,它是最近添加的Erlang类型。

Erlang / OTP 17中引入了地图。 您需要升级VM才能使用它们。

您可以将软件包用于Ubuntu,或将kerl用于多个Erlang版本的本地/临时安装和管理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM