Include? needs parentheses?

I find this kind of odd.

$ ruby -w
puts([1,2,3].include? 1)
-:1: warning: parenthesize argument(s) for future version
true

Surely there’s no ambiguity in that expression. What principle is at work
here?

Sorry if this is similar to other cases already discussed. I was paying
attention, but those cases seemed more ambiguous, hence the warning.

Gavin

“Gavin Sinclair” gsinclair@soyabean.com.au schrieb im Newsbeitrag
news:50505.129.78.228.114.1081916392.squirrel@webmail.imagineis.com

I find this kind of odd.

$ ruby -w
puts([1,2,3].include? 1)
-:1: warning: parenthesize argument(s) for future version
true

Surely there’s no ambiguity in that expression. What principle is at
work
here?

Sorry if this is similar to other cases already discussed. I was paying
attention, but those cases seemed more ambiguous, hence the warning.

I can only guess: maybe it’s because the line “puts([1,2,3].include? 1,2)”
would be amiguous?

robert

Hi,

At Wed, 14 Apr 2004 18:39:23 +0900,
Robert Klemme wrote in [ruby-talk:97118]:

Sorry if this is similar to other cases already discussed. I was paying
attention, but those cases seemed more ambiguous, hence the warning.

I can only guess: maybe it’s because the line “puts([1,2,3].include? 1,2)”
would be amiguous?

You’re correct, and Gavin may be also.

Index: parse.y

···

===================================================================
RCS file: /cvs/ruby/src/ruby/parse.y,v
retrieving revision 1.319
diff -U2 -p -d -r1.319 parse.y
— parse.y 5 Apr 2004 13:16:40 -0000 1.319
+++ parse.y 14 Apr 2004 11:17:50 -0000
@@ -119,4 +119,5 @@ static void void_expr0();
static void void_stmts();
static NODE *remove_begin();
+static void warn_to_parenthesize();
#define value_expr(node) value_expr0((node) = remove_begin(node))
#define void_expr(node) void_expr0((node) = remove_begin(node))
@@ -1217,5 +1218,5 @@ aref_args : none
> command opt_nl
{

  •           rb_warn("parenthesize argument(s) for future version");
    
  •   	warn_to_parenthesize($1);
      	$$ = NEW_LIST($1);
          }
    

@@ -1250,5 +1251,5 @@ paren_args : ‘(’ none ‘)’
> ‘(’ block_call rparen
{

  •           rb_warn("parenthesize argument for future version");
    
  •           warn_to_parenthesize($2);
      	$$ = NEW_LIST($2);
          }
    

@@ -1266,5 +1267,5 @@ opt_paren_args : none
call_args : command
{

  •           rb_warn("parenthesize argument(s) for future version");
    
  •           warn_to_parenthesize($1);
      	$$ = NEW_LIST($1);
          }
    

@@ -4512,4 +4513,17 @@ fixpos(node, orig)
node->nd_file = orig->nd_file;
nd_set_line(node, nd_line(orig));
+}
+
+static void
+warn_to_parenthesize(node)

  • NODE *node;
    +{
  • switch (nd_type(node)) {
  •  case NODE_CALL:
    
  •  case NODE_FCALL:
    
  • if (!node->nd_args) return;
  • if (node->nd_args->nd_alen == 1) return;
  • }
  • rb_warn(“parenthesize argument(s) for future version”);
    }


Nobu Nakada

Hi,

···

In message “Re: include? needs parentheses?” on 04/04/14, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

I can only guess: maybe it’s because the line “puts([1,2,3].include? 1,2)”
would be amiguous?

You’re correct, and Gavin may be also.

The basic rule was “when you use return values from method calls, use
parentheses”. So I believe I didn’t make mistake for this case. But
your expectation might be worth consideration.

						matz.

The basic rule was “when you use return values from method calls, use
parentheses”. So I believe I didn’t make mistake for this case. But
your expectation might be worth consideration.

matz.

Is the “no space before parenthesis” warning something that might be
unnecessary in a future release?

thanks!

Hi,

At Thu, 15 Apr 2004 02:34:49 +0900,
Yukihiro Matsumoto wrote in [ruby-talk:97164]:

I can only guess: maybe it’s because the line “puts([1,2,3].include? 1,2)”
would be amiguous?

You’re correct, and Gavin may be also.

The basic rule was “when you use return values from method calls, use
parentheses”. So I believe I didn’t make mistake for this case. But
your expectation might be worth consideration.

Understood. Then, the messages shouldn’t be so?

···


Nobu Nakada

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/68886
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/64933
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/84104

···

On Wednesday 14 April 2004 2:44 pm, Its Me wrote:

Is the “no space before parenthesis” warning something that might be
unnecessary in a future release?

thanks!

Hello,

···

nobu.nokada@softhome.net wrote:

Hi,

At Thu, 15 Apr 2004 02:34:49 +0900,
Yukihiro Matsumoto wrote in [ruby-talk:97164]:

I can only guess: maybe it’s because the line “puts([1,2,3].include? 1,2)”
would be amiguous?

You’re correct, and Gavin may be also.

The basic rule was “when you use return values from method calls, use
parentheses”. So I believe I didn’t make mistake for this case. But
your expectation might be worth consideration.

Understood. Then, the messages shouldn’t be so?

yes, that’d help the messages to be much less “try and fix” if people
understand them less intuitively and more objectively.

emmanuel

Hi,

···

In message “Re: include? needs parentheses?” on 04/04/15, nobu.nokada@softhome.net nobu.nokada@softhome.net writes:

The basic rule was “when you use return values from method calls, use
parentheses”. So I believe I didn’t make mistake for this case. But
your expectation might be worth consideration.

Understood. Then, the messages shouldn’t be so?

What would be a suitable message? Or is omitting parentheses better
than tweaking message?

						matz.