Home > Blockchain >  Why is there a keywork sync - no star
Why is there a keywork sync - no star

Time:02-18

In generator’s, we have async:

  • async to get an Future
  • async* to get a stream

And sync:

  • sync* to get an Iterable.

But what about sync no start* found in keywords:

Is async just a "fictional keyword"?

CodePudding user response:

The list of "keywords" that you link to is a list of identifiers (or would-be identifiers) that have special meaning anywhere in the Dart syntax.

Some of them are "reserved words", and can never be used as an identifier.

Some are "built-in identifiers" which can be used as identifiers in most, but not all, places (e.g., cannot be the name of a type).

Some are "contextual keywords" which only means something in a very specific place, where they are clearly distinguishable from a name. Those can be used as identifiers anywhere an identifier can be used - the special places where they mean something else are precisely ones where an identifier cannot be used.

A few are reserved words only in some contexts. Because history!

The identifier sync is on the list only because it's the identifier part of the contextual modifier sync*. The linked list a list of identifiers, so the sync* combination of identifier and operator cannot occur there.

So, if a word means something somewhere, it's on that list. That's all the list means. You don't need to memorize the list.

You should memorize all reserved words. Those can never be used as the name of a variable.

You might learn some of the built-in identifiers eventually, because you try to, say, use them as an import prefix (they're lower case, so you likely won't try to use them as a type name). Rarely an issue in practice.

And you're likely to completely forget that contextual keywords exist, because it's easy to think of their use in grammar as completely different from their use as variable names. If anything, primitive syntax highlighters might remind you that there is something special about that word that makes it purple when the variable next to it is orange.

CodePudding user response:

Apart from the obvious, I like to ask questions, and it does indeed look like it is a fictional keyword. If you have a look in the analysis_server.

Occam’s razor don't always apply in programming, but in this case - it will work, even you don't care ;-)

CodePudding user response:

The list of "keywords" that you link to is a list of identifiers (or would-be identifiers) that have special meaning anywhere in the Dart syntax.

Some of them are "reserved words", and can never be used as an identifier.

Some are "built-in identifiers" which can be used as identifiers in most, but not all, places (e.g., cannot be the name of a type).

Some are "contextual keywords" which only means something in a very specific place, where they are clearly distinguishable from a name. Those can be used as identifiers anywhere an identifier can be used - the special places where they mean something else are precisely ones where an identifier cannot be used.

A few are reserved words only in some contexts. Because history!

The identifier sync is on the list only because it's the identifier part of the contextual modifier sync*. The linked list a list of identifiers, so the sync* combination of identifier and operator cannot occur there. It's not fictional, just very contextual. It means something, somewhere.

If a word means something somewhere, it's on that list. That's all the list means. You don't need to memorize the list.

You should memorize all reserved words. Those can never be used as the name of a variable.

You might learn some of the built-in identifiers eventually, because you try to, say, use them as an import prefix (they're lower case, so you likely won't try to use them as a type name). Rarely an issue in practice.

And you're likely to completely forget that contextual keywords exist, because it's easy to think of their use in grammar as completely different from their use as variable names. If anything, primitive syntax highlighters might remind you that there is something special about that word that makes it purple when the variable next to it is orange.

  •  Tags:  
  • dart
  • Related