Passing PID trough Erlang char_list ?

49 views
Skip to first unread message

mraptor

unread,
Oct 13, 2015, 6:43:35 PM10/13/15
to elixir-lang-talk
Is it possible to convert PID to char_list and then convert it back from char_list to PID ?

What type is PID anyway, I remember I read it is one of the basic types or m'I wrong ?


Kevin Montuori

unread,
Oct 13, 2015, 6:54:38 PM10/13/15
to elixir-lang-talk
>>>>> "m" == mraptor <mra...@gmail.com> writes:

m> Is it possible to convert PID to char_list and then convert it
m> back from char_list to PID ?

Yes:

:erlang.list_to_pid(:erlang.pid_to_list(self()))

k.

--
Kevin Montuori
mont...@gmail.com

Ben Wilson

unread,
Oct 13, 2015, 7:32:44 PM10/13/15
to elixir-lang-talk
It is indeed a basic type. Why might you be trying to do this by the way?

As an aside, you should check out the #elixir-lang IRC room on freenode, it's an easy way to get quick answers to stuff like this.

Alexei Sholik

unread,
Oct 14, 2015, 5:26:51 AM10/14/15
to elixir-l...@googlegroups.com
Out of curiosity, what problem are you trying to solve where you need to do that?

On Wed, Oct 14, 2015 at 1:43 AM, mraptor <mra...@gmail.com> wrote:
Is it possible to convert PID to char_list and then convert it back from char_list to PID ?

What type is PID anyway, I remember I read it is one of the basic types or m'I wrong ?


--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/404da176-face-4991-8bd5-fe85876193a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mraptor

unread,
Oct 14, 2015, 9:34:25 AM10/14/15
to elixir-lang-talk
When I want to prove Erlog(Prolog) goal Robert Verdig has provided very handy function i.e. :

> g = :erlog_io.read_string 'goal(some,thing).'
{:ok, {:goal, :some, :thing}}

to convert to structure which I then pass to prove() :

> :erlog.prove state, g

I thought if I convert PID to char_list I can concatenate it and get the structure with the PID, it didnt work ;(

iex(19)> s = :erlang.pid_to_list self
'<0.82.0>'
iex(20)> :erlog_io.read_string 'goal(some,thing,' ++ s ++ ').'
{:error, {1, :erlog_parse, {:expected, :")"}}}
iex(21)> the_goal = 'goal(some,thing,' ++ s ++ ').'
'goal(some,thing,<0.82.0>).'
iex(22)> :erlog_io.read_string the_goal
{:error, {1, :erlog_parse, {:expected, :")"}}}
iex(23)>

The only other possibility is to generate the structure with dummy-atom and then replace with PID before passing to  prove(),
which as you may expect is not that handy :)

In short trying to pass PID to Erlog and then back to Elixir !
Reply all
Reply to author
Forward
0 new messages