Page 1 of 1
[Vetoed]Object Constructors {} key with quote/mix array&key
Posted: 27 Aug 2014, 06:07
by RobertL
Code: Select all
d="d"
o:={a:1,"b":2,("c"):3,(d):4}
Get a-1, b-2, c-3, "d"-4.
Can Initialize key-value which key contains quotation marks (like "d") directly in Object Constructors {}
In V2, can use t:={'"a"':1}.
- Can support mix Object Constructors with Simple Arrays, Associative Arrays?
Like static o:={0:"a","b","c",4:"e","f",m:n}, so the b/c's index is 1/2, and e's index is 4, f's is 3(more flexible!) or 5?
The purpose is here at 3#.
Re: Object Constructors {} key with quotation/mix array & ke
Posted: 27 Aug 2014, 07:06
by Coco
You can if you override the built-in function Object(), although there's no way of detecting on how the keys-values were passed(where the mix starts/end, etc.) as the function will receive them as parameters.
But why do this?
Re: Object Constructors {} key with quotation/mix array & ke
Posted: 27 Aug 2014, 08:10
by RobertL
@Coco
It's just convention. Using one object constructor to initialize a mix object with index-key and noraml-key.
Also, can change the index base from 1 to 0 (see a), or change it in the middle effect the auto index-key behind (see f).
Like in static/constant object variable, so don't need any extra initialize code.
Otherwise, we should use object() or {}, and specify every key, like {0:a,1:b,2:c,3:d,m:n}.
Re: Object Constructors {} key with quotation/mix array & ke
Posted: 27 Aug 2014, 08:23
by Coco
Well, you can override
object() to implement your custom constructor behavior:
Code: Select all
object(args*) {
return new RobertL_CustomObject(args*)
}
class RobertL_CustomObject
{
__New(args*) {
;// put your code here
}
}
The downside, you would need to re-implement the other built-in object functions when called using [/c].Syntax()
, plus this functionality as well addr := &obj, obj := Object(addr)
Re: Object Constructors {} key with quotation/mix array & ke
Posted: 27 Aug 2014, 08:34
by RobertL
@Coco
It's hard to determine the key is an index or normal-key from which orginal determined by : now from , as param*.
You mean pares string '0:"a","b","c",4:"e","f",m:n' to object with a function (don't need to override anything). Oh, also difficult to handle expression (variable).
I think it would be a big convention to expand the object constructor.
Re: Object Constructors {} key with quotation/mix array & ke
Posted: 27 Aug 2014, 19:12
by lexikos
1. As you've shown, the key can be a quoted literal string. So ask yourself, how do you include quote marks in a quoted literal string?
2. No.
Re: Object Constructors {} key with quotation/mix array & ke
Posted: 27 Aug 2014, 19:34
by RobertL
@lexikos
1. I found
t:={'"a"':1} correct in V2.
2. The purpose is
here at 3#. I think it's a big
conventionconvenience
(although just for convention).
Re: Object Constructors {} key with quotation/mix array & ke
Posted: 27 Aug 2014, 20:24
by lexikos
2. And? The answer is still No.
I think you mean "convenience", not "convention".
Re: Object Constructors {} key with quotation/mix array & ke
Posted: 27 Aug 2014, 20:54
by RobertL
Eh..All right
Amend done.
Re: [Vetoed]Object Constructors {} key with quota/mix array&
Posted: 28 Aug 2014, 00:05
by lexikos
Sorry, I overlooked the fact that this is in the Wish List forum. If the question was can it be done in the current version, the answer is as I said: No. It could be done in a future version, but I don't intend to do it. It generally wouldn't be very useful, since scripts tend not to mix the two, especially in object literals.
Re: [Vetoed]Object Constructors {} key with quota/mix array&
Posted: 28 Aug 2014, 00:22
by RobertL
@lexikos
OK. I see, no problem.
I will use a function (Add an auto-count index/key) to do this, may be used in some occasional case.