Ruby-dev summary 21637-21729

Hello,

I present you a summary of the ruby-dev mailing list.

[ruby-dev:21639] load() blocks thread scheduling
Tietew posted the following scripts which didn’t timeout and didn’t
accept Ctrl+C.

-- main.rb --
require 'timeout'
timeout(60) { load 'block.rb' }

--- block.rb
loop { }

He also posted a patch to change the thread. Matz wrote that
it would cause unexpected troubles if we didn’t block other
thread while loading a script.

[ruby-dev:21641] SOAP::StreamError: Illegal media type
SOAP4R’s test suite failed since it required pre-installed SOAP4R
library. Matz suggested that the test suite in ruby should use
not pre-installed libraries but use archived new libraries from
the archive.

[ruby-dev:21678] Problems of testing test/drb on Windows
U. Nakamura showed two opinions about test/drb on Windows as follows.
(a) test/drb/test_drbunix.rb failed if it was executed via
test/runner.rb, since Windows didn’t have Socket::UNIX*.
He thought that such error had better occur when loading
’drb/unix’.
(b) The result of test/drb/test_acl.rb was ‘E’, since the
ruby was compiled without AF_INET6 and IPAddr#ipv6?
caused NameError. He proposed some solutions to avoid
NameError.

[ruby-dev:21679] Proposal: string literal concatenation
Mput proposed a specification which enables us to concatenate
strings using a new line like the following script.

s = "foo1" "bar1"
    "foo2" "bar2"

Matz answered that he will discard string literal concatenation.

[ruby-dev:21682] ruby-tk hangs when exception is raised

Akira Yamada received a bug report as a package maintainer of
Debian. The following Ruby/TK script caused a problem that
Ctrl+C was not available. This problem have not been solved yet.

require 'tk'
r = TkRoot.new
b = TkButton.new(r) { text "break me" }
b.command proc {
  raise "error!"
}
b.pack
Tk.mainloop
···


Takaaki Tateishi ttate@ttsky.net

So what will the result of the above two lines of code be?

Paul

···

On Fri, Oct 31, 2003 at 07:01:28AM +0900, Takaaki Tateishi wrote:

[ruby-dev:21679] Proposal: string literal concatenation
Mput proposed a specification which enables us to concatenate
strings using a new line like the following script.

s = "foo1" "bar1"
    "foo2" "bar2"

Matz answered that he will discard string literal concatenation.

Hi,

···

In message “Re: ruby-dev summary 21637-21729” on 03/11/06, Paul Brannan pbrannan@atdesk.com writes:

On Fri, Oct 31, 2003 at 07:01:28AM +0900, Takaaki Tateishi wrote:

[ruby-dev:21679] Proposal: string literal concatenation
Mput proposed a specification which enables us to concatenate
strings using a new line like the following script.

s = "foo1" "bar1"
    "foo2" "bar2"

Matz answered that he will discard string literal concatenation.

So what will the result of the above two lines of code be?

Plain syntax error in 1.9.x.

						matz.

Is the syntax error because of the first line or because of the second?
I ask because I do this a lot in my code:

s = "this is a string "
"that I have chosen to break "
"into multiple lines

I would be happy to switch to using heredocs if there were an easy way
to indent heredocs.

Paul

···

On Thu, Nov 06, 2003 at 11:17:59PM +0900, Yukihiro Matsumoto wrote:

In message “Re: ruby-dev summary 21637-21729” > on 03/11/06, Paul Brannan pbrannan@atdesk.com writes:

So what will the result of the above two lines of code be?

Plain syntax error in 1.9.x.

Hi,

Is the syntax error because of the first line or because of the second?

Both. Sequence of strings will no longer be valid.

I ask because I do this a lot in my code:

s = "this is a string "
"that I have chosen to break "
“into multiple lines”

How about

s = "this is a string " +
"that I have chosen to break " +
“into multiple lines”
?

						matz.
···

In message “Re: ruby-dev summary 21637-21729” on 03/11/06, Paul Brannan pbrannan@atdesk.com writes:

So what will the result of the above two lines of code be?

Plain syntax error in 1.9.x.

Is the syntax error because of the first line or because of the second?
I ask because I do this a lot in my code:

s = "this is a string "
"that I have chosen to break "
"into multiple lines

I would be happy to switch to using heredocs if there were an easy way
to indent heredocs.

require ‘extensions/all’ # http://extensions.rubyforge.org

s = %{
> this is a string
> that I have chosen to break
> into multiple lines
}.trim(‘|’)

or

s = %{
this is a string
that I have chosen to break
into multiple lines
}.trim.tabto(0)

That would produce a three-line string, unlike your example, but you
mention indenting heredocs, so there you go.

Cheers,
Gavin

···

On Friday, November 7, 2003, 1:27:45 AM, Paul wrote:

On Thu, Nov 06, 2003 at 11:17:59PM +0900, Yukihiro Matsumoto wrote:

In message “Re: ruby-dev summary 21637-21729” >> on 03/11/06, Paul Brannan pbrannan@atdesk.com writes:

This works, but the concatenation is done at run-time instead of at
compile-time.

Paul

···

On Fri, Nov 07, 2003 at 12:36:23AM +0900, Yukihiro Matsumoto wrote:

In message “Re: ruby-dev summary 21637-21729” > on 03/11/06, Paul Brannan pbrannan@atdesk.com writes:

s = "this is a string "
"that I have chosen to break "
“into multiple lines”

How about

s = "this is a string " +
"that I have chosen to break " +
“into multiple lines”

My 1 cent: I really wish “” \ style concatenation wouldn’t go away.

Sean O'Dell
···

On Thursday 06 November 2003 07:36 am, Yukihiro Matsumoto wrote:

Hi,

In message “Re: ruby-dev summary 21637-21729” > > on 03/11/06, Paul Brannan pbrannan@atdesk.com writes:

Is the syntax error because of the first line or because of the second?

Both. Sequence of strings will no longer be valid.

I ask because I do this a lot in my code:

s = "this is a string "
"that I have chosen to break "
“into multiple lines”

How about

s = "this is a string " +
"that I have chosen to break " +
“into multiple lines”
?

Hi,

Yukihiro Matsumoto wrote:

Hi,

Is the syntax error because of the first line or because of the second?

Both. Sequence of strings will no longer be valid.

I ask because I do this a lot in my code:

s = "this is a string "
"that I have chosen to break "
“into multiple lines”

How about

s = "this is a string " +
"that I have chosen to break " +
“into multiple lines”

I would prefer this:

s = "this is a string "

  • "that I have chosen to break "
  • “into multiple lines”

I think it’s always better to avoid operators in the end of lines (code
is therefore more readeable).

Same think for this:

if ( expr1…
and expr2…
and expr3… )

# do something

end

But AFAIK && unfortunately, Ruby does not handle this kind of syntax yet.

Matz, what do you think about this?

Thanks,

···

In message “Re: ruby-dev summary 21637-21729” > on 03/11/06, Paul Brannan pbrannan@atdesk.com writes:


Laurent

On Fri, Nov 07, 2003 at 07:57:32AM +0900, Paul Brannan quipped:

How about

s = "this is a string " +
"that I have chosen to break " +
“into multiple lines”

This works, but the concatenation is done at run-time instead of at
compile-time.

Or so you assume. I don’t know how Matz will handle this, but there’s
no reason concatenation of string constants could not be done at
compile time.

Hi,

···

At Fri, 7 Nov 2003 07:57:32 +0900, Paul Brannan wrote:

On Fri, Nov 07, 2003 at 12:36:23AM +0900, Yukihiro Matsumoto wrote:

In message “Re: ruby-dev summary 21637-21729” > > on 03/11/06, Paul Brannan pbrannan@atdesk.com writes:

s = "this is a string "
"that I have chosen to break "
“into multiple lines”

How about

s = "this is a string " +
"that I have chosen to break " +
“into multiple lines”

This works, but the concatenation is done at run-time instead of at
compile-time.

In 1.8, this is concatenated at compile-time. :slight_smile:

s = “this is a string #{ # And you can write
“”}that I have chosen to break #{ # comments!
“”}into multiple lines”


Nobu Nakada

Hi,

···

In message “Re: ruby-dev summary 21637-21729” on 03/11/07, Paul Brannan pbrannan@atdesk.com writes:

This works, but the concatenation is done at run-time instead of at
compile-time.

Don’t worry. It’s done at run-time anyway.

						matz.

Hi,

···

In message “Re: ruby-dev summary 21637-21729” on 03/11/07, “Sean O’Dell” sean@celsoft.com writes:

My 1 cent: I really wish “” \ style concatenation wouldn’t go away.

Why?

						matz.

Because of Ruby’s line-based syntax, Ruby guesses that if you have hit
the end of the line and the line as a whole is valid, then you have
finished that statement. This is essentially a limitation of the parser.
There are two ways around this - require statements to end with a
special character (eg a semicolon) so that if we get to the end of the
line and haven’t found that character yet we know the statement isn’t
finished, or implement look-ahead in the parser to take a look at the
next line and see if it, when combined with the current line, is a valid
statement as a whole. This is a lot more difficult; it involves
look-ahead and creates a whole new family of ambiguities; e.g. what do
you do if the next line creates a valid statement when combined with
this line, and also the two lines are valid statements by themselves? So
if the alternative is to require every statement to end in a semicolon
(noooo!) which takes a significant chunk out of the beauty of the
language, I must say that I prefer the way it is done now - and the same
applies to most of Matz’s decisions, which is why I love this language.

Tim Bates

···

On Fri, Nov 07, 2003 at 06:04:47PM +0900, Laurent Sansonetti wrote:

I think it’s always better to avoid operators in the end of lines (code
is therefore more readeable).

But AFAIK && unfortunately, Ruby does not handle this kind of syntax yet.


tim@bates.id.au

There’s always trade-off. Newline sensitive syntax do not allow
line concatenation by operator at the beginning of a line, e.g. how
can we distinguish

s = "this is a string "
+ "that I have chosen to break "
+ “into multiple lines”

which is a single assignment statement, from

s = "this is a string "

  • "that I have chosen to break "
  • “into multiple lines”

an assignment followed by two unary plus expression?

						matz.
···

In message “Re: ruby-dev summary 21637-21729” on 03/11/07, Laurent Sansonetti laurent@datarescue.be writes:

I would prefer this:

s = "this is a string "

  • "that I have chosen to break "
  • “into multiple lines”

I think it’s always better to avoid operators in the end of lines (code
is therefore more readeable).

Same think for this:

if ( expr1…
and expr2…
and expr3… )

do something

end

But AFAIK && unfortunately, Ruby does not handle this kind of syntax yet.

Matz, what do you think about this?

You can redefine String#+, so no such optimization must be made at
compile time.

···

Robert Church (rc@pgdn.org) wrote:

On Fri, Nov 07, 2003 at 07:57:32AM +0900, Paul Brannan quipped:

How about

s = "this is a string " +
"that I have chosen to break " +
“into multiple lines”

This works, but the concatenation is done at run-time instead of at
compile-time.

Or so you assume. I don’t know how Matz will handle this, but there’s
no reason concatenation of string constants could not be done at
compile time.


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Very cool! It doesn’t need the “”, though, does it?

irb(main):001:0> “foo#{
irb(main):002:0” }bar"
=> “foobar”

···

nobu.nokada@softhome.net wrote:

In 1.8, this is concatenated at compile-time. :slight_smile:

s = “this is a string #{ # And you can write
“”}that I have chosen to break #{ # comments!
“”}into multiple lines”

Yukihiro Matsumoto wrote:

Matz, what do you think about this?

There’s always trade-off. Newline sensitive syntax do not allow
line concatenation by operator at the beginning of a line, e.g. how
can we distinguish

s = "this is a string "
+ "that I have chosen to break "
+ “into multiple lines”

which is a single assignment statement, from

s = "this is a string "

  • "that I have chosen to break "
  • “into multiple lines”

an assignment followed by two unary plus expression?

Because the String class does not provide the `+@’ method?

But as Tim pointed out, since Ruby seems to be parsed line by line, it
can be really hard to implement this. And of course, it can break the
current syntax (if we replace strings with integers, how the parser
should react since integers have `+@’ ?)

So it’s surely better to keep the current syntax.

···


Laurent

Well, isn’t “” \ load/compile-time concatenation and “” + run-time
concatenation? Right now, there’s code that uses “” \ so my first reason is
compatibility. Secondly, when (if?) Rite pre-compiles into bytecode, “” \
probably should be interpreted to mean “just slap them together” while “” +
should be “concatenate using the current implementation for the + operator”
(meaning it’s overridable, whereas the former is not).

Sean O'Dell
···

On Friday 07 November 2003 12:11 am, Yukihiro Matsumoto wrote:

Hi,

In message “Re: ruby-dev summary 21637-21729” > > on 03/11/07, “Sean O’Dell” sean@celsoft.com writes:

My 1 cent: I really wish “” \ style concatenation wouldn’t go away.

Why?

Hi,

In 1.8, this is concatenated at compile-time. :slight_smile:

s = “this is a string #{ # And you can write
“”}that I have chosen to break #{ # comments!
“”}into multiple lines”

Very cool! It doesn’t need the “”, though, does it?

irb(main):001:0> “foo#{
irb(main):002:0” }bar"
=> “foobar”

It needs for compile-time concatenation, because nil.to_s might
be replaced.

$ ruby -rNodeDump -e ‘"foo#{’ -e ‘}bar"’
NodeDump V0.9

NODE_NEWLINE: [-e:1]
NODE_DSTR: “foo”
NODE_EVSTR:
NODE_STR: “bar”

$ ruby -rNodeDump -e ‘"foo#{’ -e ‘“”}bar"’
NodeDump V0.9

NODE_NEWLINE: [-e:1]
NODE_STR: “foobar”

This optimization is limited to the case #{} ends with a
literal string (and preceding literals without any side
effects)

···

At Fri, 7 Nov 2003 10:42:51 +0900, Joel VanderWerf wrote:


Nobu Nakada