Skip to content

Functions: is ':' a sigil (no spaces after), or operator (spaces allowed) #242

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

Closed
mihnita opened this issue May 11, 2022 · 6 comments
Closed
Labels
blocker Blocks the release syntax Issues related with syntax or ABNF

Comments

@mihnita
Copy link
Collaborator

mihnita commented May 11, 2022

No description provided.

@mihnita mihnita added the syntax Issues related with syntax or ABNF label May 11, 2022
@stasm
Copy link
Collaborator

stasm commented May 12, 2022

@markusicu wrote in #230 (comment):

About the colon as a function prefix -- I am ok with using a colon, but it's a prefix, just like the dollar for variables, so it needs to attach to the function name, and there should be no space allow between the colon and the name. If you don't like the visuals, then pick a different symbol. (Earlier proposals used an @ sign.)

@mihnita
Copy link
Collaborator Author

mihnita commented May 12, 2022

Comments migrated from the slides


Slides comment, Mihai Nita (@mihnita), 11:56 AM Apr 21

Space between : and the function name seems arbitrary and inconsistent.

Why $foo (no spaces), but : number (with spaces)


Slides comment, Eemeli Aro (@eemeli), 12:35 PM Apr 21

Because in practically all prior art, $ is used attached to the next token, whereas : is expected to tolerate whitespace around it.


Slides comment, Mihai Nita (@mihnita), 11:10 AM Apr 23

I don't know what prior art you have in mind. Maybe css?
But I suspect what you have in mind uses : as separator, not "indicator of type".
We should not imitate the look of things without understanding why they do what they do.

If : is a separator, not a "badge" for function names, then {:foo} is not a function without parameters, it is a function with a null parameter.

Which has other implications.

Might seem minor. But null handling is often called "The Billion Dollar Mistake" for a reason. And a big debate in many languages & libraries.


Slides comment, Mihai Nita (@mihnita), 1:34 PM Apr 23

Here is prior art where the space (or lack of space) does matter:

https://www.w3schools.com/python/trypython.asp?filename=demo_ref_string_format

Try

txt = "For only {price:.2f} dollars!"
=> For only 49.00 dollars!

txt = "For only {price: .2f} dollars!"
=> For only  49.00 dollars!
// two spaces before 49

txt = "For only {price :.2f} dollars!"
=> KeyError: 'price '

txt = "For only {price : .2f} dollars!"
=> KeyError: 'price '

Slides comment, Markus Scherer (@markusicu), 9:05 AM Apr 25

Be mostly strict about WS -- mostly forbidden or required, not optional.
If something is a prefix, then forbid WS between it and its name. If that means that : is not good for a function, then pick a different prefix character.

@mihnita
Copy link
Collaborator Author

mihnita commented May 12, 2022

Comments migrated from the slides

$foo: number minFractionDigits=2
A function call with no argument :platform


Slides comment, Elango Cheran (@echeran), 11:30 AM Apr 21

The syntax here feels confusingly inconsistent. $foo is a bare value, but put a colon suffix it if there is a function (and function goes in 2nd position), but a function with no args goes in first position with a colon prefix.

At the least, make the function invocations consistent. If you want colons for that, or @ sign, or whatever, choose whether to prefix or suffix the function name with that character consistently.


Slides comment, Stanisław Małolepszy (@stasm), 10:50 PM Apr 21

The intent was to make the colon an operator rather than a sigil; in the examples it means "call this function". I suggested attaching it to $foo because it made it look like a typing annotation, which I think is a nice way to think about formatting functions. But it sounds like it created some confusion. Do you think it would be clearer if the coding style was $foo:number, without any whitespace?


Slides comment, Elango Cheran (@echeran), 8:30 AM Apr 22

The colon is overloaded for 2 distinct purposes, but also in visually similar locations. I think removing whitespace in one case would only address the visual similarity, at the cost of reducing the visual consistency / readability of function invocations.

One option that I was suggesting above to keep it simpler and more consistent by just using the colon (or @ or whatever char) for the function invocations, and keep the whitespacing as is.

I'm not particular about colon or @ or other character, but I think here more consistency / simplicity lends itself to readability, and vice versa about the inconsistency.

@romulocintra romulocintra added the blocker Blocks the release label May 16, 2022
@romulocintra romulocintra added this to the Technical Preview milestone May 16, 2022
@stasm
Copy link
Collaborator

stasm commented May 16, 2022

The majority of the feedback on #230 was that the idea of the : call-operator was confusing. There seems to be a consensus about making it a sigil instead.

@stasm
Copy link
Collaborator

stasm commented May 16, 2022

Another question is whether the colon (:) is the right choice for the sigil. We chose it for its visual "lightness" compared to the at sign, which was the other alternative we considered. Compare the following two placeholders:

{$foo :func opt=val}
{$foo @func opt=val}

A reason against using the colon might come from #238. One of the potential solutions could be to introduce a namespacing mechanism for UI/markup elements. It would be nice to be able to follow XML's convention of reserving names with colons for that purpose.

stasm added a commit to stasm/message-format-wg that referenced this issue May 25, 2022
Change the colon from being an operator which calls functions to a sigil that prefixes function names.

Closes unicode-org#242.
@markusicu
Copy link
Member

I don't feel strongly about : vs. @.

I do feel strongly that there should be no space between this prefix and the function name. Don't freely allow spaces everywhere. Make the function and its prefix look like a unit. (Looks like @stasm's commit did that.)

Also: https://en.wikipedia.org/wiki/Sigil --> I suggest using the term "prefix" instead :-)

stasm added a commit to stasm/message-format-wg that referenced this issue Jun 6, 2022
Change the colon from being an operator which calls functions to a sigil that prefixes function names.

Closes unicode-org#242.
stasm added a commit that referenced this issue Jun 6, 2022
Prefix function names with the colon.

Change the colon from being an operator which calls functions to a sigil that prefixes function names.

Closes #242.
@stasm stasm closed this as completed Jun 6, 2022
echeran pushed a commit that referenced this issue Sep 20, 2022
Prefix function names with the colon.

Change the colon from being an operator which calls functions to a sigil that prefixes function names.

Closes #242.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker Blocks the release syntax Issues related with syntax or ABNF
Projects
None yet
Development

No branches or pull requests

4 participants