Re: question on syntax[a,b,c]

new topic     » goto parent     » topic index » view thread      » older message » newer message

Salix wrote:
> 
> Hello,
> 
> I do not miss this option a lot but I would love to hear opinion. Currently
> the Euphoria syntax allows you to create new sequences (for printf() let's
> say)
> this way:
> 
> }}}
<eucode>
> sx={buffer[1],buffer[2],buffer[4],buffer[5],buffer[8],buffer[3],buffer[7]}
> -- or 
> sx=buffer[1..2]&buffer[4..5]&{buffer[5],buffer[8],buffer[3],buffer[7]}
> </eucode>
{{{

> 
> At the same time it would simplify the code a bit if you could say 
> 
> }}}
<eucode>
> sx=buffer[1,2,4,5,8,3,7]
> -- or 
> sx=buffer[{1,2,4,5,8,3,7}]
> </eucode>
{{{

> 
> Just to make it clear: apart from readabilty issues I do not see any
> advantage,
> so I do not propose it to be implemented. It's just that I'd like to know the
> reasons of this limitation.

I would say because:
  a) there is not much call for it, so it never got done.
  b) nested slices etc get tricky and we'd never agree on the syntax.
  c) this sort of requirement tends to be application-specific.
  d) it is trivial and more flexible to roll your own, eg:
function subset_of(sequence src, sequence idii)
sequence res
    res = repeat(0,length(idii))
    for j=1 to length(idii) do
	res[j] = src[idii[j]]
    end for
    return res
end function

sequence buffer, sx
    buffer={11,22,33,44,55,66,77,88,99}
    sx = subset_of(buffer,{1,2,4,5,8,3,7})
?sx


To expand on point b, you should ask what code sh/could replace eg
sx={buffer[3][1..2],buffer[7][3][1]&buffer[4..6]}


Regards,
Pete

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu