RE: A question about certain language features

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

Your syntax, and the form that I am suggesting are virtually identical.
The difference is in readability, and ease of implementation.
Compare:
foo[1..]   == foo[1..length(foo)]
foo[1..-1] == foo[1..length(foo)-1]

foo[1..0]  == foo[1..length(foo)]
foo[1..0-1]== foo[1..length(foo)-1]

Your implementation requires 2 checks for substitution.
My suggestion is to simply subtitute the literal '0' with length(foo)

foo[1..] could just be a typo.
foo[1..0] is defined explicity.

Yes, my example could be a typo also, but not as likely to happen.

foo[1..-1] the negative could be fairly easily missed.
foo[1..0-1] knowing that the literal '0' is always substituted with 
length(foo), it's easy to see the intention.


To summarize, your implementation adds two new rules, whereas my 
suggestion only adds one.
The concepts are identical, but the representation is different.


Chris

kbochert at ix.netcom.com wrote:
> -------Phoenix-Boundary-07081998-
> Content-type: text/plain; charset=ISO-8859-1
> Content-transfer-encoding: 8bit
> 
> You wrote on 3/21/02 10:54:37 AM:
> 
> >Karl,
> >
> >   Consider this syntax for shorthand slicing. Your current syntax sort
> >of defeats the sequence bounds checking.
> >
> >seq[1..0] -- seq[1..length(seq)]
> >seq[1..0-1] -- seq[1..length(seq)-1]
> >
> >seq[1..1-1] -- {} (reverse slice)
> >seq[1..-1] -- index [-1] out of bounds
> >
> >integer index   index=0
> >seq[1..index] -- {} (reverse slice)
> >
> >'O' is explicit, it cannot be implied. If it is, the original EU rules
> >apply.
> >
> >I haven't thouroughly looked. Does your shorthand work if it's implied
> >with a variable?
> >
> >
> >Chris
> 
> I handle 'foo[2..]' by expanding it textually. I think of it
> as a macro.
> 
> when I see the '..' followed by a ']' or '-', I insert the text
> 'length(foo)' directly into the input stream. (Having previously
> saved the 'foo').
> 'foo[2..]' causes the interpreter to actually see 'foo[2..length(foo)]'
> and 'foo[2..-(a*b)]' is seen as 'foo[2..length(foo)-(a*b)]'
> 
> 
> As a result, all the normal Euphoria processing is left intact.
> 
> Thanks for the link
> Karl Bochert
> 
> 
> -------Phoenix-Boundary-07081998---
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu