?~c(#{1+1}) This traps me in the expression authoring state

After typing ?~c(#{expression}):

Nothing I do closes it (nothing I type throws an error or exits the expression) :joy: I have to exit iex.

How can I close this in future, by the way the original expression was ?~c(#{g}) where g was matched to ?a + ?z.

I wanted to check the value of g using ? but I realised it would just give me ?g. So I used interpolation to get the value of g, I am aware this was silly as I would have gotten ?"187".

It seems as though it is trying to eval “187” but for some reason it’s not raising an error.

It would be great to know how to exit this, as I have had to recompile all the modules

Illustration


iex(73)> ?~c(#{g})
...(73)> '
...(73)> /
...(73)> ?
...(73)> emd
...(73)> ??
...(73)> }
...(73)> {
...(73)> {
...(73)> }}
...(73)> ............
...(73)> lolkjhv ygtijoujb
...(73)> =-0~9234567u8ui9oi
...(73)> 12q13567~667
...(73)> ####
...(73)> ''''
...(73)> end end
...(73)> [887]
...(73)> h.()
...(73)>    k
...(73)> :k
...(73)>
...(73)>

iex(4)> ?"187"
...(4)> d
...(4)> ?
...(4)> .
...(4)> .
...(4)> .
...(4)> .
...(4)> ......
...(4)> .

The magic incantation is: #iex:break <Enter>. A bit of a mouthful. You may want to bind it to some kind of system hotkey combo :slight_smile:

In terms of recompiling modules, as soon as I’m experimenting with more than one module I just make myself a mix project and use iex -S mix. It saves you many a headache.

1 Like

I tried using break``<Enter> it just takes break and then takes me to the next line. Then I tried actually typing #iex:break <Enter> , just in case, and it still did not work.

Am I not understanding?

edit: I of course tried #iex break then <Enter>

iex(1)> ?~
126
iex(2)> ?~c
** (SyntaxError) iex:2:3: syntax error before: c
    |
  2 | ?~c
    |   ^
    (iex 1.15.4) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.4) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.4) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 4.3.1.2) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
iex(2)> ?~c()
** (SyntaxError) iex:2:3: syntax error before: c
    |
  2 | ?~c()
    |   ^
    (iex 1.15.4) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.4) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.4) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 4.3.1.2) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
iex(2)> ?~c(#{})
...(2)>
...(2)>
...(2)> }
** (SyntaxError) iex:5:1: unexpected token: }

    HINT: the "(" on line 2 is missing terminator ")"

    |
  5 | }
    | ^
    (iex 1.15.4) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.4) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.4) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 4.3.1.2) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
iex(2)> ?~c(#{g})
...(2)> }
** (SyntaxError) iex:3:1: unexpected token: }

    HINT: the "(" on line 2 is missing terminator ")"

    |
  3 | }
    | ^
    (iex 1.15.4) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.4) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.4) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 4.3.1.2) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
iex(2)> ?
warning: found ? followed by code point 0xA (newline), please use ?\n instead
  iex:2:1

10
iex(3)> ?
warning: found ? followed by code point 0xA (newline), please use ?\n instead
  iex:3:1

10
iex(4)> ?"x"
...(4)> "
** (SyntaxError) iex:4:3: syntax error before: x
    |
  4 | ?"x"
    |   ^
    (iex 1.15.4) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.4) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.4) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 4.3.1.2) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
iex(4)>
1 Like

FYI: ? is not an operator, it is a syntax construct which just takes the next character and replaces this whole expression with integer literal, Therefore, ? works only with the single following character. You can’t use ? to get ord of the expression

3 Likes

Thanks, yes you.com (not trying to share a link or anything) told me that when I referred to ? as an operator in the search, so I had to change my reference to it in the search/question to “syntactic sugar”.

That’s great, the } works. I wonder why it did not work in my earlier attempts (in the first post). I must have dug a deeper hole when I was trying to raise an error.

Odd, I copy-pasted ?~c(#{expression}): and tried it before posting and it worked. I just tried again and it still worked! To be clear, by <Enter> I meant to press the enter key, everything else is literal. #iex:break has never not gotten me out of a hairy situation like that.

2 Likes

Heh, it was because I put a space in between #iex: and break .

Now that I see the img of it, I’ve used it and it worked. It even got me out of the one that } couldn’t fix.

Much appreciated.

I hope to* start using mix soon, just working my way through the books.

I agree the error is a bit jarring and still gets me sometimes (as in I think it didn’t work).

And yes, if you are working through a book I won’t rush you into mix.

Also, welcome to the forums!

Thanks, though I must admit I joined before, I just forgot which email I used. I joined and then revisited an old language for a while before returning.

I’m really positive about what I’ve seen while writing programs and scripts in elixir. By way of features It’s turning out to have what I hoped it would have and more.

1 Like

You have probably seen it, otherwise check out Livebook. It can be very nice for learning as a “bit more editor-y” iex.

1 Like

I installed it when doing an online video tutorial, however, I moved away from video tutorials as many of them did not have exercises and I wanted to learn by doing, so i started using the books. I will probably use Livebook after I’ve finished the first book.

I want to get familiar with things and use iex to check if something isn’t working within Livebook, or just as a troubleshooting aid.

1 Like

I don’t like typing and spamming with a lil bit of “”“”“”“”“”“”“”“”“”“”" seems to make iex take a hint it shouldn’t continue with the current expression :smile:

1 Like