diff --git a/README.md b/README.md index 643f8a6..b4aa821 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,8 @@ this is me (PRH) trying to learn some front end web dev because pixels are important despite my wishes. + +# notes + +## goal queue + diff --git a/src/wfc_wfchar.erl b/src/wfc_ltr.erl similarity index 65% rename from src/wfc_wfchar.erl rename to src/wfc_ltr.erl index 78b39e7..5ce8772 100644 --- a/src/wfc_wfchar.erl +++ b/src/wfc_ltr.erl @@ -1,10 +1,10 @@ -% @doc called wfchar to disambiguate from +% @doc called ltr to disambiguate from % % mathematically, this is a variable like "a", "b", "c", etc --module(wfc_wfchar). +-module(wfc_ltr). -export_type([ - wfchar/0 + ltr/0 ]). -export([ @@ -22,17 +22,17 @@ % - numbers ok % - no non-ascii chars --opaque wfchar() :: {c, binary()}. +-opaque ltr() :: {c, binary()}. %%----------------------- %% constructors/destructors %%----------------------- --spec validate(WfChar) -> Result - when WfChar :: wfchar(), +-spec validate(Ltr) -> Result + when Ltr :: ltr(), Result :: ok | {error, Reason :: string()}. -% @doc validate if a candidate wfchar is well-formed and the inner binary is +% @doc validate if a candidate ltr is well-formed and the inner binary is % legal validate({c, Binary}) -> @@ -43,25 +43,25 @@ validate({c, Binary}) -> Error end; validate(Term) -> - Error = wfc_utils:emsg("wfc_wfchar:validate failed; malformed wfchar: ~p", [Term]), + Error = wfc_utils:emsg("wfc_ltr:validate failed; malformed ltr: ~p", [Term]), {error, Error}. -spec from_binary(Binary) -> Result when Binary :: binary(), - Result :: {ok, wfchar()} + Result :: {ok, ltr()} | {error, Reason :: string()}. % @doc -% make sure the binary is a legal wfchar and wrap it in a {c, Binary} tuple +% make sure the binary is a legal ltr and wrap it in a {c, Binary} tuple % @end %% initial char must be [a-z] from_binary(<>) when $a =< L, L =< $z -> new2(<>, Rest); from_binary(Char = <>) -> - {error, wfc_utils:emsg("wfc_wfchar:from_binary(~p): illegal lead character: ~p", [Char, L])}; + {error, wfc_utils:emsg("wfc_ltr:from_binary(~p): illegal lead character: ~p", [Char, L])}; from_binary(Char) -> - wfc_utils:err("wfc_wfchar:from_binary(~p): malformed argument", [Char]). + wfc_utils:err("wfc_ltr:from_binary(~p): malformed argument", [Char]). %% rest must be [A-Za-z0-9_] new2(Acc, <>) when ($A =< L andalso L =< $Z) @@ -73,11 +73,11 @@ new2(Acc, <<>>) -> {ok, {c, Acc}}; new2(Acc, Rest = <>) -> WholeChar = <>, - Error = wfc_utils:emsg("wfc_wfchar:new2(~p, ~p): illegal character in wfchar: ~p; WholeChar: ~p", [Acc, Rest, BadChar, WholeChar]), + Error = wfc_utils:emsg("wfc_ltr:new2(~p, ~p): illegal character in ltr: ~p; WholeChar: ~p", [Acc, Rest, BadChar, WholeChar]), {error, Error}. --spec to_binary(wfchar()) -> binary(). +-spec to_binary(ltr()) -> binary(). to_binary({c, X}) -> X. diff --git a/src/wfc_word.erl b/src/wfc_word.erl index 53bbb47..2a74ad0 100644 --- a/src/wfc_word.erl +++ b/src/wfc_word.erl @@ -1,4 +1,4 @@ -% @doc a word is an ordset of wfchars +% @doc a word is an ordset of ltrs % % multiplication is implied in a word % @@ -15,12 +15,12 @@ %% constructors one/0, validate/1, - from_wfchars/1, to_wfchars/1, + from_ltrs/1, to_ltrs/1, %% ops mul/2, mul/1 ]). --opaque word() :: {w, ordsets:ordset(wfc_wfchar:wfchar())}. +-opaque word() :: {w, ordsets:ordset(wfc_ltr:ltr())}. %%---------------------------- %% constructor @@ -32,26 +32,26 @@ one() -> {w, []}. -validate(_) -> error(nyi). -to_wfchars(_) -> error(nyi). +validate(_) -> error(nyi). +to_ltrs(_) -> error(nyi). --spec from_wfchars(WfChars) -> Result - when WfChars :: list(wfc_char:wfchar()), +-spec from_ltrs(Ltrs) -> Result + when Ltrs :: list(wfc_ltr:ltr()), Result :: {ok, word()} | {error, Reason :: string()}. -from_wfchars(Chars) -> - from_wfchars(ordsets:from_list(Chars), []). +from_ltrs(Chars) -> + from_ltrs(ordsets:from_list(Chars), []). -%% validate each char -from_wfchars([WfChar | Rest], Acc) -> - case wfc_wfchar:validate(WfChar) of - ok -> from_wfchars(Rest, [WfChar | Acc]); +%% validate each letter +from_ltrs([Ltr | Rest], Acc) -> + case wfc_ltr:validate(Ltr) of + ok -> from_ltrs(Rest, [Ltr | Acc]); Error -> Error end; % done, all good -from_wfchars([], Acc) -> +from_ltrs([], Acc) -> {ok, {w, lists:reverse(Acc)}}. @@ -59,24 +59,17 @@ from_wfchars([], Acc) -> %% ops %%---------------------------- --spec mul(word(), word()) -> Result - when Result :: {ok, word()} - | {error, Reason :: string()}. +-spec mul(word(), word()) -> word(). % @doc product of two words +% +% assumes the words are valid mul({w, X}, {w, Y}) -> - case from_wfchars(ordsets:union(X, Y)) of - Result = {ok, _} -> Result; - Error -> Error - end. + {w, ordsets:union(X, Y)}. --spec mul(Words) -> Result - when Words :: [word()], - Result :: {ok, word()} - | {error, Reason}, - Reason :: string(). +-spec mul([word()]) -> word(). % @doc multiply a list of words together mul([Word | Rest]) -> mul(Word, mul(Rest)); -mul([]) -> {ok, one()}. +mul([]) -> one().