Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maps “地图”;“之前的语法错误”;(第一个元素)而URI.encode_查询(表单)_Maps_Elixir - Fatal编程技术网

Maps “地图”;“之前的语法错误”;(第一个元素)而URI.encode_查询(表单)

Maps “地图”;“之前的语法错误”;(第一个元素)而URI.encode_查询(表单),maps,elixir,Maps,Elixir,我已经做了几天了,我有一个问题: 每当我尝试将一个映射编码为查询字符串时,就会出现错误“syntax error before:chat_id” 但据我所知,这就是映射语法,不是吗?如图所示,在本示例中: iex> hd = %{"foo" => 1, "bar" => 2} iex> URI.encode_query(hd) "bar=2&foo=1 这里发生了什么 完整错误消息: == Compilation error on file lib/elixir

我已经做了几天了,我有一个问题:

每当我尝试将一个映射编码为查询字符串时,就会出现错误“syntax error before:chat_id”

但据我所知,这就是映射语法,不是吗?如图所示,在本示例中:

iex> hd = %{"foo" => 1, "bar" => 2}
iex> URI.encode_query(hd)
"bar=2&foo=1
这里发生了什么

完整错误消息:

== Compilation error on file lib/elixir.ex ==
** (SyntaxError) lib/elixir.ex:20: syntax error before: chat_id
    (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.Paral
lelCompiler.spawn_compilers/1

我不知道为什么会出现列出的错误,但是
URI.encode\u query/1
只返回一个
binary
参数。您正在尝试将其与
元组
进行模式匹配

你能粘贴更多的代码而不是仅仅那两行吗

iex(2)> URI.encode_query(form)
"chat_id=237&text=OMG+a+message"

嗯,它在IEx中起作用。。。。。。。。。。。我不知道错误在哪里。在链接到的文件中,
def req
后面有一个空格,这在Elixir中是不允许的(但错误消息与您在此处发布的消息不同)。删除空格后,文件将编译(有一些警告,但没有错误)。嗯,我删除了空格,仍然得到了相同的错误,“之前的语法错误:chat_id”,还有警告“在->的右侧始终需要表达式”。编辑:可能是我的elixir版本?不,它是1.4.0,最新版本只是1.4.2你是如何运行代码的?该文件包含一些无效代码(
@moduledoc
在模块外部)。你能发布可以使用elixir foo.exs运行的确切代码吗?我在Windows cmd上使用iex-S mix。我使用moduledoc进行注释,但我可以将其粘贴到模块中。而且,我从来没有处理过。exs,所以我不知道。编辑:我把@moduledoc放在模块内(当然是相同的结果),这就是我所做的。我认为这是其他文件的问题,而不是那个特定的文件。
iex(2)> URI.encode_query(form)
"chat_id=237&text=OMG+a+message"