karzilla: a green fist above the word SMASH! (Default)
[staff profile] karzilla

Bug counts: resolved 228, assigned 23, needs-review 21



I figured out how to bend S2 to my will! Well, a bit anyway.

I was all "um there's no sort function here wtf" and then I saw this bit of wiki that described how to make a Perl subroutine load into S2. So that's what I did.

function builtin keys_alpha(string{} elements) : string[]
"Return the keys of the array in alphabetically sorted order.";


That's it. keys_alpha is a regular Perl subroutine in LJ::S2. The only nonintuitive part (for me, because I don't like languages that declare variable types) was figuring out what the input and output type declarations should look like. As near as I can figure, string[] is a regular array reference and string{} is like a hash reference, except unlike a Perl hash it implicitly acts like an array of hash keys in array context. Anyway, I needed an array because in Perl, arrays preserve the ordering of their elements and hashes do not.

So yeah, that wasn't as hard as I feared.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org

Page generated Apr. 15th, 2026 10:29 pm
Powered by Dreamwidth Studios