vic/expat

Generated macro functions.

Closed this issue · 2 comments

vic commented

Following @OvermindDL1's idea:

Currently when you define a named pattern

   def var(name, meta, context) when is_atom(name) and is_list(meta) and is_atom(context)

The following macros are generated:

defmacro var()
defmacro var(bindings)
defmacro var(name, bindings)
defmacro var(name, meta, bindings)
defmacro var(name, meta, context, bindings)

var() will underscore all pattern variables not used in guard.
bindings is a Keyword of names to expressions, used to bind variables inside the pattern.
All other functions are just there for providing positional arguments (vs named ones via the last keyword)

Now, I'm thiking about adding a couple more:

defmacro var?(expr)
defmacro var!(bindings)

The first one will just check that expr conforms - that is it matches the pattern and all its guards are satisfied
and the second will raise an error unless all variables inside the patter are bound by name from bindings, it will be used for as data constructor, even for those patterns with guards.

vic commented

Now I'm thinking of no generating more macros, but just have Expat.match!(pattern) and match? just like we have Kernel.match?

Now I'm thinking of no generating more macros, but just have Expat.match!(pattern) and match? just like we have Kernel.match?

Though functions can't be used as guards.