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.
Page generated Feb. 15th, 2026 01:34 pm
Powered by Dreamwidth Studios