Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-09-2009, 06:02 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Array Slicing

This is probably a bit of a large request because it involves the syntax of the language itself, but having slicing syntax similar to that of Python would be really useful.
For example:
PHP Code:
foo "bar";
baz foo[0:1]; // return a slice from index 0 to 1
echo(baz);      // will echo "ba"
baz foo[:-1]; // return a slice from the end
echo(baz;       // will echo "r" 
It's extremely useful and shortens common string and array operations greatly.
Really, better support for treating strings as arrays in general would be nice.
Reply With Quote
  #2  
Old 11-09-2009, 06:30 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
what's wrong with using substring and subarray?

I guess this is just to make code shorter.
__________________
Quote:

Last edited by fowlplay4; 11-10-2009 at 02:28 AM..
Reply With Quote
  #3  
Old 11-09-2009, 10:18 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Yeah. This just looks like an alternative substring() syntax...
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #4  
Old 11-09-2009, 10:55 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
It's not different, my point is it's cleaner and shorter. Which is important.
Reply With Quote
  #5  
Old 11-10-2009, 03:20 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by coreys View Post
It's not different, my point is it's cleaner and shorter. Which is important.
But it already exists. Let's not make GS2 even harder to learn by adding redundant syntax...
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #6  
Old 11-10-2009, 03:56 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Hey look, it's another "this other language does this better so let's put it in GS2" thread!
Reply With Quote
  #7  
Old 11-10-2009, 04:22 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Quote:
Originally Posted by LoneAngelIbesu View Post
But it already exists. Let's not make GS2 even harder to learn by adding redundant syntax...
Make it harder? This would make it easier, and clearer. x.x
Reply With Quote
  #8  
Old 11-10-2009, 04:25 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Personally, I just wish GS2's substring supported something like string.substring(-1) which would take off 1 character from the back of the string, rather than having to write out: string.substring(0, string.length() - 1)
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #9  
Old 11-10-2009, 04:35 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
That alone would be a very nice addition.
Reply With Quote
  #10  
Old 11-10-2009, 05:20 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Tigairius View Post
Personally, I just wish GS2's substring supported something like string.substring(-1) which would take off 1 character from the back of the string, rather than having to write out: string.substring(0, string.length() - 1)
Amen. I was trying to do something similar the other day and was surprised to find it didn't work.
__________________
Reply With Quote
  #11  
Old 11-11-2009, 01:49 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by coreys View Post
Make it harder? This would make it easier, and clearer. x.x
And redundant. A new scripter would be wondering, "What is the correct syntax? Do they do different things? Why are there two ways to do this? Am I doing it wrong if I do it this way?" etc.

Different languages have different ways of doing things. Python has this syntax. PHP has the array_slice() and substr() functions. GS2 has .subarray() and .substring().

Quote:
Originally Posted by Tigairius View Post
Personally, I just wish GS2's substring supported something like string.substring(-1) which would take off 1 character from the back of the string, rather than having to write out: string.substring(0, string.length() - 1)
That seems like it wouldn't be terribly difficult to do.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #12  
Old 11-11-2009, 05:02 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
You have a point, although I think it wouldn't be quite that much of a problem for new scripters. In any case, what Tig said I think is a pretty reasonable suggestion, and not hard to add in.
Reply With Quote
  #13  
Old 11-11-2009, 05:33 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by coreys View Post
You have a point, although I think it wouldn't be quite that much of a problem for new scripters.
Quote:
Originally Posted by The Zen of Python
There should be one-- and preferably only one --obvious way to do it.
You insult The Zen by attempting to get a feature added that already exists in another form. Not only that, but Python slicing uses start and end indexes, not start and length. That will simply add more confusion.
__________________
Reply With Quote
  #14  
Old 11-11-2009, 03:02 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
In Graal script we tried to prevent any confusion. Operators only have one meaning, that's why there is @ and + for strings and numbers, instead of using + for both. The array operator should also stay like it is, the tiles[x,y] syntax can already be confusing enough.
The substring(-1) extension could be interesting, although I'm not sure if it would break some scripts that accidently go below 0 for the index?
Reply With Quote
  #15  
Old 11-11-2009, 03:44 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Well, I personally think if their script is accidentally searching for an index below 0 that it's their own fault anyways, but in that case you could use substring(0,-1), or something like that.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:50 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.