Negative values in range expression

View: New views
3 Messages — Rating Filter:   Alert me  

Negative values in range expression

by Toula Michael-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

List,

Looking at both the code and the doc, it seems that Pnuts choose to  
not support negative values in range expression by design.

I personally think that as it is supported in array deference  
expression, it should work in range expression too. It’s especially  
useful for String manipulation.

What do you think?

Best,

Mike



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...


Re: Negative values in range expression

by Toyokazu Tomatsu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

That was my preference.  When I designed the language, I was writing a
Web application that has page-navigation interface.  It was more
convenient if array[-10..10] means array[0..10].

I know some people prefer the traditional (Perl's) approach.  If it is
really better than current design, the design should be changed in
a future version.

Can you think of any concrete example that illustrates the usefulness?

Thanks,
Toyokazu Tomatsu

> List,
>
> Looking at both the code and the doc, it seems that Pnuts choose to not
> support negative values in range expression by design.
>
> I personally think that as it is supported in array deference
> expression, it should work in range expression too. It’s especially
> useful for String manipulation.
>
> What do you think?
>
> Best,
>
> Mike
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...


Re: Negative values in range expression

by Toula Michael-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tomatsu sensei,

Some examples:

function print(s) System.out.println("" + s);

import java.io.*;

dir = new File("~/scripts/");

ext = ".pnut";

filter = new FileFilter(){
        accept(file){
                file.file && file.name.endsWith(ext);
        }
}

for(f:dir.listFiles(filter)) //prints the file name without extension
        print(`Fount a script called "` + f.name[0..f.name.length() - 6] +  
`"`);
//I would prefer: print(`Fount a script called "` + f.name[0..-6] +  
`"`);

for(f:dir.listFiles(filter)) //prints the file name without extension
        print(`Fount a script called "` + f.name[0..-6] + `"`);


import java.util.jar.*;

jar = new JarFile("pnuts.jar");

for(f:jar.entries())
        if(f.directory && f.name != "META-INF/") //  !=    works on String,  
very cool
                print(f.name.replaceAll("/", ".")[0..f.name.length() - 2]);
// I would prefer : print(f.name.replaceAll("/", ".")[0..-2]);

It's just sugar to avoid calling ‘String.length() – x’ all the time.


Best,
Mike


On 31 janv. 08, at 19:23, Toyokazu Tomatsu wrote:

> Hi,
>
> That was my preference.  When I designed the language, I was  
> writing a Web application that has page-navigation interface.  It  
> was more
> convenient if array[-10..10] means array[0..10].
>
> I know some people prefer the traditional (Perl's) approach.  If it is
> really better than current design, the design should be changed in
> a future version.
>
> Can you think of any concrete example that illustrates the usefulness?
>
> Thanks,
> Toyokazu Tomatsu
>
>> List,
>> Looking at both the code and the doc, it seems that Pnuts choose  
>> to not support negative values in range expression by design.
>> I personally think that as it is supported in array deference  
>> expression, it should work in range expression too. It’s  
>> especially useful for String manipulation.
>> What do you think?
>> Best,
>> Mike
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@...
> For additional commands, e-mail: dev-help@...
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...

LightInTheBox - Buy quality products at wholesale price!