vasspilka

vasspilka

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!!

Showing Posts 1 to 4

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 OP

@LostKobrakai Hey, The functionality without macros is already written, it’s in the Ruleset.Basic module as I pointed out. The reason I want to start generating code is because I can already see that it will be hard to maintain otherwise. Furthermore some of the things I want seem to be imposible without using AST to dynamically define some of the functions.

These would include

  1. Composable rulesets
  2. Grouped action definition without complains from compiler

I have 3 actions right now, but I can easily see 10-20 or even 100 different types of actions, or even same actions with different costs/outcomes and that would not make sense to continue coding down the path I am

vasspilka

vasspilka OP

But you are right that maybe I can continue to work on this and define some more actions before going about trying to use macros or other types of code definition. Even though I feel this is the time to do so, as a lot of future work will now involve actions

vasspilka

vasspilka OP

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:

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews