Help for bootstrapping a library

I’m going to develop a library to read and write positional files. I’m analyzing different implementations for configuration of fields (name, offset, lenght, fill char).

The simplest solution that I tought is a map to represent this configuration. I’m also thinking to macro, but I’m not sure if macro is the right solution.

Any suggestion?

Thank you!

2 Likes

A macro isn’t a data type. It’s an abbreviation for some piece of code, ( at the most basic level).

You might end up writing some macros to help with manipulating your basic data types. Often this is done to present “ugly” structs as more readable versions. For example:

1…3

is a macro for this code

%{_struct_: Range, first: 1, last: 3 }

Which is also a macro for even less readable code.

%{ :__struct__ => :“Elixir.Range” , :first => 1, :last => 2 }

Writing macros is about making your code “usable”, not functional. I’d write the first version with a Map or Keyword List and then think whether a macro could make it much more usable.

2 Likes