Created
July 24, 2021 13:18
-
-
Save plvhx/a310dad15002f3cfc1609f3d5d009a14 to your computer and use it in GitHub Desktop.
erlang is shit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(main). | |
-author('u know who i am better than me ~'). | |
-export([start/0]). | |
%% internal callback when calling | |
%% array:foldl | |
adder(_, V, A) -> V + A. | |
log(Arr) -> | |
log_impl(Arr, array:size(Arr), 0). | |
log_impl(_Arr, Size, Index) when Index == Size -> ok; | |
log_impl(_Arr, Size, Index) when Index < Size -> | |
io:fwrite("value: ~p~n", [array:get(Index, _Arr)]), | |
log_impl(_Arr, Size, Index + 1). | |
start() -> | |
C0 = array:set(0, 1, array:new()), | |
C1 = array:set(1, 2, C0), | |
C2 = array:set(2, 3, C1), | |
C3 = array:set(3, 4, C2), | |
C4 = array:fix(C3), | |
log(C4), | |
io:fwrite( | |
"after calling array:foldl = ~p~n", | |
[array:foldl(fun adder/3, 0, C4)] | |
). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment