I’m trying not to be picky, but I just bumped into another case where macros
leak out to the user level.
I wanted to pass a function into a structure definition, so I wrote
defmodule Earmark.Context.Options do
defstruct do_smartypants: &(&1) # default is a noop
end
and I got
** (CompileError) lib/earmark/context.ex: invalid quoted expression: #Function<0.54589463 in file:lib/earmark/context.ex>
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
This happens, as you probably know, because the fields are evaluated at compilation time and the function wont survive after compilation. If we instead evaluated the fields at a later point we would not be able to implement struct deriving. Because to implement a protocol for a struct all fields have to be known.
It is not clear to me what the issue here. Is it that you are not allowed to put functions as default values or that the error message is bad?
Are things too familiar? Are we in the "uncanny valley", where the small imperfections are magnified?
Compare the Palm Pilot and the Apple Newton. The Newton claimed that its handwriting recognition was good enough to just use. It was 99% accurate, but the last 1% drove everyone nuts. The Palm Pilot on the other hand introduced Graffiti, a special way of writing each character. With Graffiti, accuracy was impeccable. By requiring a small change in behavior from its users (learn Graffiti) the Palm Pilot was able to deliver a superior experience.
I wonder if Elixir is having the same problems here. It feels like we can use Elixir just like we might with Ruby or Python. That 1% of functionality that is unintuitive is painful.
Is there something we can require of users that will help? Rather than try to get Elixir to match naive user expectations, is there a way that we can manage those expectations? For example, rather than hide macros, can we make them more obvious and a first class part of the user experience of using Elixir? (Yes, they are first class I. The language, but they are sort of swept under the rug in the overall initial experience)
--
--
This happens, as you probably know, because the fields are evaluated at compilation time and the function wont survive after compilation. If we instead evaluated the fields at a later point we would not be able to implement struct deriving. Because to implement a protocol for a struct all fields have to be known.
We need to evaluate everything immediately to get the fields, otherwise defstruct Module.func()
wouldnt work.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.