shahryarjb
How to create a macro like def
Hello, I try to create a custom macro to implement some functions and structure I need in my project and my goal is to make a custom tools which is created by macro.
Please see my macro
delete_list_item(:roles, DeleteErrorComponent, false, do: fn x ->
IO.inspect(x)
end, before: fn x -> IO.inspect(x) end)
This Syntax is not good for me and I need a macro like this:
admin_ui delete_list_item(:roles, DeleteErrorComponent, false) do
call_function1
call_function2
call_function3
or a block code
before
call_function1
call_function2
call_function3
or a block code
end
My problems
- I couldn’t run all functions, then I use anonymous function.
- I couldn’t create a starter like
admin_uilikedef macro (def somthing) - I should write a comma to run
beforebut I need this like top code
I saw this link: elixir/lib/elixir/lib/kernel.ex at v1.12.3 · elixir-lang/elixir · GitHub
But I couldn’t understand all of them, I’m trying to figure out how elixir kernel did this
Thanks
Most Liked
al2o3cr
The keywords that introduce block-like constructs (do, after, else, rescue, catch) are special-cased in the tokenizer:
so adding additional ones like before in your example is impossible, short of modifying the language source.
1
Popular in Questions
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
In AR this is so simple
@articles = current_user.articles
How to do in Ecto?
def index(conn, _params) do
current_user = conn.assig...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir
iex(2)...
New
Other popular topics
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New








