Question Mark operator

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Question Mark operator

David Akbari
Hi List,

So I was looking at one of Art Hunkins' pieces today and I noticed a
syntax resembling the following:

krel = (gkoff1 == 1? gkr: 0)

kamp = (gkoff1 == 1? 0: kamp)

Basically what I'm wondering is, what is the function of the question
mark operator is in this context? Is it some kind of conditional
statement?

Any help appreciated!


-David
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

jpff-2
Standard C notation for conditional expression
==John ff

--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

Michael Rhoades
In reply to this post by David Akbari

Hi David,

 

In English I would read this statement “krel   =    (gkoff1 == 1? gkr: 0) as  “Does gkoff1 equal 1? If yes then krel is gkr otherwise krel is zero.”

 

It is a standard if/then/else statement.

 

Hope this helps.

 

Michael Rhoades

 

 

 

-----Original Message-----
From: David Akbari [mailto:[hidden email]]
Sent:
Tuesday, October 25, 2005 8:02 AM
To: [hidden email]
Subject: [Csnd] Question Mark operator

 

Hi List,

So I was looking at one of Art Hunkins' pieces today and I noticed a syntax resembling the following:

krel = (gkoff1 == 1? gkr: 0)

kamp = (gkoff1 == 1? 0: kamp)

Basically what I'm wondering is, what is the function of the question mark operator is in this context? Is it some kind of conditional statement?

Any help appreciated!


-David

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.859 / Virus Database: 585 - Release Date:
2/14/2005


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.859 / Virus Database: 585 - Release Date: 2/14/2005

Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

DaveSeidel
In reply to this post by David Akbari
Hi David,

This is what's called the "ternary" operator, originally from C, but now
also in Java and other languages.  It's essentially a kind of "if"
statement.  The structure is like this:

conditional-statement ? do-this-if-true : do-this is-false

where the conditional statement is a boolean (i.e., evaluated to true or
false), and the other statements are executed based on how the
conditional statement is evaluated.

For example:

krel = (gkoff1 == 1? gkr: 0)

can be translated into "pseudocode" like so:

   if gkoff1 is equal to 1 then
       set krel1 to gkr
   else
       set krel1 to 0

- Dave


David Akbari wrote:

> Hi List,
>
> So I was looking at one of Art Hunkins' pieces today and I noticed a
> syntax resembling the following:
>
> krel = (gkoff1 == 1? gkr: 0)
>
> kamp = (gkoff1 == 1? 0: kamp)
>
> Basically what I'm wondering is, what is the function of the question
> mark operator is in this context? Is it some kind of conditional statement?
>
> Any help appreciated!
>
>
> -David

--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

jpff
Pleassssse....it is not a conditional statement; it is a conditional expression
==John ffitch
--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

David Akbari
In reply to this post by DaveSeidel

On Oct 25, 2005, at 9:22 AM, Dave Seidel wrote:

> where the conditional statement is a boolean (i.e., evaluated to true
> or false), and the other statements are executed based on how the
> conditional statement is evaluated.

I find this very interesting. I am not a programmer so I have not
become acquainted with this until recently.

What advantages (or disadvantages) does this technique (question mark
as a conditional boolean expression) offer as opposed to:

ex1
** if (gkoff == 1) kgoto somecode
                kgoto bypasscode

ex2
** if (gkoff == 1) then
                somecode = something
        else
                somecode = 0
                endif

ex3
** if (gkoff == 1) then
                somecode = something
        elseif (gkoff == 2) then
                othercode = otherthing
        elseif ...
        ... etc
                endif

and also, how (if at all) is the question mark boolean expression
implementation different in Csound5 than in previous versions?


-David

--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

Michael Rhoades
In reply to this post by jpff
Hi John.

I hope you will excuse my ignorance. Can you explain the difference between
a conditional statement and a conditional expression?

Thanks in advance.

Michael



> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]
> Sent: Tuesday, October 25, 2005 9:22 AM
> To: [hidden email]
> Cc: [hidden email]
> Subject: Re: [Csnd] Question Mark operator
>
> Pleassssse....it is not a conditional statement; it is a conditional
> expression
> ==John ffitch
> --
> Send bugs reports to this list.
> To unsubscribe, send email to [hidden email]
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.859 / Virus Database: 585 - Release Date: 2/14/2005
>

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.859 / Virus Database: 585 - Release Date: 2/14/2005
 

--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

DaveSeidel
In reply to this post by David Akbari
It really just comes down to a matter of style more than anything else.
  In the programing language world, the ternary operator is what's
referred to as "syntactic sugar", meaning it's an inessential but
elegant way to expressing something.  The ternary operator is nice and
compact, so it's suitable when all three expressions are simple ones.
If the conditional expression is more complex, or if the code the is
executed on the branches is more complex (e.g., more than one line of
code), then the ternary expression is not very suitable.

Beyond style and personally taste, consider the readability of your
code, both for yourself coming back to it after time has passed, and for
other people reading your code.  In general, it's best to write code
that clearly expresses your intention, unless you have some reason (such
as a critical optimization, for example in realtime code) to do otherwise.

I'm not aware of any difference between Csound4 and Csound5 regarding
the ternary operator, but I'm sure John or Istvan will correct me of
these is.  Likewise, I don't know if there is any difference in
performance between the different styles of conditional statements.

- Dave


David Akbari wrote:

>
> On Oct 25, 2005, at 9:22 AM, Dave Seidel wrote:
>
>> where the conditional statement is a boolean (i.e., evaluated to true
>> or false), and the other statements are executed based on how the
>> conditional statement is evaluated.
>
>
> I find this very interesting. I am not a programmer so I have not become
> acquainted with this until recently.
>
> What advantages (or disadvantages) does this technique (question mark as
> a conditional boolean expression) offer as opposed to:
>
> ex1
> **    if (gkoff == 1) kgoto somecode
>         kgoto bypasscode
>
> ex2
> **    if (gkoff == 1) then
>         somecode = something
>     else
>         somecode = 0
>         endif
>
> ex3
> **    if (gkoff == 1) then
>         somecode = something
>     elseif (gkoff == 2) then
>         othercode = otherthing
>     elseif ...
>     ... etc
>         endif
>
> and also, how (if at all) is the question mark boolean expression
> implementation different in Csound5 than in previous versions?
>
>
> -David
>

--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

abhunkin
In reply to this post by David Akbari
A bit of background on my considerable use of the conditional expression: my
main platform still being CsoundAV, CsoundAV lacks an if...then! It (and
event) were relatively recent additions (by Matt) to Csound4 that never made
it into AV (or at least hadn't the last time I looked).

Also, the conditional expression nicely suits simple situations; for these,
if...goto is cumbersome and overkill (as others have mentioned). One of my
coding goals is economy (as well as performability on as many varieties and
generations of Csound as possible).

Art Hunkins

----- Original Message -----
From: "David Akbari" <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, October 25, 2005 10:33 AM
Subject: Re: [Csnd] Question Mark operator


>
> On Oct 25, 2005, at 9:22 AM, Dave Seidel wrote:
>
> > where the conditional statement is a boolean (i.e., evaluated to true
> > or false), and the other statements are executed based on how the
> > conditional statement is evaluated.
>
> I find this very interesting. I am not a programmer so I have not
> become acquainted with this until recently.
>
> What advantages (or disadvantages) does this technique (question mark
> as a conditional boolean expression) offer as opposed to:
>
> ex1
> ** if (gkoff == 1) kgoto somecode
> kgoto bypasscode
>
> ex2
> ** if (gkoff == 1) then
> somecode = something
> else
> somecode = 0
> endif
>
> ex3
> ** if (gkoff == 1) then
> somecode = something
> elseif (gkoff == 2) then
> othercode = otherthing
> elseif ...
> ... etc
> endif
>
> and also, how (if at all) is the question mark boolean expression
> implementation different in Csound5 than in previous versions?
>
>
> -David
>
> --
> Send bugs reports to this list.
> To unsubscribe, send email to [hidden email]

--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

Iain Duncan
In reply to this post by David Akbari
You can also include the left hand side in the conditional, ie

k_foo = ( k_something > k_foo ? k_foo : k_something )

The above can be really handy, and done a bunch of times in a row can
make what would be a page of ugly if-thens into 5 lines. As I recall
nesting in the conditional is ok too:

k_foo = ( ( k_something > k_foo ) && ( k_bar > 2  ) ? k_foo + 1 :
k_somthing)

Iain


David Akbari wrote:

> Hi List,
>
> So I was looking at one of Art Hunkins' pieces today and I noticed a
> syntax resembling the following:
>
> krel = (gkoff1 == 1? gkr: 0)
>
> kamp = (gkoff1 == 1? 0: kamp)
>
> Basically what I'm wondering is, what is the function of the question
> mark operator is in this context? Is it some kind of conditional statement?
>
> Any help appreciated!
>
>
> -David
--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

David Akbari
In reply to this post by David Akbari

On Oct 26, 2005, at 6:22 PM, Jim Stevenson wrote:

> Do you know that you are posting in mime attached duplicate html?
> Can you please explain why the mime attached html?
> If so, may I please ask  which mail program is creating these html
> attachments,
> under which OS, and why?

First of to correct your erroneous observation of "duplicate HTML"
would be most prudent. It is actually XML flags for Rich Text format
which is supported in Linux and Mac OSX (not sure about Windows, at
least by default). This of course is obviously noted by the following
quote from your appended statement

--Apple-Mail-1--533209905
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
        charset=US-ASCII

It would seem Apple's Mail program that ships with OSX sends this
format by default. Inspecting further, I have changed the preferences
to send messages as plain text.

Although in the future you could perhaps change your own Mail settings
if you do not wish to view appended Rich Text format as there are
likely others on this list who use Apple's *default ships with OSX*
Mail application.

> I am most concerned about viruses in unintended attachments.

Perhaps you can upgrade your virus scanning software?

> I read email with speech.
> So it is not possible to scroll past the quotes without listening to
> them again,
> to quickly get to the new information.
> The mime attached html is far from speech friendly!

Unfortunately for this suggestion, I choose not to alter my present
style of using quotes in emails as *I* read email with my eyes so I
prefer to put quotes where they are necessary to facilitate others who
read email with eyes (likely > 80%) what points I'm trying to make are
directed specifically at. If this compromises your ability to read my
emails efficiently I apologize in advance.

However, this sounds quite interesting. What is the nature of the
implementation you use to convert text to speech? I'm sure others on
this list would be interested as well.



-David

--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

Iain Duncan
David, historically it has been csound list loose policy to use plain
text only. ( no offense meant, just pointing it out. )

Iain


David Akbari wrote:

>
> On Oct 26, 2005, at 6:22 PM, Jim Stevenson wrote:
>
>> Do you know that you are posting in mime attached duplicate html?
>> Can you please explain why the mime attached html?
>> If so, may I please ask  which mail program is creating these html
>> attachments,
>> under which OS, and why?
>
>
> First of to correct your erroneous observation of "duplicate HTML" would
> be most prudent. It is actually XML flags for Rich Text format which is
> supported in Linux and Mac OSX (not sure about Windows, at least by
> default). This of course is obviously noted by the following quote from
> your appended statement
>
> --Apple-Mail-1--533209905
> Content-Transfer-Encoding: 7bit
> Content-Type: text/enriched;
>     charset=US-ASCII
>
> It would seem Apple's Mail program that ships with OSX sends this format
> by default. Inspecting further, I have changed the preferences to send
> messages as plain text.
>
> Although in the future you could perhaps change your own Mail settings
> if you do not wish to view appended Rich Text format as there are likely
> others on this list who use Apple's *default ships with OSX*
> Mail application.
>
>> I am most concerned about viruses in unintended attachments.
>
>
> Perhaps you can upgrade your virus scanning software?
>
>> I read email with speech.
>> So it is not possible to scroll past the quotes without listening to
>> them again,
>> to quickly get to the new information.
>> The mime attached html is far from speech friendly!
>
>
> Unfortunately for this suggestion, I choose not to alter my present
> style of using quotes in emails as *I* read email with my eyes so I
> prefer to put quotes where they are necessary to facilitate others who
> read email with eyes (likely > 80%) what points I'm trying to make are
> directed specifically at. If this compromises your ability to read my
> emails efficiently I apologize in advance.
>
> However, this sounds quite interesting. What is the nature of the
> implementation you use to convert text to speech? I'm sure others on
> this list would be interested as well.
>
>
>
> -David
>
--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

David Akbari

On Oct 29, 2005, at 1:18 AM, Iain Duncan wrote:

> David, historically it has been csound list loose policy to use plain
> text only. ( no offense meant, just pointing it out. )
>
> Iain

Of course it's nice of you to point this out, but what I still fail to
comprehend completely is the problem with posting plain text plus
appended rich text format.

MS Entourage, Apple's default Mail and other apps like Kontakt in the
KDE package for Linux are all able to display rich text format in
incoming email messages.

Why then it is such a big deal if I send messages to the list that are
*by default* appending the same text with rich text XML flags? Of
course I have since changed this preference to only send plain text but
who is to prevent this from happening in the future? Surely the new
Apple OS's Mail program sets this rich text format default as well.

If this is part of "Csound list policy" then it should definitely be
documented on the Sourceforge Project page as well as safeguards built
into the ezmlm program to prevent the posting of embedded XML flags in
text messages. That will prevent the relay of any message sent with RTF
and HTML flags generated from "incompatible" mail clients.



-David

--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

Björn Lindström
David Akbari <[hidden email]> writes:

> Of course it's nice of you to point this out, but what I still fail to
> comprehend completely is the problem with posting plain text plus
> appended rich text format.
>
> MS Entourage, Apple's default Mail and other apps like Kontakt in the
> KDE package for Linux are all able to display rich text format in
> incoming email messages.

There are still many people using mail programs that do not,
however. Since you only posted text anyway, why not be polite and post
it so that they can read it too?

> If this is part of "Csound list policy" then it should definitely be
> documented on the Sourceforge Project page as well as safeguards
> built into the ezmlm program to prevent the posting of embedded XML
> flags in text messages. That will prevent the relay of any message
> sent with RTF and HTML flags generated from "incompatible" mail
> clients.

I would say there's no need for an explicit policy, since it's already
widespread netiquette to only post plain text messages to mailing
lists.

--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Question Mark operator

Jeremiah Benham
In reply to this post by David Akbari
On Sat, Oct 29, 2005 at 03:28:16AM -0400, David Akbari wrote:

> MS Entourage, Apple's default Mail and other apps like Kontakt in the
> KDE package for Linux are all able to display rich text format in
> incoming email messages.

I actually use Mutt. I can pipe the message to lynx or Mozilla if I wished but I usually
don't bother. When I see anything that is other than plain text I delete it assuming it is
spam. Kmail is a part of kontact. I have tried it and tried very hard to like it. I have
also tried very hard to like other mail clients. I still end up going back to mutt. I
have never found anything better in any system. Once you try it and realize how efficient
it is at managing and reading stuff from mailing lists you won't want to turn back. That
is of course unless you try it with then intention of proving me wrong. This not just
because I am a linux user. It is the same way on Windows and on OsX. I always end up using
mutt because it rocks.

Jeremiah

--
Send bugs reports to this list.
To unsubscribe, send email to [hidden email]