for in list

114 views
Skip to first unread message

Paul Kukiel

unread,
Jun 2, 2015, 12:28:48 AM6/2/15
to lu...@googlegroups.com
Kinda expected this to work?

<cfscript>

  myList = "1,2,3,4,5"  ;

  for(item in myList){
    writeOutput(item);
  }
  
</cfscript>


--
Paul Kukiel

Igal @ Lucee.org

unread,
Jun 2, 2015, 1:00:04 AM6/2/15
to lu...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAHX0TS7hf67-gtnU4BmddJvTnTA0LJyrysAvpz8z1AmAYsUEUg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Paul Kukiel

unread,
Jun 2, 2015, 2:42:59 AM6/2/15
to lu...@googlegroups.com

I'll double check the version but it was from Jordan's installers Friday night.

Mark Drew

unread,
Jun 2, 2015, 3:11:23 AM6/2/15
to lu...@googlegroups.com
Not sure why? Lists are not s primitive collection. Just a string. 

Try 
myList = listToArray("1,2,3,4,5")  ;

  for(item in myList){
    writeOutput(item);
  }

Mark Drew
- Sent by typing with my thumbs. 
--

Adam Cameron

unread,
Jun 2, 2015, 3:29:49 AM6/2/15
to lu...@googlegroups.com


On Tuesday, 2 June 2015 08:11:23 UTC+1, Mark Drew wrote:
Not sure why?



-- 
Adam 

Jean Moniatte

unread,
Jun 2, 2015, 3:31:39 AM6/2/15
to lu...@googlegroups.com

On Tue, Jun 2, 2015 at 9:11 AM, Mark Drew <mark...@gmail.com> wrote:
Not sure why?

Because it is practical and avoids converting the string to an array.

Thanks,
Jean


Adam Cameron

unread,
Jun 2, 2015, 3:37:36 AM6/2/15
to lu...@googlegroups.com
Indeed. Whilst CFML makes a claim that there is such a thing as a list (which is string with element delimiters in it: we *get that*), then it stands to reason that all the usual collection-iteration possibilities are availed to it.

In for a penny, in for a pound. Even if they penny is misshapen and not accepted as legal tender anywhere else.

That said: hands up who'd like to list support in .lucee entirely? [raises hand. Raises other hand too].

-- 
Adam

Paul Kukiel

unread,
Jun 2, 2015, 3:43:30 AM6/2/15
to lu...@googlegroups.com

Works in ACF and to be honest I did expect it to work in lucee

Mark Drew

unread,
Jun 2, 2015, 3:46:47 AM6/2/15
to lu...@googlegroups.com
Sorry. Hadn't memorised all tickets. Still a stupid idea. 


Mark Drew
- Sent by typing with my thumbs. 
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

Jean Moniatte

unread,
Jun 2, 2015, 3:48:53 AM6/2/15
to lu...@googlegroups.com

On Tue, Jun 2, 2015 at 9:46 AM, Mark Drew <mark...@gmail.com> wrote:
Still a stupid idea. 

If you say so.

Mark Drew

unread,
Jun 2, 2015, 3:49:19 AM6/2/15
to lu...@googlegroups.com
I have seen too much crap code using lists (Gert will back me up on this. Inside joke etc) that they make my skin crawl. Hence my questioning. Arrays are faster but I guess if under the covers it converts it to an array for you to loop through then fair enough. Go listy listy!


Mark Drew
- Sent by typing with my thumbs. 

Adam Cameron

unread,
Jun 2, 2015, 3:50:49 AM6/2/15
to lu...@googlegroups.com


On Tuesday, 2 June 2015 08:46:47 UTC+1, Mark Drew wrote:
Sorry. Hadn't memorised all tickets.


It's always best to be informed before putting one's oar in, I find. Still: I know I am an outlier in that regard.

 
Still a stupid idea. 


No. Dogmatically going "it's just a string", and being in denial that CFML has a concept that is a string-based collection is what's stupid.

-- 
Adam


Mark Drew

unread,
Jun 2, 2015, 3:51:36 AM6/2/15
to lu...@googlegroups.com
It *was* just not very performant. I have seen code that had 100's of ListGetAt all over the place in one template hence my negative attitude to use lists as a collection.  

As I said before, I wouldn't use it and if Lucee converts it to a nice array under the covers for you, then great. Go for it. 


Mark Drew
- Sent by typing with my thumbs. 
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

Mark Drew

unread,
Jun 2, 2015, 3:52:49 AM6/2/15
to lu...@googlegroups.com
I shall shut my mouth up until I can do all the relevant research on my mobile then. 
Sorry for having stupid ideas.  

Mark Drew
- Sent by typing with my thumbs. 
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

Adam Cameron

unread,
Jun 2, 2015, 3:57:54 AM6/2/15
to lu...@googlegroups.com


On Tuesday, 2 June 2015 08:49:19 UTC+1, Mark Drew wrote:
I have seen too much crap code using lists


I hasten to add that my "support" (which was more just an acknowlegdment than any sort of advocacy) of this feature in no way ought to suggest I actually think anyone should ever be using strings in this way. On the contrary: ppl should be shot for doing so in most situations I see lists being used.

However this has nothing to do with the language properly supporting a concept it's decided to implement.

-- 
Adam


Desmond Miles

unread,
Jun 2, 2015, 4:54:20 AM6/2/15
to lu...@googlegroups.com
I would not add "for in" string list support in .lucee dialect (my opinion).

I agree with some people that looping over a string is not efficient over Arrays. I would use the available cf string utilities (just like java did with their string tokenizer for e.g)

If it is intended be a shorcut for converting string list to an array then it must add a "delimiter" parameter.
I'm not a Lucee code contributor but for example the current 4.5.1.016 (and master branch) implementation only works with comma separated string list.

Adam Cameron

unread,
Jun 2, 2015, 5:09:18 AM6/2/15
to lu...@googlegroups.com


On Tuesday, 2 June 2015 09:54:20 UTC+1, Desmond Miles wrote:
If it is intended be a shorcut for converting string list to an array then it must add a "delimiter" parameter.

Good point, the solution for this has not been implemented properly, as the delimiter has been hard-coded (as a comma):


return ListUtil.listToArray(o.toString(), ',').getIterator();

(that's from the commit linked-to in https://luceeserver.atlassian.net/browse/LDEV-47)

It shouldn't be hard-coded at all, for a start; but it should be parameterised in this case.

I've suggested the ticket should be reopened & the work finished.

-- 
Adam

Paul Kukiel

unread,
Jun 2, 2015, 5:26:56 AM6/2/15
to lu...@googlegroups.com

Oh boy what have I done!

Lists have always been a part of cfml, can't change that, I would think that it you can cf loop list then for in would also just work.

Yes listToArray was used but it was one extra line if code to type in big deal.

I simply asked if it should work not weather my code is shit.

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

AJ Mercer

unread,
Jun 2, 2015, 5:51:41 AM6/2/15
to lu...@googlegroups.com

Paul Kukiel

unread,
Jun 2, 2015, 5:54:03 AM6/2/15
to lu...@googlegroups.com
It was good though, I decided to look up the initial change to lucee, which encouraged me to take a closer look at the underlying code.

So all in all a good result.


For more options, visit https://groups.google.com/d/optout.



--
Paul Kukiel

Desmond Miles

unread,
Jun 2, 2015, 6:37:16 AM6/2/15
to lu...@googlegroups.com
Thanks for the ticket feedback :)

Even if for-in with list is supported by ACF, their docs are not up-to-date because it does not explicitly state so (as of writing this but maybe I didn't search enough).
I hope others won't do the same forgetting as we need to know how to pass the delimiter if so.
e.g for(item in list ; delimiter = "/") or for(item in list ; "/") or  or for(item in list ; "==" , multiChars=true) etc...

Dominic Watson

unread,
Jun 2, 2015, 7:58:01 AM6/2/15
to lu...@googlegroups.com
I've created an ehancement request: https://luceeserver.atlassian.net/browse/LDEV-379


--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Pixl8 Interactive, 3 Tun Yard, Peardon Street, London
SW8 3HT, United Kingdom

T: +44 [0] 845 260 0726 W: www.pixl8.co.uk E: in...@pixl8.co.uk

Follow us on: Facebook Twitter LinkedIn
CONFIDENTIAL AND PRIVILEGED - This e-mail and any attachment is intended solely for the addressee, is strictly confidential and may also be subject to legal, professional or other privilege or may be protected by work product immunity or other legal rules. If you are not the addressee please do not read, print, re-transmit, store or act in reliance on it or any attachments. Instead, please email it back to the sender and then immediately permanently delete it. Pixl8 Interactive Ltd Registered in England. Registered number: 04336501. Registered office: 8 Spur Road, Cosham, Portsmouth, Hampshire, PO6 3EB

Mike Henson

unread,
Jun 2, 2015, 8:47:39 AM6/2/15
to lu...@googlegroups.com
Adding my vote that this should be made to work in Lucee, or at least document as deviating from Adobe CF. If your gonna claim that you are Adobe CF compatible, then don't complain when someone brings up an incompatibility. Even if you think its a stupid idea.

Dominic Watson

unread,
Jun 2, 2015, 9:26:02 AM6/2/15
to lu...@googlegroups.com
@Mike, exactly that has happened :). Lucee is now compatible with ACF on this, as of the releases associated with https://luceeserver.atlassian.net/browse/LDEV-47:

https://luceeserver.atlassian.net/projects/LDEV/versions/10201 (4.5.1.016)
https://luceeserver.atlassian.net/projects/LDEV/versions/10302 (5.0.0.50)

Dominic

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Igal @ Lucee.org

unread,
Jun 2, 2015, 10:09:47 AM6/2/15
to lu...@googlegroups.com
@Mark --

I personally agree with you, but the driving force behind fixing this issue was ACF compatibility.

if anything, I would prefer

    for (ch in someString) { /* ... to iterate over the characters of the string ... */ }

but then compatibility would completely break...


Igal Sapir
Lucee Core Developer
Lucee.org

Mark Drew

unread,
Jun 2, 2015, 10:23:28 AM6/2/15
to lu...@googlegroups.com
I  am with you on the looping over chars bit.

I *now* realise the context (I didn’t when I replied this morning) to this whole discussion. 

I didn’t realise there was some compat ticket lurking about "for loops”.

Not sure how I could have from the original post without reading between the lines. 
All I read  was
 "Kinda expected this to work?”

And I replied that I wouldn’t. 

I guess I stand corrected. 

Mark Drew


develop • deploy • deliver
http://charliemikedelta.com

Adam Cameron

unread,
Jun 2, 2015, 12:16:18 PM6/2/15
to lu...@googlegroups.com


On Tuesday, 2 June 2015 15:09:47 UTC+1, Igal wrote:
@Mark --

I personally agree with you, but the driving force behind fixing this issue was ACF compatibility.

if anything, I would prefer

    for (ch in someString) { /* ... to iterate over the characters of the string ... */ }

but then compatibility would completely break...



I've been mulling over a sensible syntactical tweak to disambiguate between "by list element" and "by char", but drew a blank.

However it's perhaps better to join the current decade and take an OO & FP approach to these things, by implementing String.each(), .reduce(), .map(), .sort(), .filter(), etc

It makes for more clear code to use purpose-specific iteration methods, rather than generic and procedural looping statements.

-- 
Adam

Adam Cameron

unread,
Jun 2, 2015, 12:21:16 PM6/2/15
to lu...@googlegroups.com


On Tuesday, 2 June 2015 17:16:18 UTC+1, Adam Cameron wrote:


On Tuesday, 2 June 2015 15:09:47 UTC+1, Igal wrote:
if anything, I would prefer

    for (ch in someString) { /* ... to iterate over the characters of the string ... */ }


I've been mulling over a sensible syntactical tweak to disambiguate between "by list element" and "by char", but drew a blank.


As soon as I pressed send, I got it.

You're stuck with the default syntax being used for looping over a comma-delimited list. However - if the solution had been implemented thoroughly - you could use a null delimiter to iterate by character, eg:

for (element in list[; delimiter[; multi-char]]);


EG:
for (char in "abc";null){ // or "" should work too
    echo
char; //abc
}


It's not as good as not needing to specifiy nothing (as it were), but as you say, Adobe's kinda stitched everyone up there.

And iteration methods are just better anyhow, so you've still got your best option available to you, and you can lead the way with CFML quite happily as CF doesn't have anything in that space already.

Thoughts? More something for the language forum perhaps? It needs a bit of love, after all...

-- 
Adam

Dominic Watson

unread,
Jun 2, 2015, 12:22:02 PM6/2/15
to lu...@googlegroups.com
A native string.split( regex ) would be great too; avoiding the 'list' baggage and implementing more flexible splitting using regex rather than a list of single character delimiters.

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Mark Drew

unread,
Jun 2, 2015, 12:24:47 PM6/2/15
to lu...@googlegroups.com
you mean something like:

var MaList = new List(“Tahi,Rua,Toru,Wha”);

for(s in MaList.each()){

}

and 

var MaString = “Elvis is the bomb!”;

for(c in MaString.each()){

}


That is much clearer in a way
?

Mark Drew



develop • deploy • deliver
http://charliemikedelta.com

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

Dominic Watson

unread,
Jun 2, 2015, 12:24:48 PM6/2/15
to lu...@googlegroups.com
p.s. Adam, I've just checked and this works:

<cfscript>
  mystring = "this is a string"
  mystring.each( function( char ){
      echo( char );
  } );
</cfscript>

Adam Cameron

unread,
Jun 2, 2015, 12:34:34 PM6/2/15
to lu...@googlegroups.com


On Tuesday, 2 June 2015 17:24:47 UTC+1, Mark Drew wrote:
you mean something like:

var MaList = new List(“Tahi,Rua,Toru,Wha”);

for(s in MaList.each()){

}


Not quite. This:

MaList.listEach(function(x){


});



Which I think we have already.

 
and 

var MaString = “Elvis is the bomb!”;

for(c in MaString.each()){

}


MaString.each(function(){


});


Although Dom says this has already been implemented for strings? I didnae know that.

 
-- 
Adam

Dominic Watson

unread,
Jun 2, 2015, 12:35:04 PM6/2/15
to lu...@googlegroups.com
Turns out I was hasty with my .each() example. It works, but not as I had expected. This is what you get:


<cfscript>
  mystring = "this is a string";
  mystring.each( function( char ){
    echo( char & char );
  } );
</cfscript>

Outputs: "this is a stringthis is a string".

You can specify a delimiter after the closure however:


<cfscript>
  mystring = "this is a string";
  mystring.each( function( char ){
    echo( char & char );
  }, "" );
</cfscript>

Outputs: tthhiiss iiss aa ssttrriinngg

Perhaps there is a way to set delim there, but not sure





For more options, visit https://groups.google.com/d/optout.

Dominic Watson

unread,
Jun 2, 2015, 12:36:04 PM6/2/15
to lu...@googlegroups.com
One for the docs!

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Jesse Shaffer

unread,
Jun 2, 2015, 5:22:36 PM6/2/15
to lu...@googlegroups.com
A clearer way to do all of this IMO is:
for (item in list.split("")) { // loop over chars
}

for (item in list.split(",")) { // loop over list elements
}
Sure, it uses reflection, but we're talking about lists.  They are already not great performance-wise.

for (element in list[; delimiter[; multi-char]]);
 
I would be against that for the same reason that you cannot specify the "step" (eg, every other element) in a for..in array loop.  Plus, this is all because of ACF compatibility.  I say this type of list loop is bad design to begin with, but since Lucee strives for ACF compat, it should be supported for the CFML dialect - but only to the level Adobe has supported it.  I surely hope the for..in list construct does not apply to the .Lucee dialect...

Adam Cameron

unread,
Jun 3, 2015, 3:35:03 AM6/3/15
to lu...@googlegroups.com


On Tuesday, 2 June 2015 22:22:36 UTC+1, Jesse Shaffer wrote:

for (element in list[; delimiter[; multi-char]]);
 
I would be against that for the same reason that you cannot specify the "step" (eg, every other element) in a for..in array loop.

That doesn't quite follow. step is never a feature of for..in loops of any description, because a for..in loop is specifically for iterating over all elements of the collection. The delimiter and multi-char parameters here are necessary to correctly support lists that a) don't use a hard-coded comma delimiter; b) have multi-char delimiters. These are the opposite of the step concept: they are required to facilitate looping over all list elements, not to omit them. However you're in good company (after a fashion)... the Adobe engineers made exactly the same misreading of the situation.

On the other hand I completely agree that using lists as a "thing" should be frowned up. However I believe that if one is going to support lists, then one should do the job thoroughly. Which has not been done here.

-- 
Adam

Jesse Shaffer

unread,
Jun 3, 2015, 9:51:57 AM6/3/15
to lu...@googlegroups.com


On Jun 3, 2015 2:35 AM, "Adam Cameron" <camero...@gmail.com> wrote:
>
>
>
> On Tuesday, 2 June 2015 22:22:36 UTC+1, Jesse Shaffer wrote:
>>
>>
>>> for (element in list[; delimiter[; multi-char]]);
>>
>>  
>> I would be against that for the same reason that you cannot specify the "step" (eg, every other element) in a for..in array loop.
>
>
> That doesn't quite follow. step is never a feature of for..in loops of any description, because a for..in loop is specifically for iterating over all elements of the collection.

Correct, it is the simplest array loop that follows the most common use case for looping over arrays.  You also cannot specify direction or an index.

> The delimiter and multi-char parameters here are necessary to correctly support lists that a) don't use a hard-coded comma delimiter; b) have multi-char delimiters. These are the opposite of the step concept: they are required to facilitate looping over all list elements, not to omit them. However you're in good company (after a fashion)... the Adobe engineers made exactly the same misreading of the situation.
>

It does follow if you expect for..in loops to be simple and *representing the defaults*.  The default for a cfloop over a list is that the list be a simple comma-delimited list. Any other needs are addressed with different (arguably better) constructs, of which there are at least 4.

> On the other hand I completely agree that using lists as a "thing" should be frowned up. However I believe that if one is going to support lists, then one should do the job thoroughly. Which has not been done here.
>

Maybe not for this particular construct.  However they are already thoroughly supported with other constructs.

This is Adobe's deal. Let them "fix" (preferably drop) it.  If they implement something along the lines of what you suggest, then by all means implement that.

Again, I hope all of this doesn't apply to the lucee dialect. I wouldn't mind for..in string.  I would, however, expect it to follow the more logical assumption of treating the string as a character array.

> -- 
> Adam
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/N_zoOEaW2xY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to lucee+un...@googlegroups.com.


> To post to this group, send email to lu...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/f845d6b3-470a-46bc-8edb-a28c0b68885d%40googlegroups.com.

Michael Offner

unread,
Jun 3, 2015, 11:41:08 AM6/3/15
to lucee
Hi Paul

the thread get a little bit offtopic, but your inital example should work with the current release. as you can see in the textcases this is covered:

I have also executed your code and I get the following output:
12345

Micha



Adam Cameron

unread,
Jun 3, 2015, 12:33:11 PM6/3/15
to lu...@googlegroups.com


On Wednesday, 3 June 2015 14:51:57 UTC+1, Jesse Shaffer wrote:

> That doesn't quite follow. step is never a feature of for..in loops of any description, because a for..in loop is specifically for iterating over all elements of the collection.

Correct, it is the simplest array loop that follows the most common use case for looping over arrays.  You also cannot specify direction or an index.

> The delimiter and multi-char parameters here are necessary to correctly support lists that a) don't use a hard-coded comma delimiter; b) have multi-char delimiters. These are the opposite of the step concept: they are required to facilitate looping over all list elements, not to omit them. However you're in good company (after a fashion)... the Adobe engineers made exactly the same misreading of the situation.
>

It does follow if you expect for..in loops to be simple and *representing the defaults*.  The default for a cfloop over a list is that the list be a simple comma-delimited list. Any other needs are addressed with different (arguably better) constructs, of which there are at least 4.

We can agree to disagree. I think your analysis is a bit of a retcon sort of thing, but hey. I don't really care. One way or the other.

 

Again, I hope all of this doesn't apply to the lucee dialect. I wouldn't mind for..in string.  I would, however, expect it to follow the more logical assumption of treating the string as a character array.


But we agree with each other on this one, yes.

Is there a ticket for this? Or perhaps a discussion on the language forum?

-- 
Adam

Adam Cameron

unread,
Jun 4, 2015, 3:51:36 AM6/4/15
to lu...@googlegroups.com


On Tuesday, 2 June 2015 15:09:47 UTC+1, Igal wrote:

if anything, I would prefer

    for (ch in someString) { /* ... to iterate over the characters of the string ... */ }



Reply all
Reply to author
Forward
0 new messages