Hello there,
On 07.10.21 00:00, Zesstra wrote:
> One Idea, although not terribly "pleasing":
> (@"/lwo/foo"@ "Hello", 42, "@WER says: ")
no, please, no :-o
> Gnomi does not like this one inspired by objective-c, but maybe it
> inspires someone:
> [["/lwo/foo"] "Hello", 42, "@WER says: "]
>
> Zesstra@MG
[["/lwo/foo"] param] doesn't look too bad. The leading [ suggests that
this is different from a simple data structure like ({, ([, and (<.
But: The use of quotes - while somewhat logical - seems inconsistent
with the struct variant (where no quotes are used). Hence I'd prefer
[[/lwo/foo] param] without the quotes.
That said: I wouldn't worry too much about it. After all, there also is
no literal for creating clones either, and nobody seems to really miss
it. But then again: there could also be a similar syntax for cloning,
e.g. [{/program/file} args] (with the args being passed on to the create
hook, just like - I guess - it will be done for lwobjects).
But those quotes lead me onto a tangent:
Was there ever a plan to allow for dynamically instantiating structs
with the name coming from a string variable? Since structs may inherit
other structs this could be a very useful feature to instantiate
sub-classes of structs as required.
If so, the question would be if that should be allowed at all in the
literal notation of struct and lwobject creation (and thence how to make
it consistent between the two). One way to solve it while staying
consistent with the existing (<StructName>) notation would be borrowing
the struct lookup syntax's () for getting the name from a variable, e.g.:
lwobject ob = [[/a/file/name] foo, bar];
struct st = (<StructName> bla, blub);
vs.
lwobject ob = [[(a_string_variable)] foo, bar];
struct st = (<(a_string_variable)> bla, blub);
The alternative would be to allow quotes if the string is to be
interpreted literally, and otherwise check if the provided name matches
the name of an existing variable. But this of course could break
existing code (so this would have to be an optional feature) and is
presumably harder to implement.
But that said: I would be perfectly happy, if dynamic allocation were
only possible when using new_lwobject() - and in the future maybe a
new_struct() or a variant of to_struct() -, and the literal notation
would only allow for actual string literals. In that case omitting the
quotes to keep it consistent with the existing notation would make more
sense.
cya
Invis