dmarcoux

dmarcoux

Hey,

I understand that ? returns a character’s codepoint, but I would like to know how ? is defined and reads its documentation. I looked in vain at a few modules in IEx and also tried h ?, but it’s not working. Where is it hiding itself?

Showing Posts 1 to 6

LostKobrakai

LostKobrakai

There is not really an implementation. This is a pure syntax feature of elixir.

al2o3cr

al2o3cr

The ?x syntax is handled by the tokenizer:

https://github.com/elixir-lang/elixir/blob/main/lib/elixir/src/elixir_tokenizer.erl#L233-L274

This code is also what produces the messages you get when using ? with improperly-escaped characters:

iex(1)> ? 
warning: found ? followed by code point 0x20 (space), please use ?\s instead
  iex:1:1

32

iex(2)> ?\x
warning: unknown escape sequence ?\x, use ?x instead
  iex:2:1

120
adamu

adamu

It is strange that it’s not possible to search for this as an operator. It almost feels like there should be an honorary mention in Kernel.SpecialForms (“the basic building blocks of Elixir”) that at least explains what’s going on.

LostKobrakai

LostKobrakai

There’s a bunch of syntax to define numbers, which is not documented in Kernel.SpecialForms:

1234 # decimal base (the default)
0b1010101 # binary base
0o707070 # octal base
0xF0F0F0 # hexadecimal base
?e # unicode code point

None of them have AST representations. They’re turned into their respective integers before turned into AST and are therefore part of the syntax of elixir.

quote do: 0b101010
# 42
quote do: ?e
# 101

This is similar to how [abc: :def] and [{:abc, :def}] are the same in AST (though the sugar’ed form is the default representation):

quote do: [abc: :def]
# [abc: :def]
quote do: [{:abc, :def}]
# [abc: :def]

Kernel.SpecialForms on the other hand are represented in AST, but happen to be implemented directly in the compiler, because there’s no possible macro to transform their AST to some other elixir code doing what they do (or do it efficiently).

quote do: for(i <- 1..10, do: i)
# {:for, [], […]}

I can certainly see that this is confusing though. E.g. tuple and map syntax are special forms, lists are not, as lists stay lists in AST.

dmarcoux

dmarcoux OP

Thank you all for your replies, as always, the Elixir forum delivers. This is really interesting :slight_smile:

dmarcoux

dmarcoux OP

Cool, I’ll put the same link pinned to the latest commit SHA so others can refer to this at a later date if the file changes one day:

https://github.com/elixir-lang/elixir/blob/3b90a793fca04869cf90add0fd7144ece52f9dba/lib/elixir/src/elixir_tokenizer.erl#L233-L274

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
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
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
perzanko
Do we have maintainer of absinthe-graphql/dataloader here? We have a PR that we’d like to merge to the library. Relatively small additive...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
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
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews