RFC: do not redefine def
macro and use attribute tags
#2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've made a mistake making the original pull request (#1) from master branch. This is a fix for this so I can still work on this lib, adding new features.
I've seen your talk yesterday - nice one! DbC is a great concept especial in Elixir/Erlang in creating fault tolerant systems.
This pull request is meant to be of a Request For Comment and initiating a discussion. My implementation, removes the need to redefine
def
macro (redefining core functions/macros is somewhat iffy and can have side effects, especial if another module does the same thing). Additionally, adding a contract to a functions feels more like it's a meta information about that function, so attributes are more appropriate way of assigning a contract to a function (tagging it with a contract).By doing this that way, (in the future) we can extend this by adding another attribute for defining how to inform about a broken condition:
which will return a
{:error, result}
. Or maybe a information what part of contract was broken.Unfortunately, since attributes require values, their arguments are evaluated first. This is why macro
contract
is needed, to return AST form of a conditions . It basically works as aquote
, but this can change if we'll add more information when raising on broken conditions (maybe similar information to what is returned byExCase.assert
macro).Pros:
def
macroModule.info :attributes
returnscontract_predicates
attribute containing information about each tagged functionsCons:
contract
macroAlso, I think we should use singular form
ensure
andrequire
.Cheers!