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

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
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
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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 records...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
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

We're in Beta

About us Mission Statement