Я хочу разработать очень маленький скрипт, который читает предложение и генерирует в консоли вывод n-граммы.
Это пример
Example
"Show me the code."
Returns
[
"Show",
"Show me",
"Show me the",
"Show me the code",
"me",
"me the",
"me the code",
"the",
"the code",
"code"
]
Это мойкод:
defmodule M do
def main do
sentence = IO.gets("What is the sentence : ")
ls = String.split(sentence)
lsSize = length(ls)
Enum.each 0..lsSize , fn(x) ->
posNew = x+1
IO.puts Enum.at(ls,x)
Enum.each posNew..lsSize , fn(y) ->
currentWord = Enum.join([Enum.at(ls,x), Enum.at(ls,y)], " ")
IO.puts(currentWord)
end
end
end
end
Единственное, что я получаю, это:
What is the sentence : one two three
one
one two
one three
one
two
two three
two
three
three
Можете ли вы помочь мне с этим?Я не понимаю, почему значение currentCode не обновляется за пределами Enum.each и получает сброс.Я новичок в эрланге и эликсире, и поэтому я не понимаю проблемы в этом.
Спасибо!