Skip to content

Synatctic feature requests. #1066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ghost opened this issue Jul 5, 2020 · 2 comments
Open

Synatctic feature requests. #1066

ghost opened this issue Jul 5, 2020 · 2 comments
Labels
feature Proposed language feature that solves one or more problems

Comments

@ghost
Copy link

ghost commented Jul 5, 2020

Dart is pretty simple, but there are a few additions that ould be nade to dart core.

  • exponent syntax as its easier to use.
var a=2, b=5;
var c = a**b; //c=32
  • slice syntax for strings and lists.
var a =[1,2,3,4,5];
var c = a[1:3]; //c = [2,3,4]
  • a straight forwards console input (super useful while learning dart initially)
var a = input('your name: ')
//prints 'your name: ' to console and takes what ever the user types after 
//and stores it in a.
@lrhn
Copy link
Member

lrhn commented Jul 5, 2020

The exponentiation operator, **, would be an infix, right-associative operator (operator **(arg)) with a precedence just stronger than the multiplicative operators. It would be user-implementable, and implemented by num.
It would be hard to type in a useful way, because unlike other arithmetic operators, we can't special case int ** int to have static type int. That's only true if the exponent is non-negative.

The slice operator would be a new ternary suffix operator, operator [:]([arg1, arg2). It would probably also have a slice-set operator operator [:]=(arg1, arg2, value). The calling convention would be that arg1 and arg2 must be nullable, because they can be omitted, or only make them omitable if they are nullable. (Making them optional works badly, unless we make the named, and that's very different than other operators).
Then x[:] would pass null for both parameters, x[1:] would pass null for the second parameter and x[:4] would pass null for the first parameter.

The input function is fairly simple:

import "dart;io";
String input([String query]) {
  if (query != null) stdout.write(query);
  return stdin.readLineSync();
}

I'm not sure that function belongs in the platform libraries. Console input is not something that you will use in any real program (it's a really horrible UI), so it'd just be there for people learning Dart. I'd probably prefer to make dartpad.dev easier to use instead.

@lrhn lrhn transferred this issue from dart-lang/sdk Jul 5, 2020
@lrhn lrhn added the feature Proposed language feature that solves one or more problems label Jul 5, 2020
@ghost
Copy link
Author

ghost commented Jul 5, 2020

Well thanks for taking the time to reply but I didn't get the part about the slice operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

1 participant