[Vetoed]Object Constructors {} key with quote/mix array&key

Propose new features and changes
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

[Vetoed]Object Constructors {} key with quote/mix array&key

27 Aug 2014, 06:07

  1. 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}.
  2. 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#.
Last edited by RobertL on 28 Aug 2014, 00:30, edited 4 times in total.
我为人人,人人为己?
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: Object Constructors {} key with quotation/mix array & ke

27 Aug 2014, 07:06

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?
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

Re: Object Constructors {} key with quotation/mix array & ke

27 Aug 2014, 08:10

@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}.
我为人人,人人为己?
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: Object Constructors {} key with quotation/mix array & ke

27 Aug 2014, 08:23

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)
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

Re: Object Constructors {} key with quotation/mix array & ke

27 Aug 2014, 08:34

@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.
我为人人,人人为己?
lexikos
Posts: 9559
Joined: 30 Sep 2013, 04:07
Contact:

Re: Object Constructors {} key with quotation/mix array & ke

27 Aug 2014, 19:12

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.
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

Re: Object Constructors {} key with quotation/mix array & ke

27 Aug 2014, 19:34

@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).
Last edited by RobertL on 27 Aug 2014, 20:52, edited 3 times in total.
我为人人,人人为己?
lexikos
Posts: 9559
Joined: 30 Sep 2013, 04:07
Contact:

Re: Object Constructors {} key with quotation/mix array & ke

27 Aug 2014, 20:24

2. And? The answer is still No.

I think you mean "convenience", not "convention".
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

Re: Object Constructors {} key with quotation/mix array & ke

27 Aug 2014, 20:54

Eh..All right :problem:
Amend done.
我为人人,人人为己?
lexikos
Posts: 9559
Joined: 30 Sep 2013, 04:07
Contact:

Re: [Vetoed]Object Constructors {} key with quota/mix array&

28 Aug 2014, 00:05

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.
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

Re: [Vetoed]Object Constructors {} key with quota/mix array&

28 Aug 2014, 00:22

@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.
我为人人,人人为己?

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 35 guests