我刚开始看Erlang并尝试编译我的第一个程序.与教程相比,一切看起来都不对,但我似乎无法摆脱这个错误.
这是我的代码,保存在'useless.erl'下:
-module(useless).
-export([add/2, hello/0, greet_and_add_two/1]).
add(A,B) ->
A + B.
%% Shows greetings.
%% io:format/1 is the standard function used to output text.
hello() ->
io:format("Hello, world!~n").
greet_and_add_two(X) ->
hello(),
add(X,2).
Run Code Online (Sandbox Code Playgroud)
我将目录更改为useless.erl的目录:
cd("C:/Users/CP/Documents/Erlang").
Run Code Online (Sandbox Code Playgroud)
但是,当我跑
c(useless).
Run Code Online (Sandbox Code Playgroud)
我明白了
useless.erl:1: cannot parse file, giving up
useless.erl:1: no module definition
error
Run Code Online (Sandbox Code Playgroud)
如果您的文件看起来没问题,但Erlang编译器抱怨它无法解析文件,那么您的代码可能包含无效编码.
根据文档, Erlang只接受源代码UTF-8或Latin-1编码.
有效编码是Latin-1和UTF-8,其中字符的大小写可以自由选择
请注意,您仍然只能在字符串和注释中使用扩展字符集:
在Erlang/OTP R16B中,Erlang令牌的语法被扩展为处理Unicode.支持仅限于字符串文字和注释.
如果出现解析错误或非法字符错误,您应该这样做
UTF-8或Latin-1编码使用较旧的Erlang版本(在Erlang 17之前),您可以尝试在文件的前两行中明确指定编码
%% coding: utf-8
%%% or
%% For this file we have chosen encoding = Latin-1
%%% or
%% -*- coding: latin-1 -*-
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
358 次 |
| 最近记录: |