Kin

Kin

Sigil_r example not working as shown in the official docs

I am following the elixir official docs and on the sigil page here https://elixir-lang.org/getting-started/sigils.html#custom-sigils

this example:

sigil_r(<<"foo">>, ~c"i")

is not working for me. The output should be

~r"foo"i

but it is:

iex(48)> sigil_r(<<"foo">>, ~c"i")
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an iodata term

    (stdlib 5.0.2) :binary.list_to_bin({:sigil_c, [delimiter: "\"", line: 48], [{:<<>>, [line: 48], ["i"]}, []]})
    (elixir 1.15.5) expanding macro: Kernel.sigil_r/2
    iex:48: (file)

Marked As Solved

josevalim

josevalim

Creator of Elixir

You are right, it should be:

sigil_r(<<"foo">>, [?i])

Would you like to submit a PR to the docs or shall I update it?

Also Liked

Nicd

Nicd

Looks like it works with the old charlist syntax but not with the new:

iex(1)> sigil_r(<<"foo">>, 'i')
~r/foo/i
iex(2)> sigil_r(<<"foo">>, ~c"i")
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an iodata term

    (stdlib 5.1.1) :binary.list_to_bin({:sigil_c, [delimiter: "\"", line: 2], [{:<<>>, [line: 2], ["i"]}, []]})
    (elixir 1.15.6) expanding macro: Kernel.sigil_r/2
    iex:2: (file)

I guess the syntax has been changed to the new one without checking if it works. Filing an issue here could be a good starting point: GitHub - elixir-lang/elixir-lang.github.com: Website for Elixir · GitHub

Last Post!

Kin

Kin

Please, do it if you can.

Where Next?

Popular in Questions Top

ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement