with {output, 0} <- System.cmd("git", ["reset"]) do
#do something
end
but elixir gives me an error:
the function “cmd” cannot handle clauses with the → operator because it is not a macro. Please make sure you are invoking the proper name and that it is a macro
The error you pasted seems more related to improper use of cmd inside a -> clause (not <-) in pattern matching than to the with. Maybe you have an else clause using System.cmd on the wrong side?
Expanding on what I posted before, most likely this is a problem with parentheses and/or precedence. The example you posted works fine, but if you misplace parentheses, making Elixir believe that the do ... else ... end belongs to the System.cmd rather than to the with clause you get that error:
# WRONG, this causes the error you see
with {output, 0} <- (System.cmd("echo", ["hi"]) do
else
_ -> nil
end)
# ** (CompileError) iex:7: the function "cmd" cannot handle clauses with the -> operator because it is not a macro. Please make sure you are invoking the proper name and that it is a # macro
# (stdlib) lists.erl:1354: :lists.mapfoldl/3
Only for if and when (I think; haven’t checked for case and cond). Their first argument has to be on the same line (or you put \ after the keyword and put the first argument on the next line).
EDIT: As was said, this indeed applies to all function calls without parentheses.
This is true for any function call without parenthesis. The first argument and the comma (or equivalent keywords) have to be on the same line as the function name.