Suggested Extension to Euphoria language
- Posted by JEFF ZEITLIN <jeff.zeitlin at EXECNET.COM> Feb 26, 1997
- 902 views
I was doing what I call "concept coding" today, and found that a lot of what I was doing for the project involved building up sequences from selected elements of other sequences, frequently within loops of various types. It occurred to me that an extension of the slice concept might come in useful here, such that if the subscript were a sequence of integers, it would have the effect of selecting those items in the sequence in the corresponding positions. Under such an extension, a[3..6] (legal syntax) and a[{3,4,5,6}] (illegal, but proposed) would be equivalent - but one could also write a[{1,3,4,6,8,12}] and get back a sequence containing only those elements, in that order. This would also naturally open up the possibilities of "reverse slices" (i.e., a[6..3] (illegal syntax)) in the form a[{6,5,4,3}]. As it is, to process these "extended slices", I must place the desired sequence in a variable, and then loop on the index into the variable to build the result sequence: index_seq = {1,2,3,5,8} b = {} for i = 1 to length(index_seq) b = append(b,a[index_seq[i]]) end for whereas under the proposed sequence I could say b = a[index_seq] I find this extension to be no less intuitive than the current sequential slice syntax (b = a[3..6]), and, as indicated, it seems to me to be a logical extension. Comments? N.B. for those who are curious, "concept coding" means that the code is essentially the core routines with hard-coded values (which should be parameters) to determine if the lines that I am thinking along are appropriate to solve the problem I am working on. ========================================================================= Jeff Zeitlin jeff.zeitlin at execnet.com --- ~ OLXWin 1.00b ~ War on drugs?!?! Put ME on the FRONT LINES!!!!