ubill

ubill

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.)

Showing Posts 1 to 10

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? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews