Method `-()
- Method `-
mixed`-(mixedarg1)
mixed`-(mixedarg1,mixedarg2,mixed...extras)
mixed`-(objectarg1,mixedarg2)
mixed`-(mixedarg1,objectarg2)
int`-(intarg1,intarg2)
float`-(floatarg1,int|floatarg2)
float`-(int|floatarg1,floatarg2)
string`-(stringarg1,stringarg2)
array`-(arrayarg1,arrayarg2)
mapping`-(mappingarg1,arrayarg2)
mapping`-(mappingarg1,mappingarg2)
mapping`-(mappingarg1,multisetarg2)
multiset`-(multisetarg1,multisetarg2)- Description
Negation/subtraction/set difference.
Every expression with the
-operator becomes a call to this function, i.e.-ais the same aspredef::`-(a)anda-bis the same aspredef::`-(a,b). Longer-expressions are normally optimized to one call, so e.g.a-b-cbecomespredef::`-(a,b,c).- Returns
If there's a single argument, that argument is returned negated. If
arg1is an object with an lfun::`-(), that function is called without arguments, and its result is returned.If there are more than two arguments the result is:
`-(`-(.arg1,arg2), @extras)Otherwise, if
arg1is an object with an lfun::`-(), that function is called witharg2as argument, and its result is returned.Otherwise, if
arg2is an object with an lfun::``-(), that function is called witharg1as argument, and its result is returned.Otherwise the result depends on the argument types:
arg1can have any of the following types:int|floatThe result is
, and is a float if eitherarg1-arg2arg1orarg2is a float.stringThe result is
arg1with all nonoverlapping occurrences of the substringarg2removed. In cases with two overlapping occurrences, the leftmost is removed.array|mapping|multisetThe result is like
arg1but without the elements/indices that match any inarg2(according to `== and, in the case of mappings, hash_value).The function is not destructive on the arguments - the result is always a new instance.
- Note
In Pike 7.0 and earlier the subtraction order was unspecified.
- See also