-
Notifications
You must be signed in to change notification settings - Fork 9
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
enhancement to dynamic object #474
Comments
Thoughts, @chochos? |
It's true, those are valid keys in js. But they're only accessible with k[v] syntax. We'd need syntax not only to create objects with those keys, but also to read and assign them (can't remember right now what we do with k[v] when k is native, but that's easu; the problem is there's no o[k]=v syntax in ceylon) |
Hrm. Tricky one. |
@chochos So I think the simplest solution would be to just add dynamic header = dynamic [ date = 123; ];
header.putAttribute("Content-Type", "text/plain"); We could even support the following, in addition to dynamic header = dynamic [ date = 123; attributes = { "Content-Type"->"text/plain" }; ]; |
Or instead of dynamic header = dynamic [ date = 123; ];
header.attributeMap.put("Content-Type", "text/plain"); |
Of course, I guess the natural syntax for this would be: dynamic header = dynamic { date = 123; "Content-Type" -> "text/plain", "Content-Length" -> 348 ];
String contentType = header["Content-Type"]; That would require a language change, but it's doable. We would have |
The I don't see why we need to add a different syntax with entries to the |
Grumble. because it looks like you're assigning to a string. |
well, you are assigning to a string, in a way; keys in JS objects are strings... |
This actually begs for a question if we need syntax in Ceylon for addressing weird identifiers. Some languages (Groovy for example), allow defining your method names in double quotes, allowing all kinds of weird and groovy names that can contain whitespace, special characters and unicode symbols not otherwise allowed for identifiers. This is sometimes quite neat; for example when writing test cases, you can write very descriptive method names, that read well later in the test reports... In any case, this issue is just one of these cases that shows how we need this for interop with other languages that are more liberal with identifier names than Java or Ceylon. So I have two potential ideas of how this would work:
dynamic header = dynamic [date = 123, \i'Content-Type' = "text/plain"; ];
dynamic header = dynamic [date = 123, \iContent\-Type = "text/plain"; ]; |
@luolong This is a good point. The issue is, as always, whether we can think of any non-disgusting syntax for this, now that we've already used all the reasonable quote characters for other things. |
What do you think of the proposals in my previous post? |
I'm not sure I do think anything yet. I guess the second one might be on the right track. What would be wrong with simply |
I don't see anything wrong with |
Wellyeah, I suppose, is there some reason why it wouldn't work? |
Another option that might work could be to deprecate
or
or even
Though we already use backticks for too many things. |
I think it would be better to use \ as a general escape char. these |
Nothing, except that if I actually quite like the backslash escape syntax. shared object windowsFolders {
shared String \iProgram\ Files = "Program Files";
} And it would actually look rather clean... Another question is -- what it would be escaping? Same rules as within |
I personally think we should deprecate |
in javascript there are two ways to define property names in object literals one is using with quotes and other is without like this
in ceylon i can't create this object because of this second property.There is heavy usage of this type of property in nodejs app since most of http header names have "-" in between them like "content-length"
i tried this but not working
dynamic header = dynamic [date = 123, "Content-Type" = "text/plain"; ];
is there any way??
The text was updated successfully, but these errors were encountered: