简体   繁体   中英

Why is the syntax error coming in erlang spawn function call - “ syntax error before: ')' ”?

This is the code i am running in an online compiler

-module(helloworld). 
-export([start/0, call/2]). 

start() -> 
% error in the below line as  syntax error before: ')'
Pid = spawn(?MODULE, call, ["hello","world"] ),
io:fwrite("~p",[Pid]).


call(Arg1, Arg2) -> 
io:format("~p ~p~n", [Arg1, Arg2]). 

I tried erlang compiler online in tutorialspoint and can reproduce problem. I guess it got some problem in compiler, it's not your fault, just continue investigate Erlang :)

https://www.tutorialspoint.com/compile_erlang_online.php

You can change to this compiler online

https://paiza.io/en/projects/new?language=erlang

//Edit: The issue may become from editer of tutorialspoint . It makes compiler don't understand function spawn/3 , please add double quoute '' for spawn/3 function like below, It will compile and run:

 Pid = 'spawn'(?MODULE, call, ["hello","world"] ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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