Re: maps string question

Java House <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CAJYUOtc6S=cLORHO2rpBDvs0kfOr+ck+SgDXSDbdN9TwdVWE5Q@mail.gmail.com>
Thank you Roberto and Mark for the clarification.
I am loading the data from a file using the file:consult(MapData)
Currently the file looks like this
{"key1", {"data1"}}.
{"key2", {"data2"}}.

If I want to have all binary for consistency does this means that I need to
write into the file as
{<<"key1">>, {<<"data1">>}}.
{<<"key2">>, {<<"data2">>}}.

Kind Regards
Nikolas

Στις Τετ, 13 Οκτ 2021 στις 11:24 μ.μ., ο/η Roberto Ostinelli <
[email protected]> έγραψε:

> <<“key”>> is a binary, “key” is a list, so they are not the same.
> maps:get/2 raises because the key is not found.
>
> > string:equal(Key1, Key11).
>
> The string representation for both is the same, hence this return true.
>
> Hope this helps,
> r.
>
> > On 13 Oct 2021, at 23:05, Java House <[email protected]> wrote:
> >
> > 
> > Hello
> > I am having a problem with maps and strings as keys.
> > My understanding that the the two string formats "string" and
> <<"string">> are identical but as you can see from the transcript bellow
> maps does not think so.
> > I searched but I couldn't find any function to convert form "string" to
> <<"string">> or the other way around.
> > How can I make maps to accept both format of strings?
> >
> > Erlang/OTP 24 [erts-12.0] [source] [64-bit] [smp:8:8] [ds:8:8:10]
> [async-threads:1] [jit]
> >
> > Eshell V12.0  (abort with ^G)
> > 1> Key1 = "key1".
> > "key1"
> > 2>
> > 2> Key11 = <<"key1">>.
> > <<"key1">>
> > 3>
> > 3> string:equal(Key1, Key11).
> > true
> > 4>
> > 4> Map = maps:new().
> > #{}
> > 5>
> > 5> Map1 = maps:put("key1", {something}, Map).
> > #{"key1" => {something}}
> > 6>
> > 6> maps:get(Key1, Map1).
> > {something}
> > 7>
> > 7> maps:get(Key11, Map1).
> > ** exception error: bad key: <<"key1">>
> >      in function  maps:get/2
> >         called as maps:get(<<"key1">>,#{"key1" => {something}})
> >         *** argument 2: not a map
> > 8>
> > 8> maps:get("key1", Map1).
> > {something}
> > 9>
> > 9> maps:get(<<"key1">>, Map1).
> > ** exception error: bad key: <<"key1">>
> >      in function  maps:get/2
> >         called as maps:get(<<"key1">>,#{"key1" => {something}})
> >         *** argument 2: not a map
> > 10>
> >
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.