%L, %l revisited

this is a general request for opinion/support. i, for one, would very much
like to have a margin-controlled string syntax structure. i believe this
would add another excellent and superior feature to Ruby. i think the final
and best conclusion for such was %l and %L given by Nobu Nakada:

bar = “bar”

dq = %L| foo
> #{bar}

sq = %l| foo
> bar

by using % notation, patterned after %q and %Q, other margin deliminators can
be used, for example:

dq = %L: foo
: #{bar}

from a general script programmer’s standpoint (mine) this is one of those
exhalted features that one often thinks “would’nt it be nice if…” but as
far as i know, no language has ever made a string syntax like this
available…hopefully, until now.

···


tom sawyer, aka transami
transami@transami.net

Hi,

···

At Fri, 31 Jan 2003 19:37:52 +0900, Tom Sawyer wrote:

from a general script programmer’s standpoint (mine) this is one of those
exhalted features that one often thinks “would’nt it be nice if…” but as
far as i know, no language has ever made a string syntax like this
available…hopefully, until now.

Probably, because nothing can appear after this literal in the
same line, I guess. Now I doubt its usefulness.


Nobu Nakada

its utitlity comes from one simple fact: efficiency. when one uses:

x = <<-EOS
            this is
            come
            text
EOS

or

x = %Q{
            this is
            come
            text
}

you’ve just thrown in an extra 24+ bytes of wasted empty space. and accounts
for the fact that the use of String#tabto has been publicized:

x = %Q{
            this is
            come
            text
}.tabto(0)

which is a waste of processing and isn’t very elegent.

···

On Monday 03 February 2003 01:26 am, nobu.nokada@softhome.net wrote:

Hi,

At Fri, 31 Jan 2003 19:37:52 +0900, > > Tom Sawyer wrote:

from a general script programmer’s standpoint (mine) this is one of those
exhalted features that one often thinks “would’nt it be nice if…” but
as far as i know, no language has ever made a string syntax like this
available…hopefully, until now.

Probably, because nothing can appear after this literal in the
same line, I guess. Now I doubt its usefulness.


tom sawyer, aka transami
transami@transami.net

This is misguided, IMNO (N = Naive). 24 bytes of wasted space - who
cares? tabto(0) is a waste of processing - who cares? Neither of
them is in a tight loop.

The utility or otherwise of any string-formatting feature comes down
to its elegance, to make code more pleasant to read and write.

Gavin

···

On Monday, February 3, 2003, 9:48:04 PM, Tom wrote:

its utitlity comes from one simple fact: efficiency. when one uses:

    x = <<-EOS
            this is
            come
            text
    EOS

or

    x = %Q{
            this is
            come
            text
    }

you’ve just thrown in an extra 24+ bytes of wasted empty space. and accounts
for the fact that the use of String#tabto has been publicized:

    x = %Q{
            this is
            come
            text
    }.tabto(0)

which is a waste of processing and isn’t very elegent.

Hi,

from a general script programmer’s standpoint (mine) this is one of those
exhalted features that one often thinks “would’nt it be nice if…” but
as far as i know, no language has ever made a string syntax like this
available…hopefully, until now.

Probably, because nothing can appear after this literal in the
same line, I guess. Now I doubt its usefulness.

its utitlity comes from one simple fact: efficiency. when one uses:

I meant:

puts <<-EOS, "and more"
            this is
            come
            text
EOS

or

puts %Q{
            this is
            come
            text
}, "and more"

are possible, but

puts %l|this is
       >come
       >text
, "and more"

is impossible, that is this literal can appear only at the end
of sentense. Its usage would be very restricted.

···

At Mon, 3 Feb 2003 19:48:04 +0900, Tom Sawyer wrote:


Nobu Nakada

This is misguided, IMNO (N = Naive). 24 bytes of wasted space - who
cares? tabto(0) is a waste of processing - who cares? Neither of
them is in a tight loop.

when you write a cgi app and you’re displaying some record detail that repeats
a string loop potentially hundreds of times then these bytes add up. the poor
soul on a dialup connection cares. and besides, nothing personal, but that
opinion is what leads to much of the bloated/sluggish software we have today.

The utility or otherwise of any string-formatting feature comes down
to its elegance, to make code more pleasant to read and write.

i agree, for the programmer, that’s just as important.

···

On Monday 03 February 2003 05:35 am, Gavin Sinclair wrote:


tom sawyer, aka transami
transami@transami.net

I meant:

puts <<-EOS, “and more”
this is
come
text
EOS

or

puts %Q{
this is
come
text
}, “and more”

are possible, but

puts %l|this is
>come
>text

, “and more”

besides the fact the you’d never do two literal strings together like this
(one at least would be a variable) i have never used , (but i could see for
<< which i have used.)

but not so bad:

x = %L| this
                > here
                > will
puts x, "be appended to"

the use case of %L doesn’t much prescribe to needing to append other string
formations either. more realistic example:

x = "and more"
puts %L| this
···

On Monday 03 February 2003 09:02 am, nobu.nokada@softhome.net wrote:
> is
> some
> text #{x}


tom sawyer, aka transami
transami@transami.net

Nobu,

honestly, those extra features of HERE docs to which you refer are hardly ever
used.

for instance i would never do this.

    puts <<-EOS, "and more"
            this is
            come
            text
    EOS

it’s shoddy.

···


tom sawyer, aka transami
transami@transami.net

In that case, you’re unlikely to use a here document, although I doubt
any of the alternatives are super fast. I still maintain that the
extra bytes are negligable compared to any variable inlining you would
be doing, as well as other processing. And I don’t think %l and %L
are going to make a difference.

And the antidote to sluggish software is to consider the important
bytes (or other resources), not every single one.

Admission: I’ve never written a CGI app. But I do use a dialup :frowning:

Gavin

···

On Monday, February 3, 2003, 11:55:06 PM, Tom wrote:

On Monday 03 February 2003 05:35 am, Gavin Sinclair wrote:

This is misguided, IMNO (N = Naive). 24 bytes of wasted space - who
cares? tabto(0) is a waste of processing - who cares? Neither of
them is in a tight loop.

when you write a cgi app and you’re displaying some record detail that repeats
a string loop potentially hundreds of times then these bytes add up. the poor
soul on a dialup connection cares. and besides, nothing personal, but that
opinion is what leads to much of the bloated/sluggish software we have today.

Hi,

besides the fact the you’d never do two literal strings together like this
(one at least would be a variable) i have never used , (but i could see for
<< which i have used.)

Not just succeeding two literals. Here-docs allow other things
after it, you can see an example in lib/mkmf.rb:

def try_func(func, libs, headers = nil)
headers = cpp_include(headers)
try_link(<<“SRC”, libs) or try_link(<<“SRC”, libs)

whereas %l literal can’t be used here.

but not so bad:

x = %L| this
> here
> will
puts x, “be appended to”

the use case of %L doesn’t much prescribe to needing to append other string
formations either. more realistic example:

The necessarity of these work-arounds is the reason of my
doubt.

···

At Tue, 4 Feb 2003 01:37:59 +0900, Tom Sawyer wrote:


Nobu Nakada

Hi –

···

On Tue, 4 Feb 2003, Tom Sawyer wrote:

On Monday 03 February 2003 09:02 am, nobu.nokada@softhome.net wrote:

I meant:

puts <<-EOS, "and more"
            this is
            come
            text
EOS

or

puts %Q{
            this is
            come
            text
}, "and more"

are possible, but

puts %l|this is
     >come
     >text

, "and more"

besides the fact the you’d never do two literal strings together like this
(one at least would be a variable) i have never used , (but i could see for
<< which i have used.)

I wouldn’t say never. puts “one”, “two” can be handy since it prints
each literal on a separate line; you don’t have to do multiple puts’s
or embed \n’s explicitly.

David


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Hi –

Nobu,

honestly, those extra features of HERE docs to which you refer are hardly ever
used.

for instance i would never do this.

    puts <<-EOS, "and more"
            this is
            come
            text
    EOS

it’s shoddy.

It’s neither shoddy, nor “extra” :slight_smile: It’s just how here-docs work.

I think Nobu’s point is that all existing quotation mechanisms can
be dropped into the pattern:

quote_1, quote_2, quote_3, … , quote_n

without regard to order, and that the %L one would be the one and
only exception to this, therefore an anomaly.

David

···

On Thu, 6 Feb 2003, Tom Sawyer wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

It’s neither shoddy, nor “extra” :slight_smile: It’s just how here-docs work.

and how they are hardly ever used. i mean really am i wrong about that? when
was the last time you did:

x = <<-EOS, ‘add this’
to this
EOS

that what is appended appears before what it is to be appended to, is what i
mean by “shoddy”.

I think Nobu’s point is that all existing quotation mechanisms can
be dropped into the pattern:

quote_1, quote_2, quote_3, … , quote_n

without regard to order, and that the %L one would be the one and
only exception to this, therefore an anomaly.

always trade-offs. but i don’t think the limitation of not being able to chain
methods to %L structure out ways the benefit of having elegent margin
control. but that’s IMHO.

there is this solution, though i find it a tad unattractive, but of course it
is optional:

%L|this

···

is
a
test>, ‘appended’


tom sawyer, aka transami
transami@transami.net

I’ve seen it many times. How many examples did you look at
to determine that you thought no one did that?

Besides, it’s an issue with the parser and the overall language design,
not just with here-docs.

Hal

···

----- Original Message -----
From: “Tom Sawyer” transami@transami.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, February 05, 2003 2:40 PM
Subject: Re: %L, %l revisited

It’s neither shoddy, nor “extra” :slight_smile: It’s just how here-docs work.

and how they are hardly ever used. i mean really am i wrong about that?

It’s neither shoddy, nor “extra” :slight_smile: It’s just how here-docs work.

and how they are hardly ever used. i mean really am i wrong about that? when
was the last time you did:

x = <<-EOS, ‘add this’
to this
EOS

that what is appended appears before what it is to be appended to, is what i
mean by “shoddy”.

I can’t think of many places where I’ve used this feature of HERE docs,
but if you do any automated unit testing with Test::Unit, you’ve
probably used it. I definitely used it when testing up some HTML
generation classes I wrote:

assert_equal <<-EOT, myObject.toHTML, 'generate whole HTML doc from myObject'
myObject this is my object EOT

Yes, there are many different ways of accomplishing the same thing
without using this specific “feature” of HERE docs, but having this
feature made my test suite so much easier to read, IMHO.

always trade-offs. but i don’t think the limitation of not being able
to chain methods to %L structure out ways the benefit of having
elegent margin control. but that’s IMHO.

If you like elegant margin control, go try programming Python. Then,
tell me why you’ve decided to switch back to Ruby. :slight_smile:

– Dossy

···

On 2003.02.06, Tom Sawyer transami@transami.net wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

well, noting that all my ruby code, and i have a fair amount installed, falls
in here (i don’t use usr/local/):

silver% cd /usr/lib/ruby
silver% grep -r -e ‘^.<<-\w\s*,.*$’ ./

./site_ruby/1.6/amstd/const.rb: eval <<-End, nil, FILE, LINE + 1
./site_ruby/1.6/fileutils.rb: module_eval <<-End, FILE, LINE + 1
./site_ruby/1.6/fileutils.rb: module_eval <<-End, FILE, LINE + 1
./site_ruby/1.6/fileutils.rb: module_eval <<-End, FILE, LINE + 1
./1.6/net/protocol.rb: module_eval <<-End, FILE, LINE + 1
./1.6/forwardable.rb: module_eval(<<-EOS, “(FORWARDABLE)”, 1)
./1.6/forwardable.rb: instance_eval(<<-EOS, “(FORWARDABLE)”, 1)

silver% grep -r -e ‘^.<<\w,.*$’ ./

./site_ruby/1.6/wise/source/xcolor.c: 0, NUM2INT(red)<<CS,
NUM2INT(green)<<CS, NUM2INT(blue)<<CS, 0xff, 0
Binary file ./1.6/i386-linux/socket.so matches
./1.6/net/smtp.rb: smtp.send_mail <<EndOfMail, ‘your@mail.address’,
'to@some.domain’
Binary file ./1.6/i686-linux/socket.so matches

that makes 9. (and i note they are all apart of the ruby package itself)

why such the riff here? obviously it is not an oft used aspect of here docs,
at least not in Ruby. personally i think here docs a PERLISM, anyway.

but that’s not the point. the point is %L. how does the disimilarity of one
construct invalidate the usefulness of another? moreover i offered a solution
to this stated problem by using the deliminator to end the construct. but…

‘i guess the’ <<-EOS, ‘was a better’
> original
> idea
> of
> Nobu’s
EOS, ‘idea?’

tes.rb:1: can’t find string “EOS” anywhere before EOF
tes.rb:1: parse error

anyway, i understand if there is a programming difficulty with implementation.
other than that, i think %L a very classy construct. too bad no one else
seems to think so.

···

On Wednesday 05 February 2003 02:44 pm, Hal E. Fulton wrote:


tom sawyer, aka transami
transami@transami.net

(… discussion about %l syntax for here-docs …)

Besides, it’s an issue with the parser and the overall language design,
not just with here-docs.

I don’t see why the parser would have problems with the proposed %l
syntax. Remember a statement is automatically expanded to the next
line if it isn’t finished yet:

puts 3 +
4

=> 7

The same could apply to the %l syntax:

puts %l| This is
>the first text
, %l| And this
>the second

=> This is
the first text
And this
the second

The parser has to examine the next line anyway to determine whether
the here-doc is finished or not.

Regards,
Pit

···

On 6 Feb 2003 at 6:44, Hal E. Fulton wrote:

If you like elegant margin control, go try programming Python. Then,
tell me why you’ve decided to switch back to Ruby. :slight_smile:

hey now! :wink:

···


tom sawyer, aka transami
transami@transami.net

Tom Sawyer transami@transami.net writes:

well, noting that all my ruby code, and i have a fair amount installed, falls
in here (i don’t use usr/local/):

silver% cd /usr/lib/ruby
silver% grep -r -e ‘^.<<-\w\s*,.*$’ ./

jenny:/project/remacs> grep ‘<<’ *
buffer.rb: doc(self, :create, <<-HERE, [:destroy, [Memory, :mmap]])
buffer.rb: doc(self, :destroy, <<-HERE, [:create, [Memory, :mmap]])
buffer.rb: doc(self, :rename, <<-HERE, :auto_deduce)
buffer.rb: doc(self, :point, <<-HERE, [:insert, :delete, :append, :point=])
buffer.rb: doc(self, :point=, <<-HERE, :auto_deduce)
buffer.rb: doc(self, :insert, <<-HERE, [:delete, :append])
buffer.rb: doc(self, :delete, <<-HERE, :auto_deduce)
buffer.rb: doc(self, :append, <<-HERE, :auto_deduce)
buffer.rb: doc(self, :compact, <<-HERE, [[Memory, :mmap]])
buffer.rb: doc(self, :locale, <<-HERE, [:encoding, :locale=])
buffer.rb: doc(self, :locale=, <<-HERE, :auto_deduce)
buffer.rb: doc(self, :encoding, <<-HERE, :auto_deduce)
buffer.rb: doc(self, :encoding=, <<-HERE, :auto_deduce)
buffer.rb: doc(self, :group, <<-HERE, [:create, :destroy, :rename, :group=])
buffer.rb: doc(self, :group=, <<-HERE, :auto_deduce)
buffer.rb: doc(self, :region, <<-HERE, :internal)
buffer.rb: doc(self, :region=, <<-HERE, :internal)
documentation.rb: (Object, :doc, <<-HERE, nil)
documentation.rb: (String, :new, <<-HERE, nil)
documentation.rb: (Kernel, :global_variables, <<-HERE, nil)
documentation.rb: doc(“Module”, :class_variables, <<-HERE, nil)

The above result has been edited; results not related to usage of HERE
docs followed by other arguments have been edited out. The doc method
refered throughout has this signature:
def doc(class, method, content, related_methods); … end

that makes 9. (and i note they are all apart of the ruby package itself)
Now it is 21+9=30.

at least not in Ruby. personally i think here docs a PERLISM,
anyway. Shell scripting languages already have it before there was
perl. But, I do not know if it originated from sh or something even
more ancient.

YS.

···

On Wednesday 05 February 2003 02:44 pm, Hal E. Fulton wrote:

I didn’t mean the parser would have problems of
that nature. I meant the parser would have to
undergo radical changes and here-docs as we
know them would be broken.

Hal

···

----- Original Message -----
From: “Pit Capitain” pit@capitain.de
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, February 06, 2003 2:21 AM
Subject: Re: %L, %l revisited

On 6 Feb 2003 at 6:44, Hal E. Fulton wrote:

(… discussion about %l syntax for here-docs …)

Besides, it’s an issue with the parser and the overall language design,
not just with here-docs.

I don’t see why the parser would have problems with the proposed %l
syntax.