Cleaning up code

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Cleaning up code

Donald Steven
I need several large maps whose data will need to be accessed and
updated in a number of functions.  I've defined them in main() just to
get started, but they're so extensive that they swamp the readability of
main().  I haven't found a way to "include" them as 1) erlang won't
accept simple file inclusion anywhere (like m4) and 2) my attempt to
define a map in an .hrl file (like a -record definition), as in:

keywords = #( ...}.  or Keywords = #( ...}.

just produces error messages.  I could use m4, but ...

Any suggestions?  Thanks.

Don

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Cleaning up code

Hugo Mills-2
On Thu, Jan 31, 2019 at 09:20:43AM -0500, Donald Steven wrote:

> I need several large maps whose data will need to be accessed and
> updated in a number of functions.  I've defined them in main() just
> to get started, but they're so extensive that they swamp the
> readability of main().  I haven't found a way to "include" them as
> 1) erlang won't accept simple file inclusion anywhere (like m4) and
> 2) my attempt to define a map in an .hrl file (like a -record
> definition), as in:
>
> keywords = #( ...}.  or Keywords = #( ...}.
>
> just produces error messages.  I could use m4, but ...
>
> Any suggestions?  Thanks.
   It's not clear how you're using the data, but that sounds like
either a ETS table, or a separate server process to manage the data in
each map.

   If you're only concerned about the size of the initialisation for
each map, then you could just define them in a function and call that
in your main():

main() ->
    Map1 = init_map1(),
    ...


init_map1() ->
    #{a => 3, b => 4, ...}.

   Hugo.

--
Hugo Mills             | The last man on Earth sat in a room. Suddenly, there
hugo@... carfax.org.uk | was a knock at the door.
http://carfax.org.uk/  |
PGP: E2AB1DE4          |                                        Frederic Brown

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Cleaning up code

Donald Steven
Thanks everyone.  I put the data in a separate module and that works (so
far) well. But I'll look into ETS tables, other processes, and other
ideas.  Much appreciated.

Don

On 1/31/2019 9.30 AM, Hugo Mills wrote:

> On Thu, Jan 31, 2019 at 09:20:43AM -0500, Donald Steven wrote:
>> I need several large maps whose data will need to be accessed and
>> updated in a number of functions.  I've defined them in main() just
>> to get started, but they're so extensive that they swamp the
>> readability of main().  I haven't found a way to "include" them as
>> 1) erlang won't accept simple file inclusion anywhere (like m4) and
>> 2) my attempt to define a map in an .hrl file (like a -record
>> definition), as in:
>>
>> keywords = #( ...}.  or Keywords = #( ...}.
>>
>> just produces error messages.  I could use m4, but ...
>>
>> Any suggestions?  Thanks.
>     It's not clear how you're using the data, but that sounds like
> either a ETS table, or a separate server process to manage the data in
> each map.
>
>     If you're only concerned about the size of the initialisation for
> each map, then you could just define them in a function and call that
> in your main():
>
> main() ->
>      Map1 = init_map1(),
>      ...
>
>
> init_map1() ->
>      #{a => 3, b => 4, ...}.
>
>     Hugo.
>

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions