maps string question

Java House java4dev@REDACTED
Sun Oct 17 19:43:07 CEST 2021


Thank you Maria, for the explanation.
I have indeed only the last year start concentrating my efforts in Erlang.
I am trying to build a prototype for one of my ideas using Erlang as I want
to try something different than Java.
It is easy to forget each time the special handling of strings in erlang.
I have checked several erlang projects in github and my understanding is
that most projects are converting to binary all strings just before adding
them into structures like maps.
It is really sad that at least BIF  when reading files are not
automatically converting all double quoted data  to binary instead of lists.

Kind regards
Nikolas

Στις Σάβ, 16 Οκτ 2021 στις 6:15 μ.μ., ο/η Maria Scott <
maria-12648430@REDACTED> έγραψε:

> Hi Nikolas,
>
> > 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">>}}.
>
> Maybe you should tell us a bit more about what you are trying to do here,
> in context =^^=
>
> It doesn't really matter whether you are using lists or binaries here, as
> long as you are using the same to access them in the program.
> And however that may be, as the original question was about keys, there is
> no need to change the values to binaries here, as long as your program
> handles either lists or binaries or both.
>
> If, by a guess, you are using this file as some sort of config from which
> you are filling a virgin map, you could just write a map into the file,
> like #{<<"key1">> => {<<"value1">>}, <<"key2">> => {<<"value2">>}}.
>
> Anyway... no offense, but I get the impression that you don't really
> know/understand what lists and binaries are? "..." and <<"...">> are not
> different ways to say string-ish. There are no strings in Erlang. "key1" is
> just convenient syntactic sugar to write a list of integers, namely [107,
> 101, 121, 49], and <<"key1">> is just convenient syntactic sugar to write a
> binary, namely <<107, 101, 121, 49>>.
> For an easy-to-graps explanation, you may want to read
> https://learnyousomeerlang.com/starting-out-for-real#lists and the
> following paragraphs.
>
> Kind regards,
> Maria
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20211017/823afb86/attachment.htm>


More information about the erlang-questions mailing list