it has one simple good reason for use: it allows good form indentation of code
while conserving storage. all those extra spaces add up. (for example say, in
HTML gerneration).
···
On Tuesday 14 January 2003 09:08 pm, Yukihiro Matsumoto wrote:
Hi,
In message “Re: ruby-dev summary 19198-19345” > > on 03/01/15, Paul Brannan pbrannan@atdesk.com writes:
In message “Re: ruby-dev summary 19198-19345” > > on 03/01/15, Matt Armstrong matt@lickey.com writes:
I do not like this simply because it introduces a problem of tabs -vs-
spaces.
I’m not sure Perl5 RFC162 is well though or not. But Matt’s comment
is exactly what I thought when I read that. Nobu’s idea is much
better, although I’m not convinced yet.
I think I might start using that more often. It’s nice, and it’s
easier to chain. e.g. with an appropriate String#tabto(n) method (a
la StringFormattingFunctions on the Wiki), you can resolve the
indentation like so:
s = %Q{
hi
how are you?
}.tabto(0)
Which gives “\nhi\n how are you?\n”. That code would highlight fine,
whereas using here-docs can sometimes be troublesome.
One difference between this and a here-doc is the initial newline,
which is a shame.
One more difference. tabto strips after string interpolcation,
whereas here-doc does before it.
hi = " hi"
s0 = %q{
#{hi}
how are you?
}.tabto(0)
=> “\nhi\nhow are you?\n”
s1 = <<|EOS
>#{hi}
> how are you?
EOS
=> “\n hi\n how are you?\n”
···
At Thu, 16 Jan 2003 14:08:58 +0900, Gavin Sinclair wrote:
Note also that if the text you are printing includes a } character, this
won’t work. You’ll have to use %Q instead or %Q%some string% (or some
variant) instead,
Well, only of the {}'s are unbalanced. For Example …
$ irb --simple-prompt
s = %Q{ this is { just a } test }
=> " this is { just a } test "
Come to think of it, this feature is really useful. I’d like to see it
implemented.
Cheers,
Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137
On Wed, 15 Jan 2003, Gavin Sinclair wrote:
On Wednesday, January 15, 2003, 12:36:43 PM, Daniel wrote:
On Wed, 15 Jan 2003, Gavin Sinclair wrote:
p <<-|EOS
> foo
> bar
EOS
# => " foo\n bar\n".
[snip]
Anyway. I want this functionality so bad I can taste it.
Gavin, maybe I’m missing something but I’m not sure I understand the
usefulness of this. The only example I can think of where I might like
this is when I have lots of indentation:
def function
if (condition)
p <<-|EOH
>Blah blah blah
>Blah blah blah
EOH
end
end
Well, that’s a good example! Here-documents can come up anywhere.
Is this the purpose of this feature? Or am I missing something?
Even with little/no indentation, the proposed feature would be useful
to me. I usually indent code in posts, but here will put is as if it
were in a Ruby program.
USAGE =<<-|EOU
Usage: froboz [-q] [-o DIR] files…
-q: quiet operation
-o: output to DIR
(c) 2003 Widgets Co
EOU
--------- vs ---------
USAGE =<<-EOU
Usage: froboz [-q] [-o DIR] files…
-q: quiet operation
-o: output to DIR
(c) 2003 Widgets Co
EOU
Being able to indent you text gives the same benefit as all
indentation: highlights code structure.
I do not like this simply because it introduces a problem of tabs -vs-
spaces.
I’m not sure Perl5 RFC162 is well though or not. But Matt’s comment
is exactly what I thought when I read that. Nobu’s idea is much
better, although I’m not convinced yet.
Why are you not convinced, Matz? YAGNI? Or implementation difficulty?
I think it’s a very good solution to a very real problem. The problem
is only aesthetic, but no less real for that.
If I were implementing it, I’d limit the “special character” to ‘|’,
unless someone demonstrated a reason why this shouldn’t be the case.
What I do not like about Nobu’s idea is that the here document may be
harder to edit, since every line must have the leading | character.
The extra editing pain may outweigh any benefit.
Editing this in Vim would be easier than slipping on a banana peel.
Surely this must also be the case with Emacs?
And the worst that can be said about the feature is this: if the
drawback (editing) outweighs the advantage (which is subjective, but
to some people, great), then you don’t have to use it.
Gavin
···
On Wednesday, January 15, 2003, 3:17:11 PM, Matt wrote:
In message “Re: ruby-dev summary 19198-19345” >> on 03/01/15, Matt Armstrong matt@lickey.com writes:
In message “Re: ruby-dev summary 19198-19345” on 03/01/15, Gavin Sinclair gsinclair@soyabean.com.au writes:
Why are you not convinced, Matz? YAGNI? Or implementation difficulty?
I think it’s a very good solution to a very real problem. The problem
is only aesthetic, but no less real for that.
Nobu already made a patch to implement it. I feel like it can make
programs more cryptic. “<<-|FOO”?? WHAT DOES IT MEAN?
Other heredoc notations follow shell convention, so that there’s
nothing new in syntax. One of Ruby’s secret is to be slow to merge
new syntax.
Why are you not convinced, Matz? YAGNI? Or implementation difficulty?
I think it’s a very good solution to a very real problem. The problem
is only aesthetic, but no less real for that.
Nobu already made a patch to implement it. I feel like it can make
programs more cryptic. “<<-|FOO”?? WHAT DOES IT MEAN?
Other heredoc notations follow shell convention, so that there’s
nothing new in syntax. One of Ruby’s secret is to be slow to merge
new syntax.
matz.
It’s a great secret. Keep the syntax simple, the core classes clean, and
let library developers fill in minor details like this.
This works well enough for me, and I don’t have to type | characters.
(But it doesn’t solve the hard-tabs-versus-spaces problem; I just don’t
use hard tabs.)
class String
# Tabs left or right by n chars, using spaces
def tab(n)
if n >= 0
gsub(/^/, ' ' * n)
else
gsub(/^ {0,#{-n}}/, "")
end
end
# Preserves relative tabbing.
# The first non-empty line ends up with n spaces before nonspace.
def tabto(n)
if self =~ /^( *)\S/
tab(n - $1.length)
else
self
end
end
end
str = %{\
header
subhead
text
}.tabto(2)
puts str
===output===
header
subhead
text
···
In message “Re: ruby-dev summary 19198-19345” > on 03/01/15, Gavin Sinclair gsinclair@soyabean.com.au writes:
When I first saw it mentioned in a ruby-dev summary several weeks ago,
I knew instantly what it meant. You see the | representing a left
margin, and it’s obvious.
The secret is already violated with regard to <<-EOF (i.e. allowing an
indented end marker). Well, I just tried it in bash, and it didn’t
allow an indented EOF. Maybe other sheels do.
Gavin
···
On Wednesday, January 15, 2003, 4:39:36 PM, Yukihiro wrote:
Hi,
In message “Re: ruby-dev summary 19198-19345” > on 03/01/15, Gavin Sinclair gsinclair@soyabean.com.au writes:
Why are you not convinced, Matz? YAGNI? Or implementation difficulty?
I think it’s a very good solution to a very real problem. The problem
is only aesthetic, but no less real for that.
Nobu already made a patch to implement it. I feel like it can make
programs more cryptic. “<<-|FOO”?? WHAT DOES IT MEAN?
Other heredoc notations follow shell convention, so that there’s
nothing new in syntax. One of Ruby’s secret is to be slow to merge
new syntax.
Why are you not convinced, Matz? YAGNI? Or implementation difficulty?
I think it’s a very good solution to a very real problem. The problem
is only aesthetic, but no less real for that.
Nobu already made a patch to implement it. I feel like it can make
programs more cryptic. “<<-|FOO”?? WHAT DOES IT MEAN?
If you’re not used to it, even <<-FOO is cryptic.
Personally, I’d dispense with the hyphen in this
case… only one punctuation mark is needed
in order to remove ambiguity: <<|FOO
Other heredoc notations follow shell convention, so that there’s
nothing new in syntax. One of Ruby’s secret is to be slow to merge
new syntax.
We all trust your judgment, as you have treated us
very well in the past. A (mineral) ruby is not
produced quickly, nor is a (software) Ruby.
Hal
···
----- Original Message -----
From: “Yukihiro Matsumoto” matz@ruby-lang.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, January 14, 2003 11:39 PM
Subject: Re: ruby-dev summary 19198-19345
In message “Re: ruby-dev summary 19198-19345” > on 03/01/15, Gavin Sinclair gsinclair@soyabean.com.au writes:
When I first saw it mentioned in a ruby-dev summary several weeks ago,
I knew instantly what it meant. You see the | representing a left
margin, and it’s obvious.
I don’t forget there’s one feel like that. Thank you.
The secret is already violated with regard to <<-EOF (i.e. allowing an
indented end marker). Well, I just tried it in bash, and it didn’t
allow an indented EOF. Maybe other sheels do.
sh has “<<-EOF”.
matz.
···
In message “Re: ruby-dev summary 19198-19345” on 03/01/15, Gavin Sinclair gsinclair@soyabean.com.au writes:
Nobu already made a patch to implement it. I feel like it can make
programs more cryptic. “<<-|FOO”?? WHAT DOES IT MEAN?
I just though, why not “<<|FOO”. In other words, the ‘-’ in there
doesn’t serve much purpose.
s = <<|FOO
>this
> is
> my
> text
FOO
To me, the ‘-’ means the same that it always does: it allows the
end-of-document marker to be indented. I don’t see why that should
change. In other words, the example given above is an incomplete
here-document, based on the assumption in the following section.
What happens if a here-doc is specified to have the left margin (‘|’)
but for one or more lines it is not used, as in:
s = <<-|EOS
> One
> Two
Three
> Four
EOS
puts s
I think the correct output is:
One
Two
Three
Four
(end of output)
In that case, it’s pretty easy to see what becomes of the quoted
example at the top. The fifth line is " FOO".
At the end of the day, the “-” and (proposed) “|” features of Ruby
here-documents are independent of each other.
Gavin
···
On Thursday, January 16, 2003, 2:39:54 AM, Matt wrote: