小编San*_*oni的帖子

在elixir sigil中逃脱闭括号

我想要一个自定义的sigil,这样我每行可以有一个元素.

这是我的代码

def sigil_l(text,[]), do: String.split(text,"\n")
Run Code Online (Sandbox Code Playgroud)

这适用于

~l(Clash of Titans
   The day after Tomorrow
   The Transporter
 )
Run Code Online (Sandbox Code Playgroud)

这失败了

~l(The man from Earth (2007)
   Gone Girl (2014)
   )
Run Code Online (Sandbox Code Playgroud)

请注意上面的括号

这是错误消息

"{" starting at line 38 is missing terminator "}". Unexpected token: )
(elixir) lib/kernel/parallel_compiler.ex:97: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8
Run Code Online (Sandbox Code Playgroud)

预期的结果是

["The man from Earth (2007)",
"Gone Girl (2014)"]
Run Code Online (Sandbox Code Playgroud)

需要更改哪些代码.我是否还需要在输入中添加任何字符并处理sigil defination?

更新

@AbM提供的解决方案是正确的.我在elixir版本1.0.4上,所以它不起作用.它适用于1.1.x.

~l(The man from Earth (2007\)
   Gone Girl (2014\)
   )
Run Code Online (Sandbox Code Playgroud)

sigils elixir

0
推荐指数
1
解决办法
301
查看次数

标签 统计

elixir ×1

sigils ×1