RFC: do not redefine def macro and use attribute tags#2
Open
x4lldux wants to merge 2 commits intoepsanchezma:masterfrom
Open
RFC: do not redefine def macro and use attribute tags#2x4lldux wants to merge 2 commits intoepsanchezma:masterfrom
def macro and use attribute tags#2x4lldux wants to merge 2 commits intoepsanchezma:masterfrom
Conversation
Changes the implementation to not redefine `def` macro. Additionaly, pre- and post-conditions are now attributes, since specifying a contract for a function, feels more as a "tagging" it with a contract.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
defmacro (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
contractis 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.assertmacro).Pros:
defmacroModule.info :attributesreturnscontract_predicatesattribute containing information about each tagged functionsCons:
contractmacroAlso, I think we should use singular form
ensureandrequire.Cheers!