mudasobwa
Creator of Cure
The post covering how to generate nifty types to use in @spec in compile time with macros.
Trending in Guides/Tuts
# ~/src/livebook/.iex.exs
System.cmd("xdg-open", [ LivebookWeb.Endpoint.access_url() ] )
Because Livebook requires a unique passcode on ...
New
You probably already know that <span>{nil}</span> in a HEEX template produces <span> </span> when rendered. I fin...
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
- #ai
- #elixirconf-us
- #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 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
I’ve only skimmed it, but couldn’t find any parameterized type in there, all defined types are of arity 0, have I missed something?
mudasobwa
It does not matter what arity are types, I meant one could parametrize call to
use Scaffoldwith types, not parametrized types themselves.Parameteized types would be handled for granted. I have removed “parametrized” from the tagline to avoid misunderstanding, thanks.
Qqwy
I think the code you are presenting in the post can be simplified greatly.
I believe the following works:
mudasobwa
But this is almost exactly what I present in Working Solution. Yes, I agree, that maybe
unquote_splicing/1migth to some extent look more exquisite, but I explicitly wanted to show a low-level approach, dealing with real AST instead.Also, this approach wouldn’t allow propagated types (
:versionin my example,) becauseversion: atom()outside of the quote would raise.Qqwy
But what about adding them outside of the quote, rather than adding them to the quote you are writing anyway? Or maybe you might write them in their own dedicated quote before the final quoted AST that is returned?
The main reason to use the explicit AST-notation is to pattern-match on it (which you cannot do with quoted fragments because the
.
metafields of{name, meta, arguments}would often not match). In places where you are constructing AST it is virtually always more understandable to work withquote/unquote, in my humble opinionmudasobwa
Eh.
{^name, _, ^arguments} = ast?Anyway, this is the top of the iceberg only, because the approach shown would fail if the arguments are not hardcoded (compile-time literals,) but e. g. passed as a module argument (
use Scaffold, @params.)I have this problem overcome as well, and for it, I was not able to stay high-level not descending to AST, but mentioning this would have made the text too huge. I am planning Part II. Down the rabbit hole, so stay tuned
Qqwy
I meant more like for instance:
Very true
I’m looking forward to it!
mudasobwa
For the sake of consistency I posted it here: Elixir Blog Posts - #627 by benlime