[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Understanding { } and block_given

Srijayanth Sridhar

5/8/2009 5:49:00 AM

[Note: parts of this message were removed to make it a legal post.]

Hello,

I have the following:

class DSL
def DSL.load filename
dsl = new
dsl.instance_eval(File.read(filename))
dsl
end
def to sym,*args,&block
if block_given?
b=class << self;self;end
b.instance_eval {
define_method(sym,*args,&block)
}
end
end
def method_missing sym,*args
"#{sym}"
end
alias :say puts
end

foo=DSL.load("sample.dsl")


sample.dsl:

to smile do
say ":)"
end
to be_polite {
say "thank you"
}
smile
be_polite


The resulting output is:

moonwolf@trantor:~/ruby/dsl/todo$ ./dsl.rb
:)
moonwolf@trantor:~/ruby/dsl/todo$

be_polite and indeed, anything enclosded in {} doesn't seem to be eval-ed as
blocks. Why is this?

Jayanth

14 Answers

Srijayanth Sridhar

5/8/2009 9:42:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

This is definitely not a block_given thing.

block is coming through as a NilClass it seems.

puts block.class yields NilClass. The strange bit is that when I do it
outside of instance_eval with just a define_method under irb, it works as
expected. I am lost.

Anyone?

Jayanth

On Fri, May 8, 2009 at 11:19 AM, Srijayanth Sridhar <srijayanth@gmail.com>wrote:

> Hello,
>
> I have the following:
>
> class DSL
> def DSL.load filename
> dsl = new
> dsl.instance_eval(File.read(filename))
> dsl
> end
> def to sym,*args,&block
> if block_given?
> b=class << self;self;end
> b.instance_eval {
> define_method(sym,*args,&block)
> }
> end
> end
> def method_missing sym,*args
> "#{sym}"
> end
> alias :say puts
> end
>
> foo=DSL.load("sample.dsl")
>
>
> sample.dsl:
>
> to smile do
> say ":)"
> end
> to be_polite {
> say "thank you"
> }
> smile
> be_polite
>
>
> The resulting output is:
>
> moonwolf@trantor:~/ruby/dsl/todo$ ./dsl.rb
> :)
> moonwolf@trantor:~/ruby/dsl/todo$
>
> be_polite and indeed, anything enclosded in {} doesn't seem to be eval-ed
> as
> blocks. Why is this?
>
> Jayanth
>

F. Senault

5/8/2009 9:54:00 AM

0

Le 08 mai à 11:42, Srijayanth Sridhar a écrit :

> [Note: parts of this message were removed to make it a legal post.]
>
> This is definitely not a block_given thing.

It's an operator precedence thing. {} binds at a higher precedence than
do/end, meaning that, in the absence of parentheses, in one case, it's
the first function that takes the block and in the other, it's the
second one.

For instance :

>> def test ; (block_given? ? 'block' : 'no block') ; end
=> nil
>> puts test do end
no block
=> nil
>> puts test { }
block

In the first case, it's puts who gets the block (and discards it). In
the second case, it's my function. Compare to :

>> puts(test) do end
no block
=> nil
>> puts(test) {}
no block
=> nil
>> puts(test do end)
block
=> nil
>> puts(test {})
block

Fred
--
Just a reflection Just a glimpse Just a little reminder Of all the
what abouts And all the might have Could have beens Another day Some
other way But not another reason to continue And now you're one of us
The wretched (Nine Inch Nails, The Wretched)

Malcolm McLean

6/12/2014 7:26:00 PM

0

On Wednesday, June 11, 2014 6:11:24 AM UTC+1, hjw...@panix.com wrote:
> malcolm.mclean5@btinternet.com wrote:
>
>
> In 1917 it was not written the way people spoke then, but using the thees
> and thous of the the KJ.>
>
So dropping the thees and thous for the 1962 translation didn't reflect a shift in
English usage, but a change in the understanding of what appropriate religious
language was like.

Herman Rubin

6/12/2014 10:27:00 PM

0

On 2014-06-11, Arthur Kamlet <kamlet@panix.com> wrote:
> In article <ln8nr3$fes$1@reader1.panix.com>,
> Harry Weiss <hjweiss@panix.com> wrote:

>>In 1917 it was not written the way people spoke then, but using the thees
>>and thous of the the KJ.>



> The 1917 JPS English uses the King James "three score and ten" whereas
> "score" is now considered a very outmoded term. Although Lincoln
> must have remembered the King James usage when he composed his
> "Four score and twenty" as he was not accompanied by speechwriters.

Score was in common usage at that time.

--
This address is for information only. I do not claim that these views
are those of the Statistics Department or of Purdue University.
Herman Rubin, Department of Statistics, Purdue University
hrubin@stat.purdue.edu Phone: (765)494-6054 FAX: (765)494-0558

henry.p.goodman

6/13/2014 6:21:00 AM

0

On Thursday, June 12, 2014 11:27:14 PM UTC+1, Herman Rubin wrote:
> On 2014-06-11, Arthur Kamlet <kamlet@panix.com> wrote:
>
> > In article <ln8nr3$fes$1@reader1.panix.com>,
>
> > Harry Weiss <hjweiss@panix.com> wrote:
>
>
>
> >>In 1917 it was not written the way people spoke then, but using the thees
>
> >>and thous of the the KJ.>
>
>
>
>
>
>
>
> > The 1917 JPS English uses the King James "three score and ten" whereas
>
> > "score" is now considered a very outmoded term. Although Lincoln
>
> > must have remembered the King James usage when he composed his
>
> > "Four score and twenty" as he was not accompanied by speechwriters.
>
>
>
> Score was in common usage at that time.
>
What I find ironic is that seventy would be a better translation of the Hebrew Shivim.
Henry Goodman

mm

6/13/2014 5:56:00 PM

0

On Fri, 13 Jun 2014 06:20:59 +0000 (UTC),
"henry.dot.goodman.at.virgin.net" <henry.p.goodman@gmail.com> wrote:

>On Thursday, June 12, 2014 11:27:14 PM UTC+1, Herman Rubin wrote:
>> On 2014-06-11, Arthur Kamlet <kamlet@panix.com> wrote:
>>
>> > In article <ln8nr3$fes$1@reader1.panix.com>,
>>
>> > Harry Weiss <hjweiss@panix.com> wrote:
>>
>>
>>
>> >>In 1917 it was not written the way people spoke then, but using the thees
>>
>> >>and thous of the the KJ.>
>>
>>
>>
>>
>>
>>
>>
>> > The 1917 JPS English uses the King James "three score and ten" whereas
>>
>> > "score" is now considered a very outmoded term. Although Lincoln
>>
>> > must have remembered the King James usage when he composed his
>>
>> > "Four score and twenty" as he was not accompanied by speechwriters.

and seven

>>
>> Score was in common usage at that time.
>>
>What I find ironic is that seventy would be a better translation of the Hebrew Shivim.

Exactly. That's one example of what's wrong with the 1917 translation.

Well, I don't think I see the irony. I'd just call it a mistake.

I havent' had time to explain why later ones were better. But in short
the problem is that 1917 was largely based on the Revised Version and
American Standard Version That is, Xian translations. I assume, in
order to save time. The translators went through them finding and
correcting all the obvious Xian mistakes and probably most of the
non-obvious tiny shades of meaning.

But that is not the same thing as translating from Hebrew, as later
Jewish translations were done.

The basic question translators asked themselves when looking at the
Revised and American Standard Versions was, "Does this conflict with
the Jewish Bible as I know it".

The basic question used in translating straight from Hebrew is "What is
the best translation of the original Hebrew that I can render?**

So since 3 score and 10 is numerically equal to 70, that was good enough
in 1917. But obviously the proper, better translation is seventy.

**Also, good translators need to consider not just literal meaning. The
word "best" means more than just literal meaning. In portions that are
poetic, they should try to capture the poetry. Where there are
allusions, they should try to capture the allusion. Where words in the
original are related to each other, they should try to use words in the
translation that are also related to each other. When idioms are used,
they should try to capture the tone of the idiom. When the original
uses onomatopoeia is use, the translation should too. (and I'm sure I'm
leaving out things) Often a compromise has to be made, which doesn't
fullly capture, or doesn't capture at all, some aspects of the original
All of this is much harder or impossible when starting with another
translation.


>Henry Goodman

--

Meir
It is better to eat an onion in Jerusalem than a cockerel in Egypt. 1055CE

mm

6/13/2014 6:28:00 PM

0

On Fri, 13 Jun 2014 17:56:18 +0000 (UTC), mm <mm2005@bigfoot.com> wrote:

>
>I havent' had time to explain why later ones were better. But in short
>the problem is that 1917 was largely based on the Revised Version and
>American Standard Version That is, Xian translations. I assume, in
>order to save time. The translators went through them finding and
>correcting all the obvious Xian mistakes and probably most of the
>non-obvious tiny shades of meaning.

I failed to say why this is possible at all. There are sentences and
probably whole sections where Jewish and Xian translations, at least the
pshat, the simple clear meaning of the Hebrew, mean the same. Often
words, phrases, once in a while maybe whole sentences are word for word
the same. So it's possible to do an acceptable job by starting with a
Xian translation if one is thorough in looking for both big and little
errors, incuding shades of meaning and smaller.

But it still won't be as good as starting with Hebrew for the whole
thing, for the reasons I have below in the quoted text:

>But that is not the same thing as translating from Hebrew, as later
>Jewish translations were done.
>
>The basic question translators asked themselves when looking at the
>Revised and American Standard Versions was, "Does this conflict with
>the Jewish Bible as I know it".
>
>The basic question used in translating straight from Hebrew is "What is
>the best translation of the original Hebrew that I can render?**
>
>So since 3 score and 10 is numerically equal to 70, that was good enough
>in 1917. But obviously the proper, better translation is seventy.
>
>**Also, good translators need to consider not just literal meaning. The
>word "best" means more than just literal meaning. In portions that are
>poetic, they should try to capture the poetry. Where there are
>allusions, they should try to capture the allusion. Where words in the
>original are related to each other, they should try to use words in the
>translation that are also related to each other. When idioms are used,
>they should try to capture the tone of the idiom. When the original
>uses onomatopoeia is use, the translation should too. (and I'm sure I'm
>leaving out things) Often a compromise has to be made, which doesn't
>fullly capture, or doesn't capture at all, some aspects of the original
>All of this is much harder or impossible when starting with another
>translation.

--

Meir
It is better to eat an onion in Jerusalem than a cockerel in Egypt. 1055CE

Herman Rubin

6/16/2014 6:01:00 PM

0

On 2014-06-16, Giorgies E Kepipesiom <kepipesiom@hotmail.com> wrote:
> On Sunday, June 15, 2014 8:34:24 PM UTC-4, Herman Rubin wrote:

>> The word "mitzraim" is dual, meaning "two rivers". The rivers
>> are the White Nile and the Blue Nile, which merge to form the Nile.

> You are correct that the Hebrew suffix "ayim" indicates a pair of something. So Mitzrayim means a pair of whatever "mitzr" means. You say "mitzr" means river? In what language? Certainly not Hebrew.

Egyptian.

> GEK


--
This address is for information only. I do not claim that these views
are those of the Statistics Department or of Purdue University.
Herman Rubin, Department of Statistics, Purdue University
hrubin@stat.purdue.edu Phone: (765)494-6054 FAX: (765)494-0558

Giorgies E Kepipesiom

6/16/2014 11:49:00 PM

0

On Monday, June 16, 2014 2:01:16 PM UTC-4, Herman Rubin wrote:
>
> Egyptian.
>
Egyptian? Are you sure? So let me see if I understand your hypothesis correctly. The name Mitzrayim, which appears hundreds of times in the Hebrew Scriptures, is half Hebrew and half Egyptian? Sort of Egyptian-River-Hebrew-Pair? Ridiculous. Either you made that up, or you have swallowed whole something you read that someone else made up.

GEK

Evertjan.

6/17/2014 7:55:00 AM

0

Giorgies E Kepipesiom <kepipesiom@hotmail.com> wrote on 17 jun 2014 in
soc.culture.jewish.moderated:

> On Monday, June 16, 2014 2:01:16 PM UTC-4, Herman Rubin wrote:
>>
>> Egyptian.
>>
> Egyptian? Are you sure? So let me see if I understand your hypothesis
> correctly. The name Mitzrayim, which appears hundreds of times in the
> Hebrew Scriptures, is half Hebrew and half Egyptian? Sort of
> Egyptian-River-Hebrew-Pair? Ridiculous. Either you made that up, or you
> have swallowed whole something you read that someone else made up.

Methinks there is the possibility that it is as Egyptian in origin as the
name "Moshe", which appears hundreds of times in Hebrew Scriptures.

It may not be true, but why is it ridiculous, and more to the point,
why does Herman's suggestion make you so angry?

Should we only "swallow" what you say
and consider what others say as just "made up"?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)