• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

dynamic array

Engaged ,
Oct 30, 2012 Oct 30, 2012

Copy link to clipboard

Copied

I just wanted to know does Colfusion support dynamic array?

Do I need to know how many rows of data to store data in advance or we can create as program needed?

How many dimensions array ColdFustion support?

Thanks again for helping and information,

regards,

Iccsi,

Views

2.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Oct 30, 2012 Oct 30, 2012

Votes

Translate

Translate
Guide ,
Oct 30, 2012 Oct 30, 2012

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2012 Oct 30, 2012

Copy link to clipboard

Copied

iccsi wrote:

I just wanted to know does Colfusion support dynamic array?

Do I need to know how many rows of data to store data in advance or we can create as program needed?

You can dynamically store as many as you like. In the following code, the array elements a[2], a[3], a[4], a[6] are undefined. Hence the need to first initialize an array using arraySet().

a = arrayNew(1);

a[1]="str a";

a[5]="str e";

a[7]="str g";

How many dimensions array ColdFustion support?

3

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2012 Oct 30, 2012

Copy link to clipboard

Copied

How many dimensions array ColdFustion support?

3

arrayNew() supports a max of three dimensons.  ColdFusion itself kinda supports any number of dimensions, with the caveat that it doesn't support true multidimension arrays at all, it merely supports arrays of arrays.

I discuss ColdFusion's array support fairly thoroughly on my blog: http://adamcameroncoldfusion.blogspot.co.uk/search/label/Arrays. Best read in chronological order.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 30, 2012 Oct 30, 2012

Copy link to clipboard

Copied

Thanks a million for helping and information,

Regards,

Iccsi,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

Adam Cameron. wrote:

arrayNew() supports a max of three dimensons.  ColdFusion itself kinda supports any number of dimensions, with the caveat that it doesn't support true multidimension arrays at all, it merely supports arrays of arrays.

True. ArrayNew() is in fact ColdFusion's way to mimic multidimensionality. ColdFusion arrays defined in other ways, such as ["a","b"], betray what a ColdFusion array really is at heart, a Java vector.

<cfscript>

     testArray = ["a","b"];

</cfscript>

<cfoutput>

Class of testArray: #testArray.getClass().getname()#<br>

Superclass of testArray: #testArray.getClass().getSuperClass().getname()#

</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

BKBK wrote:

ColdFusion arrays defined in other ways, such as ["a","b"], betray what a ColdFusion array really is at heart, a Java vector.

JavaDocs: "The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created."

Hardly seems like a "betrayal" to me. How does ArrayNew() provide you with something more true to a Vector?

Jason

Ref: http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Vector.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

12Robots wrote:

BKBK wrote:

ColdFusion arrays defined in other ways, such as ["a","b"], betray what a ColdFusion array really is at heart, a Java vector.

JavaDocs: "The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created."

Hardly seems like a "betrayal" to me. How does ArrayNew() provide you with something more true to a Vector?

I didn't suggest arrayNew() is true to a Vector. I said it is a vector at heart. The betrayal is in the true multidimensionality Adam talked about. A vector has just the single dmension, of course.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

You said "ColdFusion arrays defined in other ways, such as ["a","b"], betray what a ColdFusion array really is at heart, a Java vector."

How does using Array literal notation betray what a ColdFusion array really is? It is still a vector. It can still be used to create a "multi-dimensional" array. And it does it in a much cleaner way and can go beyond the limit of 3 dimensions.

<cfset testArray = [

          [1,2],

          [3,4]

] />

<cfset testArray2 = ArrayNew(2) />

<cfset testArray2[1][1] = 1 />

<cfset testArray2[1][2] = 2 />

<cfset testArray2[2][1] = 3 />

<cfset testArray2[2][2] = 4 />

<cfoutput>

Class of testArray: #testArray.getClass().getname()#<br>

Superclass of testArray: #testArray.getClass().getSuperClass().getname()#

<br />

Class of testArray2: #testArray2.getClass().getname()#<br>

Superclass of testArray2: #testArray2.getClass().getSuperClass().getname()#

<cfdump var="#testArray#" label="testArray 1" />

<cfdump var="#testArray2#" label="testArray 2" />

</cfoutput>

<cfset testArray3 = [

          [

                    [

                              [

                                        [

                                                  []

                                        ]

                              ]

                    ]

          ]

] />

<cfdump var="#testArray3#" label="Super Multi-Dimensional Array" />

jason

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

Let me cut a long story short. Your examples only confirm what I have said. A vector that has vectors as its elements, each of which has vectors as elements remains a vector. Its dimension remains 1.

As Adam rightly points out, arrayNew(3), like your testArray3 example, isn't true multidimensionality. It only mimics it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

>> Isn't true multidimensionality. It only mimics it.

As is the case with many languages. There is nothing wrong with emulating a multi-dimensional array using vectors, or arrays in arrays as the case may be, it is quite common.

But you still have not addressed my question. You implied there was somethign different about using Array literal notation vs ArrayNew() that somehow betrayed what arrays truly are, but you keep dodging that part of the quesitons.

If you would just either be so kind as to explain the statement I have quoted twice or just tell me, "oops, I used the wrong wording", I would be content.

Jason

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

12Robots wrote:

>> Isn't true multidimensionality. It only mimics it.

As is the case with many languages. There is nothing wrong with emulating a multi-dimensional array using vectors, or arrays in arrays as the case may be, it is quite common.

Nobody says there is anything wrong with it. There was just the fine point to be made about multidimensionality. Your own contribution only adds to the discussion, naturally.

But you still have not addressed my question. You implied there was somethign different about using Array literal notation vs ArrayNew() that somehow betrayed what arrays truly are, but you keep dodging that part of the quesitons.

I have addressed it every single time. The literal notation says nothing explicit about dimension. ArrayNew(3) tells you explicitly the dimension is 3, whereas arrayNew(3) is a vector. Vectors are one-dimensional. That is what motivated my use of the word betrayal.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

Sorry mate.  I don't follow the point you're trying to make here either.

The dimensionality in a short-hand-syntax array declaration isn't quite as clear as a number (like the 3 in arrayNew(3)), but it's clear that Jason's Super Multi-Dimensional Array example is a "multi-dimensional array" (as far as that sort of thing exists in CF).

I don't get the usage of the word "betrayal" either.

But I do think everyone is on the same page though, yes?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

Adam Cameron. wrote:

But I do think everyone is on the same page though, yes?

I think so, too.

Adam Cameron. wrote:

The dimensionality in a short-hand-syntax array declaration isn't quite as clear as a number (like the 3 in arrayNew(3)), but it's clear that Jason's Super Multi-Dimensional Array example is a "multi-dimensional array" (as far as that sort of thing exists in CF).

True.

Sorry mate.  I don't follow the point you're trying to make here either.

I think Jason read too much into the word betrayal. I actually said it in support of what you, Adam, mentioned about true multidimensionality. I'll rewind the tape.

Adam Cameron. wrote:

arrayNew() supports a max of three dimensons.  ColdFusion itself kinda supports any number of dimensions, with the caveat that it doesn't support true multidimension arrays at all, it merely supports arrays of arrays.

BKBK wrote:

True. ArrayNew() is in fact ColdFusion's way to mimic multidimensionality. ColdFusion arrays defined in other ways, such as ["a","b"], betray what a ColdFusion array really is at heart, a Java vector.

Thus, you can rewrite any array defined with arrayNew(3) in terms of the literal notation. However, the concept of multidimensionality is ambiguous in the literal notation, where the vector nature dominates. You will find, for example, that

<cfset testArray = [[1,2],3,4]>

is legitimate ColdFusion code with no arrayNew equivalent. Also, what would you say is the dimension of testArray? One and a half? After all, we know it is at least 1, and not quite 2.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

True. ArrayNew() is in fact ColdFusion's way to mimic multidimensionality. ColdFusion arrays defined in other ways, such as ["a","b"], betray what a ColdFusion array really is at heart, a Java vector.

Thus, you can rewrite any array defined with arrayNew(3) in terms of the literal notation. However, the concept of multidimensionality is ambiguous in the literal notation, where the vector nature dominates. You will find, for example, that

<cfset testArray = [[1,2],3,4]>

is legitimate ColdFusion code with no arrayNew equivalent. Also, what would you say is the dimension of testArray? One and a half? After all, we know it is at least 1, and not quite 2.

Ah right, I'm with ya.  Yeah, I see what you mean with your usage of "betray" now, although - perhaps Jason was the same - I read more of a negative connotation to it than perhaps you meant.

I like the notion of a 1.5 dimension array, btw 😉

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

BKBK wrote:

I think Jason read too much into the word betrayal.

Don't put the onus on the reader. If you don't mean "betrayal", don't write "betrayal".  You spoke about Array notation in a very negative way that made no sense to me (still doesn't). Saying that someone "read too much into" somethign is a cop out for you not writing it correctly in the first place.

Jason

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

12Robots wrote:

BKBK wrote:

I think Jason read too much into the word betrayal.

Don't put the onus on the reader. If you don't mean "betrayal", don't write "betrayal".  You spoke about Array notation in a very negative way that made no sense to me (still doesn't). Saying that someone "read too much into" somethign is a cop out for you not writing it correctly in the first place.

Cop out? Writing correctly? I don't think your sourness is justified. You seem to be reading just one meaning of the word betrayal, the one you call very negative. Words have meaning only within a given context.

It is apparent that you continue to ignore the context in which I use the word. It could also be that you are unaware of that use of the word.

Look up the word betrayal. That should convince you there are several meanings of the word that are not negative.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

And if you need to resort to the 3rd or 4th definition of a word, then there is probably a better one to choose.

I am done arguing.  As you were.

Jason

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2012 Oct 31, 2012

Copy link to clipboard

Copied

LATEST

Nuff's nuff.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation