What is the equivalent of Python's "%s" % "MyString"?

I think the op implied late binding or late generation of string and
variables/hashes. I think ruby can do this w finesse, so we’ve seen examples
of workarounds immediately posted (thanks guys, I learned a lot here).

Thus
given foo_string % foo_hash, one can generate foo_string anytime one
wants and just tells it to “Hey foo_string, get your values from foo_hash”.
foo_hash of course may contain a lot of key-val pairs. We need not
care/worry of the order or counts of the vars since the foo_string will just
pickup what it wants.

This style is also good for structures and records in db, imho.

I hope I was thinking straight here. Pls correct me guys if I’m wrong.
In this regard, I vote for Nobu’s rcr.

kind regards -botp

···

GGarramuno@aol.com [mailto:GGarramuno@aol.com] wrote:

nobu.nokada@softhome.net wrote in message
news:<200406020151.i521pOHY005774@sharui.nakada.niregi.kanuma.
tochigi.jp>…

Hi,

At Wed, 2 Jun 2004 03:43:42 +0900,
Sam Sungshik Kong wrote in [ruby-talk:102028]:

s = “My name is %(name)s and my age is %(age)d.” %
{“name”: “Sam”,
“age”: 34}

I know that ruby has “#{name}” expression.
But that requires a variable named “name” in advance.
I want to bind the format string and data later.

I proposed that feature once in [ruby-dev:16351], though
rejected, but
still I think that it would be useful for I18N. Is it worth for RCR?

Do you have an example on how would you use this? I ask
because I would also vote strongly against it.

One of the things that I really loved about ruby while
learning it was its “#{}” syntax, as it seemed to me a much
more consistent way of achieving what sprintf, $, %, etc.
have been trying for years to achieve in languages like C,
perl, python, etc.

[snip good examples]
The %s syntax is anything but readable once you have more
than 3 elements. Using a hash to try to clarify it seems to
me more of a crutch for languages that do not support ruby’s
extremely powerful “#{}” formating. That syntax still forces
me to look for meaning of the text format string in two
different places (in the location of the text and at the end
of it), instead of in a single place as I read the string,
which seems like a step backwards overall.

Note (from David Black): This was a message sent by Botp to ruby-talk
that didn’t make it through. I resent it, with a small change, to see
if it would make it, and it did.

The change was to strip “Re:” and put “about” in the subject line…

“Peña, Botp” botp@delmonte-phil.com writes:

···

GGarramuno@aol.com [mailto:GGarramuno@aol.com] wrote:

nobu.nokada@softhome.net wrote in message
news:<200406020151.i521pOHY005774@sharui.nakada.niregi.kanuma.
tochigi.jp>…

Hi,

At Wed, 2 Jun 2004 03:43:42 +0900,
Sam Sungshik Kong wrote in [ruby-talk:102028]:

s = “My name is %(name)s and my age is %(age)d.” %
{“name”: “Sam”,
“age”: 34}

I know that ruby has “#{name}” expression.
But that requires a variable named “name” in advance.
I want to bind the format string and data later.

I proposed that feature once in [ruby-dev:16351], though
rejected, but
still I think that it would be useful for I18N. Is it worth for RCR?

Do you have an example on how would you use this? I ask
because I would also vote strongly against it.

One of the things that I really loved about ruby while
learning it was its “#{}” syntax, as it seemed to me a much
more consistent way of achieving what sprintf, $, %, etc.
have been trying for years to achieve in languages like C,
perl, python, etc.

[snip good examples]
The %s syntax is anything but readable once you have more
than 3 elements. Using a hash to try to clarify it seems to
me more of a crutch for languages that do not support ruby’s
extremely powerful “#{}” formating. That syntax still forces
me to look for meaning of the text format string in two
different places (in the location of the text and at the end
of it), instead of in a single place as I read the string,
which seems like a step backwards overall.

I think the op implied late binding or late generation of string and
variables/hashes. I think ruby can do this w finesse, so we’ve seen examples
of workarounds immediately posted (thanks guys, I learned a lot here).

Thus
given foo_string % foo_hash, one can generate foo_string anytime one
wants and just tells it to “Hey foo_string, get your values from foo_hash”.
foo_hash of course may contain a lot of key-val pairs. We need not
care/worry of the order or counts of the vars since the foo_string will just
pickup what it wants.

This style is also good for structures and records in db, imho.

I hope I was thinking straight here. Pls correct me guys if I’m wrong.
In this regard, I vote for Nobu’s rcr.

kind regards -botp

David A. Black
dblack@wobblini.net

(Meaning, didn’t make it through to comp.lang.ruby.)

David

···

On Thu, 3 Jun 2004, David Alan Black wrote:

Note (from David Black): This was a message sent by Botp to ruby-talk
that didn’t make it through. I resent it, with a small change, to see
if it would make it, and it did.


David A. Black
dblack@wobblini.net

"David Alan Black" <dblack@wobblini.net> schrieb im Newsbeitrag
news:m3vfi98ggu.fsf@wobblini.net...

Note (from David Black): This was a message sent by Botp to ruby-talk
that didn't make it through. I resent it, with a small change, to see
if it would make it, and it did.

The change was to strip "Re:" and put "about" in the subject line....

I assume this is a stupid question, but the GW doesn't contain a header
detection regexp that looks like this:

/^(.*):\s+(.*)$/

/^(.*):\s+(.*)$/ =~ 'Subject: Re: foo bar'

=> 0

$1

=> "Subject: Re"

$2

=> "foo bar"

Really stupid question...

    robert

"Peña, Botp" <botp@delmonte-phil.com> writes:

>
> > nobu.nokada@softhome.net wrote in message
> > news:<200406020151.i521pOHY005774@sharui.nakada.niregi.kanuma.
> > tochigi.jp>...
> > > Hi,
> > >
> > > At Wed, 2 Jun 2004 03:43:42 +0900,
> > > Sam Sungshik Kong wrote in [ruby-talk:102028]:
> > > > s = "My name is %(name)s and my age is %(age)d." %
> > {"name": "Sam",
> > > > "age": 34}
> > >
> > > > I know that ruby has "#{name}" expression.
> > > > But that requires a variable named "name" in advance.
> > > > I want to bind the format string and data later.
> > >
> > > I proposed that feature once in [ruby-dev:16351], though
> > rejected, but
> > > still I think that it would be useful for I18N. Is it worth for

RCR?

> >
> > Do you have an example on how would you use this? I ask
> > because I would also vote strongly against it.
> >
> > One of the things that I really loved about ruby while
> > learning it was its "#{}" syntax, as it seemed to me a much
> > more consistent way of achieving what sprintf, $, %, etc.
> > have been trying for years to achieve in languages like C,
> > perl, python, etc.
> >
> > [snip good examples]
> > The %s syntax is anything but readable once you have more
> > than 3 elements. Using a hash to try to clarify it seems to
> > me more of a crutch for languages that do not support ruby's
> > extremely powerful "#{}" formating. That syntax still forces
> > me to look for meaning of the text format string in two
> > different places (in the location of the text and at the end
> > of it), instead of in a single place as I read the string,
> > which seems like a step backwards overall.
>
>
> I think the op implied late binding or late generation of string and
> variables/hashes. I think ruby can do this w finesse, so we've seen

examples

> of workarounds immediately posted (thanks guys, I learned a lot here).
>
> Thus
> given foo_string % foo_hash, one can generate foo_string anytime one
> wants and just tells it to "Hey foo_string, get your values from

foo_hash".

> foo_hash of course may contain a lot of key-val pairs. We need not
> care/worry of the order or counts of the vars since the foo_string

will just

···

> GGarramuno@aol.com [mailto:GGarramuno@aol.com] wrote:
> pickup what it wants.
>
> This style is also good for structures and records in db, imho.
>
> I hope I was thinking straight here. Pls correct me guys if I'm wrong.
> In this regard, I vote for Nobu's rcr.
>
> kind regards -botp
>
>
>
>

--
--
David A. Black
dblack@wobblini.net

Hi --

···

On Thu, 3 Jun 2004, Robert Klemme wrote:

"David Alan Black" <dblack@wobblini.net> schrieb im Newsbeitrag
news:m3vfi98ggu.fsf@wobblini.net...
>
> Note (from David Black): This was a message sent by Botp to ruby-talk
> that didn't make it through. I resent it, with a small change, to see
> if it would make it, and it did.
>
> The change was to strip "Re:" and put "about" in the subject line....

I assume this is a stupid question, but the GW doesn't contain a header
detection regexp that looks like this:

/^(.*):\s+(.*)$/

>> /^(.*):\s+(.*)$/ =~ 'Subject: Re: foo bar'
=> 0
>> $1
=> "Subject: Re"
>> $2
=> "foo bar"

Really stupid question...

Which part is the question? :slight_smile: If it's whether that regexp appears in
the code, the answer is no. But I'm not understanding what suggests
that it might.

David

--
David A. Black
dblack@wobblini.net

"David A. Black" <dblack@wobblini.net> schrieb im Newsbeitrag
news:Pine.LNX.4.44.0406030437540.1134-100000@wobblini...

Hi --

>
> "David Alan Black" <dblack@wobblini.net> schrieb im Newsbeitrag
> news:m3vfi98ggu.fsf@wobblini.net...
> >
> > Note (from David Black): This was a message sent by Botp to

ruby-talk

> > that didn't make it through. I resent it, with a small change, to

see

> > if it would make it, and it did.
> >
> > The change was to strip "Re:" and put "about" in the subject

line....

>
> I assume this is a stupid question, but the GW doesn't contain a

header

> detection regexp that looks like this:
>
> /^(.*):\s+(.*)$/
>
> >> /^(.*):\s+(.*)$/ =~ 'Subject: Re: foo bar'
> => 0
> >> $1
> => "Subject: Re"
> >> $2
> => "foo bar"
>
> Really stupid question...

Which part is the question? :slight_smile: If it's whether that regexp appears in
the code, the answer is no. But I'm not understanding what suggests
that it might.

You said you fixed the message by removing "Re:" from the subject line and
replaced it by "about". The wild guess was just that - since "Re:" ends
with a colon - there might be a regexp somewhere that wrongly identifies
the header name as "Subject: Re:", which in turn might have had other
unwanted consequences.

But I barely dared to ask that because I didn't assume that anyone
involved in the GW software would use such a regexp... :slight_smile:

Kind regards

    robert

···

On Thu, 3 Jun 2004, Robert Klemme wrote:

Hi --

···

On Thu, 3 Jun 2004, Robert Klemme wrote:

"David A. Black" <dblack@wobblini.net> schrieb im Newsbeitrag
news:Pine.LNX.4.44.0406030437540.1134-100000@wobblini...
> Hi --
>
> On Thu, 3 Jun 2004, Robert Klemme wrote:
>
> >
> > "David Alan Black" <dblack@wobblini.net> schrieb im Newsbeitrag
> > news:m3vfi98ggu.fsf@wobblini.net...
> > >
> > > Note (from David Black): This was a message sent by Botp to
ruby-talk
> > > that didn't make it through. I resent it, with a small change, to
see
> > > if it would make it, and it did.
> > >
> > > The change was to strip "Re:" and put "about" in the subject
line....
> >
> > I assume this is a stupid question, but the GW doesn't contain a
header
> > detection regexp that looks like this:
> >
> > /^(.*):\s+(.*)$/
> >
> > >> /^(.*):\s+(.*)$/ =~ 'Subject: Re: foo bar'
> > => 0
> > >> $1
> > => "Subject: Re"
> > >> $2
> > => "foo bar"
> >
> > Really stupid question...
>
> Which part is the question? :slight_smile: If it's whether that regexp appears in
> the code, the answer is no. But I'm not understanding what suggests
> that it might.

You said you fixed the message by removing "Re:" from the subject line and
replaced it by "about". The wild guess was just that - since "Re:" ends
with a colon - there might be a regexp somewhere that wrongly identifies
the header name as "Subject: Re:", which in turn might have had other
unwanted consequences.

But I barely dared to ask that because I didn't assume that anyone
involved in the GW software would use such a regexp... :slight_smile:

Yeah, hopefully not :slight_smile: I think what's happening is that the "Re:"
flags the message as a reply, so then the lack of a Reference: header
results in rejection of the message (since it then appears to be a
reply to nothing). In the case of Botp's message, I saved the
message, manually removed "Re:", and then resent it to the gateway.

David

--
David A. Black
dblack@wobblini.net

"David A. Black" <dblack@wobblini.net> schrieb im Newsbeitrag
news:Pine.LNX.4.44.0406030559200.4758-100000@wobblini...

Hi --

>
> "David A. Black" <dblack@wobblini.net> schrieb im Newsbeitrag
> news:Pine.LNX.4.44.0406030437540.1134-100000@wobblini...
> > Hi --
> >
> >
> > >
> > > "David Alan Black" <dblack@wobblini.net> schrieb im Newsbeitrag
> > > news:m3vfi98ggu.fsf@wobblini.net...
> > > >
> > > > Note (from David Black): This was a message sent by Botp to
> ruby-talk
> > > > that didn't make it through. I resent it, with a small change,

to

> see
> > > > if it would make it, and it did.
> > > >
> > > > The change was to strip "Re:" and put "about" in the subject
> line....
> > >
> > > I assume this is a stupid question, but the GW doesn't contain a
> header
> > > detection regexp that looks like this:
> > >
> > > /^(.*):\s+(.*)$/
> > >
> > > >> /^(.*):\s+(.*)$/ =~ 'Subject: Re: foo bar'
> > > => 0
> > > >> $1
> > > => "Subject: Re"
> > > >> $2
> > > => "foo bar"
> > >
> > > Really stupid question...
> >
> > Which part is the question? :slight_smile: If it's whether that regexp appears

in

> > the code, the answer is no. But I'm not understanding what suggests
> > that it might.
>
> You said you fixed the message by removing "Re:" from the subject line

and

> replaced it by "about". The wild guess was just that - since "Re:"

ends

> with a colon - there might be a regexp somewhere that wrongly

identifies

> the header name as "Subject: Re:", which in turn might have had other
> unwanted consequences.
>
> But I barely dared to ask that because I didn't assume that anyone
> involved in the GW software would use such a regexp... :slight_smile:

Yeah, hopefully not :slight_smile: I think what's happening is that the "Re:"
flags the message as a reply, so then the lack of a Reference: header
results in rejection of the message (since it then appears to be a
reply to nothing). In the case of Botp's message, I saved the
message, manually removed "Re:", and then resent it to the gateway.

Sounds like the new server software trying to be smart. Sometimes that's
not a good idea...

Regards

    robert

···

On Thu, 3 Jun 2004, Robert Klemme wrote:
> > On Thu, 3 Jun 2004, Robert Klemme wrote: