elixir

IEx - How to cancel multiline command?


When I use IEx and make a typo like additional bracket or ", then most of the time I get a syntax error. But there are cases like this one:

iex(3)> Enum.each '12345', &(IO.puts(&1"))    
...(3)> end   
...(3)> )   
...(3)> '    
...(3)> end    
...(3)> ""    
...(3)> ... ? How to produce syntax error ?    
...(3)>     
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded    
      (v)ersion (k)ill (D)b-tables (d)istribution   

I cannot make a syntax error and continue from scratch and I have to relaunch entire IEx. Is there any keyboard shortcut or command to skip performing current iex(3) and go to next iex(4)?


Solution

  • Start your line with #iex:break

    iex(1)> Enum.each '12345', &(IO.puts(&1"))    
    ...(1)> ...
    ...(1)> #iex:break
    
    ** (TokenMissingError) iex:1: incomplete expression
    

    This is documented in Elixir's IEx documentation in section Expressions in IEx