tim2CF
Hi again, I have question related to previous. To find answer I probably have to read compiler source code, but maybe you know answer already. I want some utility function which will do validation of ast, something like:
valid_guard?(ast) :: boolean
which I want to reuse to assume that given expression is pure. This function, or similar equivalent should exist in Erlang/Elixir compiler for sure, because it’s doing this purity validation well.
Writing own custom equivalent is not the best option, because you have to deal with possible things like
import Kernel, except: [{:'-', 1}]
import UnpureOverride, only: [{:'-', 1}]
But compiler is already doing all this smart stuff and can recognise this impurity
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
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
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
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
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
I’ve followed the Phoenix LiveView file upload code here Uploads — Phoenix LiveView v1.0.0-rc.7 and so far everything works just fine wit...
New
Other Trending Topics
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
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
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #ai
- #iex
- #graphql
- #elixirconf-us
- #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)
lpil
If you want to know if a macro is a valid guard you can use Macro — Elixir v1.20.2 and then traverse the AST, checking if all the calls in that AST are guards themselves.
If you wish to know whether a function it pure it is a much more difficult task, one not possible with the Elixir compiler today.
What do you mean by this? The Elixir compiler does not know whether functions are pure or not.
tim2CF
I mean that both Erlang and Elixir compilers don’t allow application of impure functions in guard expressions. And I just want to reuse this utility. Check that given AST is pure for sure, either that it might be impure.
lpil
They don’t track if functions are pure, instead they have a small list of permitted functions and operators, and if any other functions are used then the code is rejected by the compiler. In Elixir it is the same process I outlined above with macro expansion.
Purity inference isn’t need as being pure isn’t enough for a function to be valid in a guard.
tim2CF
Thanks, I understand, that’s completely fine for my proposes. I maintain this library
And atm it don’t allow any function application. But I want to allow application of functions which are pure for sure. It can be small subset of pure functions, that’s fine. Because atm expressions like
foo: -42are rejected by library because there is&Kernel.-/1function application there.tim2CF
I just don’t want to re-invent the wheel, and deal with tricky possibilities like
Erlang/Elixir compiler already have utility to deal with this kind of stuff and reject it in guards because of possible impurity
hauleth
No, not really. Erlang/Elixir just have defined set of “guard safe” functions which are allowed. There is much broader set of pure functions that will not be allowed in guards.
lpil
They do not have this functionality I’m afraid.
You’re effectively wanting to write a kind of static type system for Erlang- it would be a large piece of work.
tim2CF
I think it will be quite enough for purposes of my library. Do you know name of utility function which checks that given AST is valid guard? Or maybe some guesses where to search it?
lpil
I suspect it will not be, you will be limited to just these functions:
There’s no way to iterate or recurse, and there is no flow control.
hauleth
erl_internal:guard_bif/2orerl_lint:is_guard_test/1