#process.Pid to String?
1 messages · Page 1 of 1 (latest)
You can turn anything into a string with string.inspect. I don't think there's anything for parsing a PID, though.
Wild guess: You might want to look into named processes.
Note the format isn’t stable so it’s not suitable for parsing
There isn’t anything you can practically do by parsing a pid
There are interestingly some Erlang functions that can do that (stringify and parse a pid) but they are very explicitly only for debugging purposes and not to be used in applications, just in case you are interested:
https://www.erlang.org/doc/apps/erts/erlang.html#list_to_pid/1
I was using that one for a BEAM inspector / debugging type tool
Right, not so practical but it was just out of curiosity.
I was practicing Gleam, and found a challenge for my self - how can I parse the PID info?
The process.self spits out something like this: //erl(<0.89.0>)
If I can take off the brackets and filter out the numbers within a list, and check if there are 3 elements. That would be a good small puzzle for me.
This is purely my learning purpose, so the code is not the most efficient. Any suggestion would be appreciated, but the string.inspect is the one I was looking for.
If you really want to just parse that inspect representation into a list for fun/learning, I'd just do it like so:
input
|> string.drop_start(7)
|> string.drop_end(2)
|> string.split(".")
should give you the same
Oh, that makes sense. We can just ignore the first 7 and last 2 from the original string.
Discord is new to me. I should also learn how to format a code snippet in the chat as well 😅
io.println("hello")
io.println("hello")
you can do
to get the rust syntax highlighting, which is close enough to gleam
You can't! There's no accessible information in a pid, the format can change at any point