hi,
i am wondering why there seem to be no functions for || or &&. what is the reason for that?
greetings, martin.
instead of: a[0] || a[1] || a[2] || ... a[n] i could use: `||(@a)
i am currently using `|(@a) which works because a is array(int) in that case. but it would not work for other cases.
greetings, martin.
Because || and &&, much like ?, aren't really operators, but rather control structures disguised as operators. It's impossible to uphold the semantics of ||, && and ? if they would require function calls.
Or, well, I suppose it would be possible in theory if the right-side expressions would be passed as implicit lambdas to an operator function, but that would be rather ugly, and not particularly useful except as a way of confusing the user.
/ Leif Stensson, Lysator
Previous text:
2004-09-26 23:16: Subject: is there a `||()
hi,
i am wondering why there seem to be no functions for || or &&. what is the reason for that?
greetings, martin.
/ Brevbäraren
thank you, that was the answer i was looking for. i didn't understand why at first, but while writing to explain how i don't understand why the semantics are different, i realized that for OR(a, b) both a AND be must be evaluated, but for (a||b) this is not the case.
now, anyone have a suggestion how to solve an equivalent of: `|(@array(int)) with array(mixed)? i could write a helper function, but maybe there is a neat shortcut somewhere.
greetings, martin.
Array.reduce(lambda(mixed a,mixed b) { return a||b; },({0,0,1}));
(2) Result: 1
maybe?
/ Mirar
Previous text:
2004-09-27 00:10: Subject: Re: is there a `||()
thank you, that was the answer i was looking for. i didn't understand why at first, but while writing to explain how i don't understand why the semantics are different, i realized that for OR(a, b) both a AND be must be evaluated, but for (a||b) this is not the case.
now, anyone have a suggestion how to solve an equivalent of: `|(@array(int)) with array(mixed)? i could write a helper function, but maybe there is a neat shortcut somewhere.
greetings, martin.
/ Brevbäraren
int OR(array x) { return search(`!(x[*]),0) == -1; } int AND(array x) { return sizeof(`!(x[*]) - ({0})); }
There are many other ways of course. Calling `! on each element allows for x->`!() to be evaluated.
/ Fredrik (Naranek) Hubinette (pappa)
Previous text:
2004-09-27 00:10: Subject: Re: is there a `||()
thank you, that was the answer i was looking for. i didn't understand why at first, but while writing to explain how i don't understand why the semantics are different, i realized that for OR(a, b) both a AND be must be evaluated, but for (a||b) this is not the case.
now, anyone have a suggestion how to solve an equivalent of: `|(@array(int)) with array(mixed)? i could write a helper function, but maybe there is a neat shortcut somewhere.
greetings, martin.
/ Brevbäraren
pike-devel@lists.lysator.liu.se