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
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
Failing to Introduce Elixir - John Darrington
https://www.youtube.com/watch?v=KjAH68yVnh8
Comments welcome! View the <span class="hasht...
New
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
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 11 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
tim2CF
@lpil and @hauleth
Thanks, I know how to do it now!
hauleth
erl_internal:guard_bif/2orerl_lint:is_guard_test/1lpil
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.
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
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.
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.
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
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.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
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.