Syntax Error in Code Example from Website
When I try to execute the first code example from the website in an interactive shell, I get a syntax error. I have no clue about what could possibly cause that syntax error. Could it be possible that this is a bug in the parser that crept in quite recently, and nobody but I noticed? I'm just guessing because I find it quite unlikely that this problem has been existing for a longer time, as somebody else would probably have noticed earlier then. I'm using the newest Elixir from the master branch. I haven't tried any other Elixir so far.
Below is the code with the stacktrace I get:
Erlang R16B (erts-5.10) [source] [64-bit halfword] [smp:2:2] [async-threads:0] [kernel-poll:false]
Interactive Elixir (0.7.3.dev) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> defmodule Yo muthafucka do
...(1)> IO.puts "Definin tha function ghetto"
...(1)>
...(1)> def ghetto do
...(1)> IO.puts "Yo muthafucka Ghetto"
...(1)> end
...(1)>
...(1)> IO.puts "Function ghetto defined"
...(1)> end
** (SyntaxError) iex:1: syntax error before: muthafucka
/usr/local/lib/erlang/lib/parsetools-2.0.7/include/yeccpre.hrl:128: :elixir_parser.yecctoken_end_location/1
/usr/local/lib/erlang/lib/parsetools-2.0.7/include/yeccpre.hrl:113: :elixir_parser.yeccpars1/7
/usr/local/lib/erlang/lib/parsetools-2.0.7/include/yeccpre.hrl:56: :elixir_parser.yeccpars0/5
src/elixir_translator.erl:17: :elixir_translator.forms/4
src/elixir_translator.erl:27: :elixir_translator.forms!/4
src/elixir.erl:96: :elixir.eval/4
/home/klausi/dev/elixir/lib/iex/lib/iex/server.ex:7: IEx.Server.start/1
This is doesn't working, because you have space in the name of module: Yo muthafucka
You need take a name of module without space or using an atom syntax, like: :"Yo muthafucka"
The example from this site looks like to be wrong.
This works:
iex(1)> defmodule Yomuthafucka do
...(1)> IO.puts "Definin tha function ghetto"
...(1)> def ghetto do
...(1)> IO.puts "Yo muthafucka Ghetto"
...(1)> end
...(1)> IO.puts "Function ghetto defined"
...(1)> end
And for the future, I think it is MUCH better to use official guide: http://elixir-lang.org/
Yeah, exactly. The website linked on the issue was generated automatically and changed some of the words, rendering an invalid syntax.