mraptor
Let say I have a tuple :
{:sum, %{x: 23}, %{y: 55 }}
Out of this how can I create the following function :
def sum({ %{x: 23}, %{y: 55 }} ), do: true
as a second question, let say I have :
{:sum, %{x: 23}, %{y: 55 }, %{when: “y > 11”} }
how do I create the function with guard ? btw. guard format could be different, say list or something else . whichever is easier ?
How about the case where the function that has to be generated has the form :
def sum({ work = %{x: 23, y: 54 } }) …
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
Can you talk a bit more about your use case?
Elixir macros can generate functions at compile time from data but this is a bit of an odd way to go about it. If you’re trying to do it at run time I think you really just need to treat it as a data transformation instead of as meta-programming.
mraptor
I’m trying to make sort of Production system and want header-function-matching to do most of the work for me, where the rules are passed/created from tuples.
Btw .. prod system is a list of IF-THEN rules and perfectly match “def fun(IF), do: THEN pattern”
kip
Here’s a simple example using your data that might get you started:
In IEx:
mraptor
Why this does not work, but the one you gave work.
** (ArgumentError) cannot invoke def/2 outside module
(elixir) lib/kernel.ex:5122: Kernel.assert_module_scope/3
(elixir) lib/kernel.ex:3893: Kernel.define/4
(elixir) expanding macro: Kernel.def/2
iex:24: (file)
(prod_sys) expanding macro: ProdSys.rule/1
iex:24: (file)
OvermindDL1
What error message do you get and what is the full example code to test with?
mraptor
here is simpler one :
mraptor
Here is another example :
OvermindDL1
That tells you exactly the issue, you are calling
rule/1, which is a macro that returns adefAST, and you cannot calldefat that location, you can only call it from inside a module.mraptor
So how can I solve it… i.e. be able to create functions on demand !?
OvermindDL1
Exactly what the error says, you have to call your
rulemacro from inside adefmodulebody.