vasspilka

vasspilka

Calling for Veteran Macro user or guru for questions/help

Hello there everyone,

I’ve been working on this pet project for a while now. It’s a very interesting idea, the concept is around a content sharing platform but instead of each person having a personalized feed that they can scroll through, the content exists in locations that can be explored by users.

Here is the repo to the project

One of the core concepts in this platform are actions that can be taken by users, right now to handle all the actions I define functions in a module I call Ruleset.Basic. This seems to work well for now however I can see this will get out of hand as I’m going to be defining more functionality, furthermore I envisioned this platform with extendible and composable rulesets, where one can define actions on separate modules (ideally using some macros to make them cleaner) and then one could put these actions into a ruleset module. By doing something like

defmodule SomeRuleset do
  use Ruleset
  
  register_actions [ActionModule1, ActionModule2, ActionModule3]
  
  # Other ruleset functionality
end

I tried to work on the DSL to come up with how I would ideally like to define these actions and some expriments are here and here.

I would like to ask of the community if they could help me figure this out.

The requirements are:

  1. Defining actions is clean and effortless to do
  2. Actions defined can be included in different ruleset modules
  3. Undefined functionality defaults to doing nothing

One solution I came up with while writing this would be to use structs as a basis to define the functions in the end. That would require writing less macros and seems it could be quite extendible and flexible.

Something among the lines

%DefinedAction{
  name: :some_action,
  cost: 20,
  on_action_taken: fn exlorer, action -> "updates on explorer on action taken" end,
  valid_when: fn exlorer, action -> "validation before taking action" end,
  reaction: %{
    journey: [affect: :location]
  },
  affects: %{
    exlorer: fn exlorer, action -> "updates on explorer on action passed" end,
    location: fn location, action -> "updates on explorer on action passed"
  }

And then this struct could be used to define the functions with much less fuzz than having several macros one for each key we have here.

Would the former make sense? Would it be a good solution to problem?

Thank you for taking the time to read, Is anyone with interest in helping me figure out an ellegant solution?
Also if anyone find the project a cool idea and want to help out in any way let me know. There is lots to do still and any help is appreciated!!

Most Liked

LostKobrakai

LostKobrakai

I would suggest you build the functionality without macros first. Take the time to come up with some examples covering your intended usecases quite well (you know some simple ones, some complex, …). When you‘re done it‘ll be way easier to see where exactly macros can provide more succinct means of writing those modules.

vasspilka

vasspilka

Sorry to be reviving this thread. I just wanted to say I managed to solve the abstraction without macros.
All I use is modules behaviors and a bit of metaprogramming. I am sure protocols would also do but I have had less experience with them. I might be writing an article about the app next week so anyone interested stay tuned :slight_smile:

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
shahryarjb
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
Fl4m3Ph03n1x
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
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement