RE: listed subscripting
- Posted by Cuvier Christian <christian.cuvier at insee.fr> Apr 24, 2006
- 500 views
> Subject: Re: listed subscripting > > > posted by: ags <eu at 531pi.co.nz> > > Antonio Alessi wrote: > > An expression like: > > }}} <eucode> > > newString- = > originalString[1..2]&"INSERT"&originalString[5..9]&originalStr > ing[27..$] > > </eucode> {{{ > > could simply become: > > }}} <eucode> > > newString- = originalString[1..2]&"INSERT"&[5..9]&[27..$] > > </eucode> {{{ > > It should be plain to implement, I mean more useful than > complicated... > > I don't think that would work very well. What if you wanted > to use multiple strings like: > > }}} <eucode> > newString = originalString[1..2] & "INSERT" & > otherString[3..5] & [5..9] > </eucode> {{{ > What would the "[5..9]" refer to? > > I like the idea of listed subscripts though. It would only > be useful IMHO if it worked with predefined sequences like: > > }}} <eucode> > constant REPORT_FIELDS = {1,5,9,13} > > sequence item > > --in some for loop > item = record[REPORT_FIELDS] > </eucode> {{{ > > That changes the semantics codepilot originally brought up though, ie: > > variable[1,5,9,13] > > does not look the same as > > variable[{1,5,8,13}] > > and Al Getz wrote: > > I've had my share of problems like this too, where you could use > > some sort of functionality to deal with sequences easier. > > Another that comes immediately to mind is > > {a,b,c,d}=s[1,2,3,4] > > I think Rob has already made his views clear on multiple > lvalue assignment and I tend to think it would be a headache > in the context of Euphoria. > > What happens (even in the case of a subscript list) if the > sequence s is not as long as the subscript list? > > Gary > Perhaps a cleaner syntax would be to mention the insert explicitly rather than through the use of & when only one sequence is involved, using & when really concatenating different things:
newString=insert(originalString[1..2,5..9,27..$],"INSERT",3) --but newString=originalString[1..2]&"INSERT"&otherString[5..9,27..$]
And of course, it is a real pain not to be able to write:
function doSomething(sequence vars) --... end function procedure whatEver() integer n1,n2 sequence s1,s2,s3 --... {n1,n2,s1,s2,s3}=doSomething({n1,n2,s1,s2,s3}) --... end procedure
The above code would allow to write a separate routine for what doSomething does, avoiding the error prone, tiresome, cluttered, unelegant urrent solution:
vars=doSomething({n1,n2,s1,s2,s3}) n1=vars[1] s1=vars[3] --etc
Rob, when will you decide to make Euphoria simple to use??? CChris