【问题标题】:I dont understand why my first Elixir script failing我不明白为什么我的第一个 Elixir 脚本失败了
【发布时间】:2019-02-19 18:04:19
【问题描述】:

我正在努力学习 Elixir。

我找到了这个演示语法:

#---
# http://media.pragprog.com/titles/elixir16/code/spawn/pmap1.exs
# Excerpted from "Programming Elixir
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/elixir16 for more book information.
#---
defmodule Parallel do
  def pmap(collection, func) do
    collection
    |> Enum.map(&(Task.async(fn -> func.(&1) end)))
    |> Enum.map(&Task.await/1)
  end
end

result = Parallel.pmap 1..1000, &(&1 ​*​ &1)

我把上面的语法放在一个文件里:pmap1.exs

接下来我尝试用一​​个简单的 shell 命令运行它:

dan@h78:~/elxr/public/notes $ elixir pmap1.exs
** (SyntaxError) pmap1.exs:18: unexpected token: "​" (column 38, codepoint U+200B)
    (elixir) lib/code.ex:767: Code.require_file/2
dan@h78:~/elxr/public/notes $ 

我是不是运行不正确?

我在某处有语法错误吗?

【问题讨论】:

    标签: elixir


    【解决方案1】:

    由于某种原因,在您的代码示例中,有两个“零宽度空格”(Unicode 代码点 200B),一个位于 * 字符的每一侧。删除两个零宽度空格后,您的代码对我来说运行良好。

    (您正在为result 分配一个值,但没有打印它或用它做其他事情,所以它说warning: variable "result" is unused,但这是下一步。IO.inspect(result) 是一种快速的方法。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      相关资源
      最近更新 更多