Search code examples
concurrencyerlangerl

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]). 

Solution

  • 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"] ),