Page 1 of 1
Programming Languages Allowing "Comlex" Prepositio
Posted: Tue Jan 10, 2006 10:44 am
by nigma
Does anyone know of languages that would allow you to test whether either x or y is equal to z like this
Code: Select all
if ((x || y) == z) // Do something
as opposed to how you would have to do this in C with
Code: Select all
if (x == z || y == z) // Do something
Posted: Tue Jan 10, 2006 10:50 am
by timvw
php

in_array($z, array($x, $y))
although i've just started learing lisp (or any other function language), i've got a feeling it should be fairly easy to express this: (but can't give an example right away)
Re: Programming Languages Allowing "Comlex" Prepos
Posted: Tue Jan 10, 2006 10:50 am
by pilau
nigma wrote:Does anyone know of languages that would allow you to test whether either x or y is equal to z like this
Code: Select all
if ((x || y) == z) // Do something
as opposed to how you would have to do this in C with
Code: Select all
if (x == z || y == z) // Do something
I don't know of a language that does this but I find the latter code (the one we use on PHP, for example) more convenient. Maybe because I got used to it.
Posted: Tue Jan 10, 2006 1:53 pm
by feyd
yeah, the z in set x, y would be the way to go. There are no languages that I know of that have such a construct as an operator though.. I'd imagine ML has it. The problem I'm seeing is there's no operator combination I can really think of that would make sense in this situation.
nigma's first example would calculate if x or y would evaluate to true then check if z matched the result, obviously not the intention. I have to say though, it is quite rare that I have to do such a comparison in any of the languages and developments I have done personally.
Posted: Tue Jan 10, 2006 2:30 pm
by nigma
Maybe that wasn't the best example. A more practical one might be if you wanted to check whether the value of a variable falls between two other values. For example, instead of having to say "if x is less than this AND x is greater than that" you could say "if x is less than this and greater than that".
Maybe in implementation in might look something like:
Does this make sense?
Posted: Tue Jan 10, 2006 3:03 pm
by feyd
although I can understand, and have at times wanted to do just that, I often do this instead:
Code: Select all
if($x < 1) {
// execute left hand
} elseif( $x > 5 ) {
// execute right hand
} else {
// $x is between 1 and 5
}
mostly because I need to do special case work for each instance, so I order it to how and where the language will help me do it efficiently

Posted: Tue Jan 10, 2006 11:09 pm
by nigma
Feyd, does that mean you don't think it'd be a useful language feature?
Posted: Wed Jan 11, 2006 12:21 am
by timvw
I think you would end up with a lot of operators... eg: "l < $var < r", "l <= $var < r", ... These are still relatively simple to understand but if you look at the way perl6 is going with all it's operators i have my doubts if they really make things easier...