Ah, that explains everything! Thank you :) On Thursday, March 9, 2017 at 6:50:45 AM UTC-5, Michał Muskała wrote: > > when is an operator - it behaves very similar to operators like == or in. > > iex(1)> quote(do: 1 when 2) > {:when, [], [1, 2]} > iex(2)> quote(do: 1 == 2) > {:==, [context: Elixir, import: Kernel], [1, 2]} > > In case of def, the left side (of the operator) is the call and right the > guards. > > Michał. > > On 9 Mar 2017, 12:42 +0100, Brian Cardarella <br...@dockyard.com > <javascript:>>, wrote: > > If I quote the following: > > > Code.string_to_quoted """ > if foo do > "true" > else > "false" > end > """ > > I get the following AST: > > {:if, [line: 1], [{:foo, [line: 1], nil}, [do: "true", else: "false"]]} > > Which makes sense to me as the last node is a list. However, `when` seems > to follow different rules and I'm not following exactly how Elixir parses > it from the AST: > > Code.strig_to_quoted """ > def foo(bar) when bar == 1 do > "baz" > end > """ > > {:def, [line: 1], > [{:when, [line: 1], > [{:foo, [line: 1], [{:bar, [line: 1], nil}]}, > {:==, [line: 1], [{:bar, [line: 1], nil}, 1]}]}, [do: "baz"]]} > > `when` is not in that last list, but is now the first element in the > values for `:def` > > Can someone point me to examples of how Elixir is parsing `when` within > the source? I dug around in Kernel which brought me to elixir_def but got > stuck there. > > Use case: I am experimenting with writing some macro functions that could > take guard clauses. > >
-- 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-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/4ba975e3-7dc7-4ea3-b799-5ffcf8c277bb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.