lecture 05

This commit is contained in:
SowinskiBraeden committed 2026-10-14 16:26:51 -07:00
1 parent cda6101a3d
commit 6c54e7a49b
7 files changed
+175

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
# see abstract syntax tree (ast)
quote do: 1 + 2
# {:+, [context: Elixir, imports: [{1, Kernel}, {2, Kernel}]], [1, 2]}
#
# +
# / \
# 1 2
#
alias String, as: S
# {:__aliases__, [alias: String], [:S]}
### Abstract literal
quote do: 1 # -> 1
quote do: "hello" # -> "hello"
quote do: [1, 2, 3] # -> [1, 2, 3] # a list of ast literals is an ast literal
quote do: {1, 2} # -> {1, 2} # doubles are ast literals but not triples
### Macro - something that takes an AST and returns an AST
x = 2
quote do: x # -> {:x, [], Elixir} # doesnt evaluate it, just ast of expression
quote do: unquote(x) # -> 2