rvirding

rvirding

Creator of Erlang

Where can I find a proper Elixir language reference manual? Need it for courses. The web site is very much a tutorial, as are the books.

Showing Posts 56 to 47

OvermindDL1

OvermindDL1

Just an aside, if really should not be a special form or parsed with the syntax or anything of the sort in Elixir, it could easily be just a macro like:

defmacro if(cond_ast, bodies) do
  then_body = bodies[:do]
  else_body = bodies[:else]
  quote do
    cond do
      unquote(cond_ast) -> unquote(then_body)
      true -> unquote(else_body)
    end
  end
end

Or something of that sort. There’s no reason for it to be anything but a macro in Kernel, oh and look it is (although it does some weird stuff like special case the random atom nil and such… *cough* still not a fan of nil being special at all), but yea it is not syntax, nor is def as it is just a macro as well.

The point of this is, since they are macro’s then the user could override them to make them do something else (like how I override def in my defguard library to allow you to define super-guards like is_struct (I still think my style (though complete) of defguard should be built-in to elixir) (I might be in a lisp’y mood…)), but because of that syntax coloring them special may not always make sense, like say in a DSEL.

What I really really hate being special-form’d are things like with and for, both of those could have been done in other more traditionally ‘macro’ ways without the comma-splosion, but since they are special-formed then syntax coloring on them can be specialized…

tmbb

tmbb

Ok, we do agree on this one.

Here I’m not sure we agree. The definition of syntax I use (it’s been a long time since I’ve read a book on the subject) is the same as the one given on Wikipedia (Syntax (programming languages) - Wikipedia):

In computer science, the syntax of a computer language is the set of rules that defines the combinations of symbols that are considered to be a correctly structured document or fragment in that language.

While semantics is (from the same article):

The syntax of a language describes the form of a valid program, but does not provide any information about the meaning of the program or the results of executing that program. The meaning given to a combination of symbols is handled by semantics (either formal or hard-coded in a reference implementation). Not all syntactically correct programs are semantically correct.

From the point of view of the syntax, there is nothing special about if and def. The rules you use to decide whether they are part of a valid program are the same. They are both ordinary identifiers.

I admit my perspective might be too pedantic, strict and theoretical. After all, you’re the one who has implemented (real, used by may people) languages in practice, so I certainly respect your mental models regarding this topic!

But in this case, the difference these definitions draw between Syntax and Semantics is useful to me, while your nebulous notion of “it’s syntax if most programmers agree it is” is to vague for me personally.

rvirding

rvirding OP

Creator of Erlang

Yes, you are misunderstanding my position.

We do agree. I did not say that “it looks like syntax”, what I said was “what a binary looks like” “is very much syntax”. I could flip the order and say syntax is what they look like.

Again I did not say looks like syntax, but what it looks like is syntax. And I see def and if as syntax as they are part of the standard definition of the Elixir language. In the same as data types.

OvermindDL1

OvermindDL1

Mmmmmmmm… ^.^

I mean, uh, cough…

tmbb

tmbb

I wonder if there should be two reference guides: one for Developers who don’t want to write macros and one for Developers who want to write macros, maybe titled something like:

  1. Reference for Developers who don’t like LISP or don’t know what it is, which basically describes elixir like if it were python. After all, it has def, if, with, Enum.reduce_while (basically a python for loop that doesn’t leak outside the scope). defmacro does not exist and the |> operator is a special form that does magic with your functions to put the arguments in the right place. Modules are like classes that have no internal state and can’t be instantiated, unless they inherit (sorry, use! they use!) GenServers and you mess with something arcane like the process registry. Then you get gets and sets and mutable internal object state. Ok, I’ll stop now :smile:

  2. Reference for Developers who think that LISP is the best thing ever and that the characters that compose the program are mere distractions from the holy truth of the AST, which describes elixir as if it were LISP and in which after chapter 2 all programs are written directly by manipulating the AST using functions (do ... end? defmacro? who needs them? We write our AST directly!)

Despite the joking nature of these titles, and the parody-like description, I’m being serious, and I’d totally buy a book like number two if someone were to write it. And if @rvirding’s right, then reference #1 might be useful for many people too.

tmbb

tmbb

I don’t think we agree. You say it looks like it is syntax. I say it is syntax. It’s a sequence of symbols that’s translated into an AST in a very unconventional way compared to the rest of the language (the same goes for maps, tuples, etc).

You’ve written this, which makes me think you think these cases are analogous. My position is that def and if look like syntax (they are turned into an AST node the way any function call is), while <<...>> is syntax (the parser does funny stuff with it to turn it into an AST node).

Or am I misunderstanding your position?

EDIT: The individual expressions separated by commas inside of a <<...>> are certainly not syntax (but they do look like it, enough to fool me before trying quote a binary quote do <<...>> end, like José showed above).

rvirding

rvirding OP

Creator of Erlang

I agree. What a binary looks like is very much syntax, the same as for all the other data types. The syntax describes what things look like. What they are parsed to is basically irrelevant to most users.

I think the important thing is to understand for whom you are writing a syntax description.

tmbb

tmbb

Ok, thanks! I agree with you, then. The types inside the <<>> are certainly not syntax, and they shouldn’t be highlighted any differently in a syntax highlighter.

rvirding

rvirding OP

Creator of Erlang

I would say that that is a language developers way of looking at it. :slight_smile: For most users of Elixir whether parts of the “standard syntax” like def and if are built-in syntax or macros is completely irrelevant. How I write them and how do I use them are the important bits. do ... end vs do: ... is a little more complex but I think you can happily just describe what they look like and how they equate to make most users happy and to get them right.

Again, I think most users, even those who write big complex systems, will not define their own macros even though they will be using lots of things defined by macros. In one way it is similar to the fact that using OTP you can write large extremely concurrent and parallel systems without a spawn, send or receive in sight. You should know that things are being done concurrently but you don’t need to use the explicit concurrency primitives.

josevalim

josevalim

Creator of Elixir

Sigils are very different from containers such as tuples, lists and binaries.

Yes. But the parser does not add meaning to this. You can also write this:

iex(1)> quote do: <<x :: def(foo, do: 1)>>
{:<<>>, [],
 [{:::, [],
   [{:x, [], Elixir},
    {:def, [context: Elixir, import: Kernel],
     [{:foo, [context: Elixir], Elixir}, [do: 1]]}]}]}

Therefore, syntax wise, <<>> can mean anything. That’s why I said you won’t find the documentation for what <<1::byte>> means in the syntax reference. The syntax allows you to put whatever you want on the right side of ::, the meaning comes from elsewhere.

This is a big contrast to other languages, such as Erlang, where what is allowed inside <<>> is a directly known by the parser.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews