KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What does it mean to compare functions in Erlang with the operators =:= , == , < , > , =< , >= ? I was playing around with the interpreter and got these results: Eshell V5.9.2 (abort with ^G) 1> X = fun() -> {} end. #Fun<erl_eval.20.82930912> 2> Y = fun() -> {} end. #Fun<erl_eval.20.82930912> 3> 3> {X == X, X =:= X}. {true,true} 4> {X >= X, X =< X}. {true,true} 5> {X > X, X < X}. {false,false} 6> 6> {X == Y, X =:= Y}. {true,true} 7> {X >= Y, X =< Y}. {true,true} 8> {X > Y, X < Y}. {false,false} This makes sense. It looks like it's comparing the abstract syntax tree of the two functions. But in this session X and Y are defined the same once again but are different, also now X<Y ? Eshell V5.9.2 (abort with ^G) 1> X = fun() -> {} end. #Fun<erl_eval.20.82930912> 2> 2> {X == X, X =:= X}. {true,true} 3> {X >= X, X =< X}. {true,true} 4> {X > X, X < X}. {false,false} 5> 5> Y = fun() -> {} end. #Fun<erl_eval.20.82930912> 6> 6> {X == Y, X =:= Y}. {false,false} 7> {X >= Y, X =< Y}. {false,true} 8> {X > Y, X < Y}. {false,true} So it looks like it's not comparing the AST or any sort of unique references. Maybe it is comparing references, just some optimization is happening and X and Y get bound to the same reference? If there is some explanation for this, what happens across different VMs or different nodes?
Tags (comma-separated)
Save Edits
Cancel