Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > cannot return negative value ?

Reply
Thread Tools

cannot return negative value ?

 
 
Josselin
Guest
Posts: n/a
 
      01-15-2007
I got the following error :

parse error, unexpected tUMINUS_NUM

userCredential.flagged? ? return -1 : return 1

what's wrong ?

I tried also

userCredential.flagged? ? return (-1) : return 1

same problem.....

 
Reply With Quote
 
 
 
 
Farrel Lifson
Guest
Posts: n/a
 
      01-15-2007
On 15/01/07, Josselin <(E-Mail Removed)> wrote:
> I got the following error :
>
> parse error, unexpected tUMINUS_NUM
>
> userCredential.flagged? ? return -1 : return 1
>
> what's wrong ?
>
> I tried also
>
> userCredential.flagged? ? return (-1) : return 1
>
> same problem.....


This seems to work:

return userCredentials.flagged? ? -1 : 1

Farrel

 
Reply With Quote
 
 
 
 
Peter Szinek
Guest
Posts: n/a
 
      01-15-2007
Josselin wrote:
> I got the following error :
>
> parse error, unexpected tUMINUS_NUM
>
> userCredential.flagged? ? return -1 : return 1

You mean

return userCredential.flagged? -1 : 1

?

I am not sure in Ruby, but if it's the same than in C or anywhere else,
the ternary operator evaluates to a value, and you can not really
execute things like this inside...

Cheers,
Peter

__
http://www.rubyrailways,com


 
Reply With Quote
 
Josselin
Guest
Posts: n/a
 
      01-15-2007
On 2007-01-15 12:43:21 +0100, Peter Szinek <(E-Mail Removed)> said:

> Josselin wrote:
>> I got the following error :
>>
>> parse error, unexpected tUMINUS_NUM
>>
>> userCredential.flagged? ? return -1 : return 1

> You mean
>
> return userCredential.flagged? -1 : 1
>
> ?
>
> I am not sure in Ruby, but if it's the same than in C or anywhere else,
> the ternary operator evaluates to a value, and you can not really
> execute things like this inside...
>
> Cheers,
> Peter
>
> __
> http://www.rubyrailways,com


thanks a lot first time I was using this kind of return... )

 
Reply With Quote
 
Josselin
Guest
Posts: n/a
 
      01-15-2007
On 2007-01-15 12:41:09 +0100, "Farrel Lifson" <(E-Mail Removed)> said:

> On 15/01/07, Josselin <(E-Mail Removed)> wrote:
>> I got the following error :
>>
>> parse error, unexpected tUMINUS_NUM
>>
>> userCredential.flagged? ? return -1 : return 1
>>
>> what's wrong ?
>>
>> I tried also
>>
>> userCredential.flagged? ? return (-1) : return 1
>>
>> same problem.....

>
> This seems to work:
>
> return userCredentials.flagged? ? -1 : 1
>
> Farrel


hanks a lot first time I was using this kind of return... )


 
Reply With Quote
 
Farrel Lifson
Guest
Posts: n/a
 
      01-15-2007
On 15/01/07, Peter Szinek <(E-Mail Removed)> wrote:
> Josselin wrote:
> > I got the following error :
> >
> > parse error, unexpected tUMINUS_NUM
> >
> > userCredential.flagged? ? return -1 : return 1

> You mean
>
> return userCredential.flagged? -1 : 1
>
> ?
>
> I am not sure in Ruby, but if it's the same than in C or anywhere else,
> the ternary operator evaluates to a value, and you can not really
> execute things like this inside...
>
> Cheers,
> Peter


This seems to work though

userCredentials.flagged? ? (return -1) : (return 1)

Farrel

 
Reply With Quote
 
Bertram Scharpf
Guest
Posts: n/a
 
      01-15-2007
Hi,

Am Montag, 15. Jan 2007, 20:30:08 +0900 schrieb Josselin:
> I got the following error :
>
> parse error, unexpected tUMINUS_NUM
>
> userCredential.flagged? ? return -1 : return 1
>
> what's wrong ?


when saying

userCredential.flagged? ? (return -1) : (return 1)

or even

userCredential.flagged? ? begin return -1 end : begin return 1 end

you will probably see that the return statement is definitely in the
wrong place.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

 
Reply With Quote
 
Nobuyoshi Nakada
Guest
Posts: n/a
 
      01-15-2007
Hi,

At Mon, 15 Jan 2007 20:30:08 +0900,
Josselin wrote in [ruby-talk:234078]:
> I got the following error :
>
> parse error, unexpected tUMINUS_NUM
>
> userCredential.flagged? ? return -1 : return 1
>
> what's wrong ?


Because `return' is a statement. In Ruby, a "statement" is
defined as an expression which has lower precedence and can't
appear directly in another expression.

--
Nobu Nakada

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding (and getting rid) of optparse.py:668: FutureWarning:%u/%o/%x/%X of negative int will return a hofer Python 2 09-26-2008 05:41 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
Negative setup and Negative hold prem_eda VHDL 5 10-11-2004 12:14 PM
getting return value from function without return statement. Seong-Kook Shin C Programming 1 06-18-2004 08:19 AM
Return a return value from Perl to Javascript PvdK Perl 0 07-24-2003 09:20 AM



Advertisments