crashangelbr

crashangelbr

No Populate Variable in Loop Each rumtine, Why?

Hello, I am learning elixir and I am not managing to populate my variables at runtime … inside a loop … Why do the variables go blank again every time?

def teste do
    t = String.split("sentence  [sentence]  <sem-s> N F S  @NPHR §DENOM #3->0", " ", trim: true)
    token = ""
    lemma = ""
    syntax = ""
    role = ""
    child = ""
    root = ""
    tags = []
    attrs = []
    t
    |> Enum.with_index()
    |> Enum.each(fn {e, i} ->
      if i == 0 do
        token = e
      else
        # Verb
        if i == 1 do
          lemma = e
        else
          # Syntax
          if i == Enum.count(t) - 3 do
            syntax = e
          else
            # Role
            if i == Enum.count(t) - 2 do
              role = e
            else
              # Dependency
              if i == Enum.count(t) - 1 do
                e = String.replace(e, "#", "")
                e = String.replace(e, "-", "")
                child = Text.mid(e, String.slice(e, 0..0), ">")
                root = Text.mid(e, ">")

                # ===================================================
                #Last Index >> Get All Variables and Inser in Mnesia
                # ===================================================
                IO.puts ">> #{token} >> #{lemma} >> #{syntax} >> #{role}"

              else
                # Tags
                if String.contains?(e, ["<", ">"]) == true do
                  [e | tags]
                else
                  # Attributes
                  [e | attrs]
                end
              end
            end
          end
        end
      end
    end)
  end

Most Liked

LostKobrakai

LostKobrakai

Read the answers on this topic from earlier today:

Where Next?

Popular in Questions Top

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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
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
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement