Another Programming Idiom You've Never Heard Of
prog21.dadgum.com
Another Programming Idiom You've Never Heard Of
1–10 of 35 posts
Re: Another Programming Idiom You've Never Heard Of
#2 @a = (10, 5, 9, 6, 20, 17, 1);
@slice = @a[0, 1, 3, 6];
Though I've never seen this used for anything other than simple sublists (like @a[0..3]).Re: Another Programming Idiom You've Never Heard Of
#3Re: Another Programming Idiom You've Never Heard Of
#4Re: Another Programming Idiom You've Never Heard Of
#5Perl can do this as well: @a = (10, 5, 9, 6, 20, 17, 1); @slice = @a[0, 1, 3, 6]; Though I've never seen this used for anything other than simple sublists (like @a[0..3]).
Re: Another Programming Idiom You've Never Heard Of
#6Perl can do this as well: @a = (10, 5, 9, 6, 20, 17, 1); @slice = @a[0, 1, 3, 6]; Though I've never seen this used for anything other than simple sublists (like @a[0..3]).
@state[1,2,3,5,6,7,9,10,11,13,14,15] =
@state[5,10,15,9,14,3,13,2,7,1,6,11];
That's the row shift transformation in AES encryption.Re: Another Programming Idiom You've Never Heard Of
#7Perl can do this as well: @a = (10, 5, 9, 6, 20, 17, 1); @slice = @a[0, 1, 3, 6]; Though I've never seen this used for anything other than simple sublists (like @a[0..3]).
a = [10 5 9 6 20 7];
slice = a([1 2 4 7]);
I guess it's not called matrix laboratory for nothing.Re: Another Programming Idiom You've Never Heard Of
#8Oh look, you just invented array slices! https://en.wikipedia.org/wiki/Array_slicing
Maybe slightly late for that.
Re: Another Programming Idiom You've Never Heard Of
#9Perl can do this as well: @a = (10, 5, 9, 6, 20, 17, 1); @slice = @a[0, 1, 3, 6]; Though I've never seen this used for anything other than simple sublists (like @a[0..3]).
@array[@indices]
in the past. Can't remember why, but I have. It also works for hashes: %hash = (foo => "bar", one => "two", alpha => "beta");
@keys = ('alpha', 'one');
@hash{@keys} == ('beta', 'two');Re: Another Programming Idiom You've Never Heard Of
#10Oh look, you just invented array slices! https://en.wikipedia.org/wiki/Array_slicing
A different guy with the same deficiency: "Wrong, it's a common idiom in (list of obscure languages)".
Plus: array slicing, in 95% of the languages mentioned (and 99% of common languages) is NOT what he talks about. It just returns a sub-array and it only takes an uper/lower bound.