Showing Posts 21 to 30

OvermindDL1

OvermindDL1

Oooo, I did not know it had this inconsistency… I may need to start adding an ending optional ignored argument to all my multi-line (mostly macro) functions so I can keep , at the end. :slight_smile:

The language has a ton of ‘surprising’ cases like this already, this would actually remove one of the surprises if trailing commas were allowed inside parenthesis. :wink:

nathanl

nathanl

This is exactly why we can’t have trailing commas. You are doing a function call without parenthesis so with trailing commas it’s ambiguous what the last argument is.

I hadn’t considered that.

However, it seems that the root cause of the ambiguity is that parentheses are optional. There’s nothing ambiguous about this, is there?

# syntax error
ArgsDemo.normal_args(
  10,
  "blue",
)

If there’s a closing parenthesis, couldn’t the parser notice that and ignore the trailing comma?

We should also strive to reduce the amount of ambiguity in the language

I totally agree. Making parentheses required for function calls would remove the ambiguity, at some (arguable) aesthetic cost.

OvermindDL1

OvermindDL1

Indeed, I’d have the parser only accept trailing commas if it is inside parenthesis, otherwise it’d be disallowed.

nathanl

nathanl

Indeed, I’d have the parser only accept trailing commas if it is inside parenthesis, otherwise it’d be disallowed.

Yes - or inside [].

ericmj

ericmj

Elixir Core Team

Yes, that’s what we do inside brackets. But we don’t want to add it for function calls because, like I said earlier, we can’t support it for parenthesis-less functions and we feel it would be inconsistent and confusing to only support it for some function calls.

That would be a breaking change and would not possible until Elixir 2.0.

mgwidmann

mgwidmann

I’m not sure this topic is worth discussing any longer. I think everyone feels like the loss of the trailing comma is worth losing over losing optional parenthesis. I remember the backlash when elixir started warning about omitting parenthesis when piping and I’m fairly positive thats not something the community would be willing to trade.

wmnnd

wmnnd

I wonder why you would want trailing commas in function calls.

Functions in Elixir and Erlang are defined by their name and arity. A trailing comma in a function call seems to introduce unnecessary ambiguity when it comes to the arity of the called function.

Does foo(bar,) refer to foo/1 or foo/2 with the second parameter accidentally omitted?

OvermindDL1

OvermindDL1

Multi-line, especially useful for macro’s:

someMacro(
  ModuleName,
  a_very_long_argument_maybe_some_AST_for_the_macro,
  or_maybe - a_set_of + math_that / needs_to * be_performed,
  a: 1, # Or keyword list for those that like to use them without `[]`
  b: 2,
  c: 3,
)

Convoluted example, but it gets the point across. Plus it unifies the trailing comma syntax with [] and {} and %{} too, thus making things more consistent. :slight_smile:

I’d never recommend a trailing comma in a single-liner, not in any of those.

wmnnd

wmnnd

But in this example, you’re still using the trailing comma for a keyword list and not for function parameters.

OvermindDL1

OvermindDL1

Each of those lines were intended to be exampled stand-alone. ^.^

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews