idi527

idi527

In erl shell I can paste <x.y.z> and it would be parsed as a PID. From http://erlang.org/doc/man/shell.html:

The shell can parse commands with pids (<0.60.0>), ports (port<0.536>), references (#Ref<0.1662103692.2407792644.214210>), and external functions (fun<a.b.1>), but the command fails unless the corresponding pid, port, reference, or function can be created in the running system.

But in iex I seem to have to use pid/1,3, ref/1,4 functions, and I don’t know how to deal with ports (currently I use Port.list/0 but there’s probably a nicer approach) … Does anyone know if there is any format for pids, refs, ports, etc that iex can parse?

Showing Posts 1 to 8

OvermindDL1

OvermindDL1

╰─➤  iex
Erlang/OTP 21 [erts-10.1.1] [source] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:1] [hipe]

Interactive Elixir (1.7.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> h pid

                                def pid(string)                                 

Creates a PID from string.

## Examples

    iex> pid("0.21.32")
    #PID<0.21.32>


                                def pid(x, y, z)                                

Creates a PID with 3 non-negative integers passed as arguments to the function.

## Examples

    iex> pid(0, 21, 32)
    #PID<0.21.32>
    iex> pid(0, 64, 2048)
    #PID<0.64.2048>

That’s the format it uses. :slight_smile:

A Port is just a PID for note.

idi527

idi527 OP

So there is no way to use something like <0.21.32> to get #PID<0.21.32>? That is, without having to use a function? Just copy-pasting #PID<0.21.32> back into the iex would be great.

A Port is just a PID for note.

Thanks! But how can I use it? I see ports as [#Port<0.0>, #Port<0.2>, #Port<0.4>], and I can’t use pid(0, 0) or pid("0.0").

OvermindDL1

OvermindDL1

I think ports are considered ‘external pids’ (like pids on a remote system), so you can’t use the pid functions on those. Why not assign it to something? :slight_smile:

idi527

idi527 OP

Why not assign it to something? :slight_smile:

Sometimes I just don’t have this ability, so I default to Port.list/0 which is a bit annoying if there are many open ports. Unless the approach I showed above with copy-pasting is impossible due to some inner workings of iex,

So there is no way to use something like <0.21.32> to get #PID<0.21.32> ? That is, without having to use a function? Just copy-pasting #PID<0.21.32> back into the iex would be great.

something like port/2 (similar to ref/4 and pid/3) would be nice to have.

OvermindDL1

OvermindDL1

I think it would be possible to make such a function, wouldn’t be perfectly performant but if run from iex that wouldn’t really matter, just add something like def port(a, b), do: Enum.find(Port.list(), &(inspect(&1) == "#Port<#{a}.#{b}>")) to your iex helpers, like in a .iex.exs file that contains something like:

def IExHelpers do # Support both string and integral representations
  def port(i), do: Enum.find(Port.list(), &(inspect(&1) == i))
  def port(a, b), do: port("#Port<#{a}.#{b}>")
end
import IExHelpers
dch

dch

The way I do this is to store the last fews transaction (e.g. in Phoenix or Plug) into a ConCache, and then I can retrieve the original item from Cache. For long-running things, I pull them out of the Application.env or possibly a given GenServer state. It’s almost always for debugging, so the other option is to use tracing to collect the raw data as either function call parameters going in, or as return values on the way back.

idi527

idi527 OP

In my case I look up the ports with :sys.get_state, then use Port.list to get the position of the port, and then Enum.at to actually get the port … @OvermindDL1’s approach would save me one step, but still, just copy pasting #Port<0.2043> from :sys.get_state output and into iex would be great. What I wonder about is if there is a way to make iex recognize #Port<...>, #PID<...>, and #Reference<...> as not comments, but port, pid, and reference respectively.

wojtekmach

wojtekmach

Hex Core Team

As @michalmuskala wrote in a feature request we can currently do:

iex> :erlang.list_to_port('#Port<0.7>')
#Port<0.7>
— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
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
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
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
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; 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
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews