ubill

ubill

Iex Shell: How to delete/overwrite an alias in the shell?

I have asked this question on Slack, no solutions from there, so putting it up here.

The situation is,

Let’s say I’ve typed in the iex shell alias Asdf.Qwer, but actually what I need now is simply Qwer , I have no way to clear Asdf.Qwer because alias Qwer just again gives me Asdf.Qwer . So am I forever stuck with that? Or is there a way to reset/delete aliases

In other words, Qwer is now forever referring to Asdf.Qwer because of my mistype, and there is no way to delete/say that I don’t want this anymore. Or is there?

(P.S. an unrelated question, is the source code of Elixir Forum available as open source somewhere? It’s a great interface and I admire it very much.)

First 10 of 11 Posts Switch mode

bobbypriambodo

bobbypriambodo

Is closing and reopening the shell (or via respawn) not a viable solution? (basically it will clear all bound variables and aliases in the shell.)

ubill

ubill OP

Thanks, but I don’t want to clear all variable bindings I have currently declared so far and am working on something. (Otherwise just ctrl-C twice out from the shell and coming in back again would have been done.)

Reason I’m asking is to see whether this possibility is already there, just that I don’t know the way how-to.

And Erlang’s shell did have an f() / f(variable) function that cleared the binding (for all/a variable), so I just want to find out if there’s something along the same idea in Iex.

ubill

ubill OP

It may be the aliases are stored in some (state-holding) variable or struct somewhere, like in Python-world, ‘sys.modules’ or such. But I don’t know.

muhifauzan

muhifauzan

Since you use alias which is alias Asdf.Qwer, you can refer to the original Qwer using Elixir. Call it like this Elixir.Qwer.

bobbypriambodo

bobbypriambodo

Hmm, funny, it seems that you can overwrite alias in some cases and can’t in other cases. I’ve played with this:

iex> alias Asdf.Qwer
Asdf.Qwer
iex> Qwer
Asdf.Qwer

# still not working
iex> alias Qwer
Asdf.Qwer
iex> alias Qwer, as: Qwer
Asdf.Qwer

# this works?
iex> alias Foo, as: Qwer
Foo
iex> Qwer
Foo

# this also works
iex> alias Bar.Qwer
Bar.Qwer
iex> Qwer
Bar.Qwer

# funnily, this seemed to work at first glance (but really doesn't)
iex> alias Elixir.Qwer
Qwer # refers Qwer, yeay!
iex> Qwer
Bar.Qwer # it reverts, the alias doesn't work.
josevalim

josevalim

Creator of Elixir

This is a bug. Can you please file a bug report?

muhifauzan

muhifauzan

Yeah, I can confirm this. I also just playing around with alias in IEx with the same result as yours.

bobbypriambodo

bobbypriambodo

Will do!

ubill

ubill OP

Thanks guys. Just saw the replies as I’ve been away for the holidays.

@bobbypriambodo’s tests and attempts did make sense but ultimately discovered that it couldn’t behave as expected or intended; I tried and confirmed that too.

# originally already before this `alias Asdf.Qwer`
iex(42)> Qwer
Asdf.Qwer 
iex(43)> alias Elixir.Qwer, as: Qwer
Qwer      
iex(44)> Qwer
Asdf.Qwer 
iex(45)> alias Foo, as: Qwer
Foo       
iex(46)> Qwer
Foo       
iex(47)> Elixir.Qwer
Qwer      
iex(48)> alias Elixir.Qwer, as: Qwer
Qwer      
iex(49)> Qwer
Foo 

So logging as a bug does appear to make the most sense. Thanks again everybody!! :grinning:

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement