AtomVM icon indicating copy to clipboard operation
AtomVM copied to clipboard

term_to_binary doesn't support lambdas

Open jgonet opened this issue 11 months ago • 3 comments

Following code:

-module(hello_world).
-export([f/0, start/0]).

f() ->
    term_to_binary(fun() -> ok end).

start() ->
    ?MODULE:f(),
    ok.

crashes with

Unknown external term type: 106583908418080

Using external functions (term_to_binary(fun ?MODULE:f/0)) works.

jgonet avatar Feb 06 '25 20:02 jgonet

Question is, should we support this if erl_eval is not in the path?

pguyot avatar Feb 08 '25 09:02 pguyot

I don't get the question, are you asking if anything else than code in erl_eval needs that? The code bloat is a good argument but IMO it should be discussed more generally as well, sometimes you don't e.g. need all ETS machinery.

FWIW, we also need compressed, deterministic, and {minor_version, 2} for our usecase. I wonder if supporting all terms is needed for distribution as well.

jgonet avatar Feb 10 '25 09:02 jgonet

and it would also be nice if binary_to_term(Bin) would work when Bin is the binary representation of a fun as this potentially would enable me to implement some cli functionality.

elsbiet avatar Mar 15 '25 10:03 elsbiet