In official DSLs document: Domain-Specific Languages (DSLs) — Elixir v1.18.4 , and in the very first example, it says we could implement a validator using data structures, and it provides the usage code here:
# 1. Data structures
import Validator
validate user, name: [length: 1..100], email: [matches: ~r/@/]
I used functions and macros before, so I understand the #2 and #3 examples. But English is not my native language, and I’m new to the DSLs thing, so I am wondering what is the module definition for the Validator in this example so that we can use it in the line:
validate user, name: [length: 1..100], email: [matches: ~r/@/]
I can’t find any answer from this forum, Google search, etc, so it seems to be very obvious for everyone. It makes me feel frustrated, but I really wanna know the answer. Please help to provide the example code for the definition of the ‘validate’, thanks in advance.
defmodule Validator do
# What is the definition of the 'validate' here?
# It can't be a 'def validate, do: :something', right? That's a function definition.
end