Programming Languages Allowing "Comlex" Prepositio

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Programming Languages Allowing "Comlex" Prepositio

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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)
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Re: Programming Languages Allowing "Comlex" Prepos

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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:

Code: Select all

if (x (< 5 && > 1))
Does this make sense?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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 :)
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Feyd, does that mean you don't think it'd be a useful language feature?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
Post Reply