Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created Text Operations #2

Closed
s-p-n opened this issue Aug 10, 2013 · 0 comments
Closed

Created Text Operations #2

s-p-n opened this issue Aug 10, 2013 · 0 comments
Assignees

Comments

@s-p-n
Copy link
Owner

s-p-n commented Aug 10, 2013

[Version: 0.0.2-11-chinchilla]

I added index and range selection to Texts. "bar"[1] will be "a". Here is an example:

/*
    Given a string, return a new string where the first and last chars have been exchanged. 
*/

var frontBack = (str: "") {
    return if str[0] is str[-1]:
        str;
    else:
        str[-1] & str[1:-1] & str[0];
    end;
};

print(frontBack("code"));   // eodc
print(frontBack("a"));      // a
print(frontBack("ab"));     // ba
print(frontBack("abba"));   // abba

You can use negative numbers on the second parameter to cycle backward through the text. You can also use negative numbers in regular indices. For example, "bar"[-1] is"r"`.

Arrays are unusable due to a regression.

@ghost ghost assigned s-p-n Aug 10, 2013
@s-p-n s-p-n closed this as completed Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant