[yast-devel] new builtin sublist
Hi, I have added a new builtin to YCP (yast2-core 2.16.46) called sublist. More or less like substring. ciao Arvin -- Arvin Schnell, <aschnell@suse.de> Software Engineer, Research & Development SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On Wed, Apr 09, 2008 at 11:26:15AM +0200, Arvin Schnell wrote:
Hi,
I have added a new builtin to YCP (yast2-core 2.16.46) called sublist. More or less like substring.
Here is the documentation: There are two version, one takes 2 args the other 3: * @builtin sublist * @short Extracts a sublist * * @description * Extracts a sublist of the list <tt>LIST</tt> starting at * <tt>OFFSET</tt>. The <tt>OFFSET</tt> starts with 0. * * @param list LIST * @param integer OFFSET * @return list * * @usage sublist ([ "a", "b", "c"], 0) -> [ "a", "b", "c" ] * @usage sublist ([ "a", "b", "c"], 2) -> [ "c" ] * @builtin sublist * @short Extracts a sublist * * @description * Extracts a sublist of the list <tt>LIST</tt> starting at * <tt>OFFSET</tt> with length <tt>LENGTH</tt>. The * <tt>OFFSET</tt> * starts with 0. * * @param list LIST * @param integer OFFSET * @param integer LENGTH * @return list * * @usage sublist ([ "a", "b", "c"], 0, 2) -> [ "a", "b" ] * @usage sublist ([ "a", "b", "c"], 1, 1) -> [ "b" ] -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
Arvin Schnell wrote:
* @usage sublist ([ "a", "b", "c"], 0) -> [ "a", "b", "c" ] * @usage sublist ([ "a", "b", "c"], 2) -> [ "c" ]
It does not beat ruby's elegance. ;-) In ruby, Arrays have operator[], where with one parameter it returns an Object (the object at the given index), but if operator [] has two parameters, then it returns an array with the given range. [1,2,3,4,5,6][1] => 2 [1,2,3,4,5,6][1,3] => [2, 3, 4] Of course you can do a = [1,2,3,4,5,6] a[1] or a[1,3] I just wanted to enhance that the method [] is available on a explicit array as much as you can see Integer methods doing 3.methods or get the abs by doing -10.abs Duncan -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On Wed, Apr 09, 2008 at 03:07:00PM +0200, Duncan Mac-Vicar Prett wrote:
Arvin Schnell wrote:
* @usage sublist ([ "a", "b", "c"], 0) -> [ "a", "b", "c" ] * @usage sublist ([ "a", "b", "c"], 2) -> [ "c" ]
It does not beat ruby's elegance. ;-)
Neither does it beat python's slice syntax elegance ;-) s = "hello world" s[6:] -> 'world' from 6th on s[:5] -> 'hello' upto 5th s[-5:] -> 'world' from 5th backwards on s[:-6] -> 'hello' upto 6th backwards s[2:8] -> 'llo wo' from 2nd to 8th s[2:8:2] -> 'low' from 2nd to 8th but only every second s[9:2:-2] -> 'lo l' :) But having to write "sublist(s, nil, -2, nil)" doesn't look so cool. cu Arvin -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
participants (2)
-
Arvin Schnell
-
Duncan Mac-Vicar Prett