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

P

Peña, Botp

(e-mail address removed) wrote in message
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
 
D

David Alan Black

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 said:
(e-mail address removed) wrote in message
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
 
D

David A. Black

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.

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


David
 
R

Robert Klemme

David Alan Black said:
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+(.*)$/
=> "foo bar"

Really stupid question...

robert

Peña said:
(e-mail address removed) wrote in message
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
 
D

David A. Black

Hi --

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

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

=> "foo bar"

Really stupid question...

Which part is the question? :) 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
 
R

Robert Klemme

David A. Black said:
Hi --



Which part is the question? :) 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... :)

Kind regards

robert
 
D

David A. Black

Hi --

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... :)

Yeah, hopefully not :) 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
 
R

Robert Klemme

David A. Black said:
Hi --



Yeah, hopefully not :) 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top