2

Would it be possible to change the environment variables of an erlang fun without interfering with the code concerning the function definition and the lambda lifting?

Specifically I would like to explicitly change the pid(<12036.69.0>) on the env of a fun that has this info:

[{pid,<12036.68.0>},
 {module,expl},
 {new_index,7},
 {new_uniq,<<197,235,209,205,33,163,202,255,8,58,234,128,135,166,147,185>>},
 {index,7},
 {uniq,103767694},
 {name,'-test_no_pid/0-fun-1-'},
 {arity,0},
 {env,[<12036.69.0>]},
 {type,local}]

It does not matter what the fun does since I want this solution to be a general one that just changes all the pids on the env of the fun.

Panagiotis Fytas
  • 426
  • 2
  • 7
  • 12
  • Based on our private discussion, I think what you need is merely a way to *create* a new fun with the environment changed. – aronisstav Jun 13 '18 at 11:39

1 Answers1

3

No, that would break the referential transparency property of the fun as a constant value. It's no different from updating a field of a tuple, and such a destructive change could even make the garbage collector crash because it violates the internal assumptions about directions of pointers.

RichardC
  • 10,412
  • 1
  • 23
  • 24
  • Do you know of an alternative way of getting the abstract code of the function since it does not appear as part of the environment in this occasion? – Panagiotis Fytas Jun 12 '18 at 14:49
  • If the module is compiled with the debug_info flag, you can extract this info later from a chunk in the beam file. It contains the whole expanded syntax tree of the module. – RichardC Jun 12 '18 at 17:50
  • I added a different dimension in the question: how could one create a new fun with an updated environment? – aronisstav Jun 13 '18 at 11:57