Post by Martin Bährthis is actually one of the things i miss in pike.
I wish there are multiset/mapping/array compared by values.
I wrote a ByValue.pmod to implement this, but still want a native one, must inherit ByValue.Item is boring.
$ cat ByValue.pmod/module.pmod
#! /bin/env pike
class Array(mixed ... a)
{
mixed `[](int pos){ return a[pos];}
mixed `[]=(int pos,mixed val){ return a[pos]=val;}
int _sizeof()/*{{{*/
{
return sizeof(a);
}/*}}}*/
int `==(object rhd)/*{{{*/
{
if(!objectp(rhd))
return 0;
return equal(a,rhd->a);
}/*}}}*/
int `<(object rhd)/*{{{*/
{
if(sizeof(a)==sizeof(rhd->a)){
if(sizeof(a)==0)
return 0;
if(a[0]<rhd->a[0])
return 1;
else if(a[0]==rhd->a[0])
return .Array(@a[1..])<.Array(@rhd->a[1..]);
else if(a[0]>rhd->a[0])
return 0;
}
}/*}}}*/
object `-(object rhd)/*{{{*/
{
object res=.Array(@allocate(sizeof(a)));
for(int i=0;i<sizeof(a)&&i<sizeof(rhd->a);i++){
res->a[i]=a[i]-rhd->a[i];
}
return res;
}/*}}}*/
object `+(object ... args)/*{{{*/
{
object res=.Array(@allocate(sizeof(a)));
for(int i=0;i<sizeof(a);i++)
res->a[i]=a[i];
foreach(args,object rhd){
for(int i=0;i<sizeof(res->a)&&i<sizeof(rhd->a);i++){
res->a[i]=res->a[i]+rhd->a[i];
}
}
return res;
}/*}}}*/
int __hash()/*{{{*/
{
return hash_value(predef::`+(0.0,@map(a,hash_value)));
}/*}}}*/
string _sprintf(int t)/*{{{*/
{
if(t=='O'){
array aa=({});
foreach(a,mixed v){
aa+=({sprintf("%O",v)});
}
return "Array("+aa*","+")";
}
}/*}}}*/
}
class Pair{
inherit .Array;
void create(mixed first,mixed second)/*{{{*/
{
::create(first,second);
}/*}}}*/
string _sprintf(int t)/*{{{*/
{
if(t=='O'){
array aa=({});
foreach(a,mixed v){
aa+=({sprintf("%O",v)});
}
return "Pair("+aa*","+")";
}
}/*}}}*/
}
class Set{
inherit .Array;
void create(mixed ... args)/*{{{*/
{
::create(@sort(args));
}/*}}}*/
string _sprintf(int t)/*{{{*/
{
if(t=='O'){
array aa=({});
foreach(a,mixed v){
aa+=({sprintf("%O",v)});
}
return "Set("+aa*","+")";
}
}/*}}}*/
}
int sn;
int autoid()
{
return ++sn;
}
class Item{
int _byvalue_item_id=.autoid();
int `<(object rhd)/*{{{*/
{
if(Program.inherits(rhd,Item)){
return _byvalue_item_id<rhd->_byvalue_item_id;
}
}/*}}}*/
int __hash()/*{{{*/
{
return hash_value(_byvalue_item_id);
}/*}}}*/
string _sprintf(int t)/*{{{*/
{
if(t=='O'){
return "ByValue.Item("+_byvalue_item_id+")";
}
}/*}}}*/
}
Guo Xue Song
Post by Martin BährDate: Sun, 16 Nov 2014 17:58:56 +0100
Subject: Re: New "cut" operator (was: Pike 8.0 RC1)
Post by ééªæ¾Post by Peter Bortasstring cutfront(string text, string divisor)
"<some thing>"->cutfront(">")
I would think cutfront is ok. object oriented you know, the object was always come out first.
this is actually one of the things i miss in pike.
i'd love
string_value->function(args ...);
String.function(string_value, args ...);
same for other types.
greetings, martin.
--
eKita - the online platform for your entire academic life
--
chief engineer eKita.co
pike programmer pike.lysator.liu.se caudium.net societyserver.org
BLUG secretary beijinglug.org
foresight developer foresightlinux.org realss.com
unix sysadmin
Martin BÀhr working in china http://societyserver.org/mbaehr/