rvirding

rvirding

Creator of Erlang

How can I get Elixir to help me with generating match specifications from funs. There is an Erlang function :ets.fun2ms/1 which can do this. Sort of anyway, in that the Erlang compiler actually tranforms this to the match specification at compile time. Can I tell the Elixir compiler to do this tranformation?

There are no problems in using match specifications explicitly in Elixr of course as they are just data structures, it doing the transformation I am after.

Showing Posts 1 to 5

hauleth

hauleth

There is no way to have ets:fun2ms/1 in Elixir, as Elixir disallows parse transforms. However you can use macros to achieve the same thing.

kokolegorille

kokolegorille

There is this old post…

Maybe this package can help?

patrickdm

patrickdm

There is also @ityonemo’s

https://github.com/E-xyza/match_spec

:ets matchspec helper library for elixir. Exposes the fun2ms/1 macro which transforms elixir-style function code into ets matchspecs.

iex> require MatchSpec
iex> MatchSpec.fun2ms(fn {key, value} when key === :foo -> value end)
[{{:"$1", :"$2"}, [{:"=:=", :"$1", {:const, :foo}}], [:"$2"]}]

fun2ms and ms2fun for elixir! Advent of code day 22 (remastered)

rvirding

rvirding OP

Creator of Erlang

Thanks for the suggestions. Why does the Elixir compiler disallow parse transforms?

The problm is I have another issue than just doing it from Elixir :smiley: and that is I want to do it from LFE (Lisp Flavoured Erlang) as well. And there I have records which Elixir doesn’t, and these 2 packages, don’t really support. The LFE compiler makes full use of the Erlang compiler so it just translates all record operations into the record expressions in the Erlang AST.

I am also looking at doing it in a nice way using the modules in Erlang but without parse transforms, which will be the last option.

hauleth

hauleth

Here is discussion

https://github.com/elixir-lang/elixir/issues/5762

Writing such macro also shouldn’t be really hard there, so it can go that route.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
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
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
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
velrest
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
samoloth
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
FlyingNoodle
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
nseaSeb
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

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews