"yield called out of block" 
Author Message
 "yield called out of block"

Having just talked with a nuby in email, I believe this error message
should be reworded.

irb(main):009:0> [1,2,3].each
LocalJumpError: yield called out of block
        from (irb):9:in `each'
        from (irb):9

How about any of the following:

  "yield called but no block given"
  "there is nothing to yield to"
  "an iterator usually needs to be given something to do" ;-)

Anyway, the current message doesn't quite seem to capture what is wrong.
My correpondent was convinced there was something wrong with the
iterator method.

  -- Mark



Wed, 21 Apr 2004 01:13:25 GMT  
 "yield called out of block"
This doesn't really have much to do with the original post, but why not
just completely eliminate the problem and take a cue from Lisp by just
allowing functions to return multiple values?  yield could simply have
the same effect as values does in CL.


Wed, 21 Apr 2004 02:27:53 GMT  
 "yield called out of block"
Hello --

Quote:

> This doesn't really have much to do with the original post, but why not
> just completely eliminate the problem and take a cue from Lisp by just
> allowing functions to return multiple values?  yield could simply have
> the same effect as values does in CL.

Well, that would leave us needing a new word for what used to be
"yield" :-)  I don't think that values in CL does what yield does, does
it?  Wouldn't this (returning multiple values) be closer?

  def thing
    return 1,2,3
  end

In any case, yield and related iterator behavior are very central to
Ruby; I doubt they're in flux or under consideration for elimination.
At least, I hope not :-)

David

--
David Alan Black


Web:  http://pirate.shu.edu/~blackdav



Wed, 21 Apr 2004 03:54:46 GMT  
 "yield called out of block"
Because yield can be used for all sorts of useful things, and returning 10,000
values from a function requires having 10,000 * sizeof(item) bytes allocated,
whereas iterating through them with yield would only require one instance of
said item in memory during each iteration.

OTOH, I have no idea how values works in CL, so I could be putting my foot in my
mouth.

Besides, you CAN return multiple values in ruby, really. There's a built-in
array type.

from Alexander Schofield on 2001-11-03 at 03:27:53:

Quote:
> This doesn't really have much to do with the original post, but why not
> just completely eliminate the problem and take a cue from Lisp by just
> allowing functions to return multiple values?  yield could simply have
> the same effect as values does in CL.

--
Eli Green


Wed, 21 Apr 2004 04:32:02 GMT  
 "yield called out of block"

Quote:

> Having just talked with a nuby in email, I believe this error message
> should be reworded.

> irb(main):009:0> [1,2,3].each
> LocalJumpError: yield called out of block
>         from (irb):9:in `each'
>         from (irb):9

> How about any of the following:

>   "yield called but no block given"
>   "there is nothing to yield to"
>   "an iterator usually needs to be given something to do" ;-)

I saw the same error message today, and it didn't help to solve the
problem. Any of your suggestion would be good; the last one is the best.
  Or: 'no task given for the iterator'.

Tobi

--
Tobias Reif
http://www.pinkjuice.com/myDigitalProfile.xhtml

go_to('www.ruby-lang.org').get(ruby).play.create.have_fun
http://www.pinkjuice.com/ruby/



Wed, 21 Apr 2004 04:43:11 GMT  
 "yield called out of block"

Quote:
> Well, that would leave us needing a new word for what used to be
> "yield" :-)  I don't think that values in CL does what yield does,
> does
> it?  Wouldn't this (returning multiple values) be closer?

>   def thing
>     return 1,2,3
>   end

Yes it would.  I wasn't suggesting we eliminate yields primary purpose, just
that we modify it in one case (that case being when no block is supplied).
Either to return multiple values as you have shown above by collecting them into
an array and returning that object, which would probably be easier to implement,
or to do what the CL values does and return them as true seperate values (which
would allow you to take the first and ignore the rest), does Perl have something
similar to this?  Having yield collect everything into an array (when no block
is supplied) would save typing in all those cases where that's all you were
really using the iterator for anyways.

Quote:
> In any case, yield and related iterator behavior are very central to
> Ruby; I doubt they're in flux or under consideration for elimination.
> At least, I hope not :-)

So do I.


Wed, 21 Apr 2004 05:20:01 GMT  
 "yield called out of block"

Quote:
----- Original Message -----


Sent: Friday, November 02, 2001 3:20 PM
Subject: [ruby-talk:24205] Re: "yield called out of block"

> Yes it would.  I wasn't suggesting we eliminate yields primary purpose,
just
> that we modify it in one case (that case being when no block is supplied).
> Either to return multiple values as you have shown above by collecting
them into
> an array and returning that object, which would probably be easier to
implement,
> or to do what the CL values does and return them as true seperate values
(which
> would allow you to take the first and ignore the rest), does Perl have
something
> similar to this?  Having yield collect everything into an array (when no
block
> is supplied) would save typing in all those cases where that's all you
were
> really using the iterator for anyways.

This is an interesting idea. I'm uncertain yet
as to whether I like it. Let me make sure I
understand you.

When we iterate over a list of 20 items and
yield them one at a time (without a block),
do we get an array back? What if we yield
them in pairs, i.e. not one at a time?

Hal



Wed, 21 Apr 2004 05:26:17 GMT  
 "yield called out of block"
Hello --


Quote:
> > Well, that would leave us needing a new word for what used to be
> > "yield" :-)  I don't think that values in CL does what yield does,
> > does
> > it?  Wouldn't this (returning multiple values) be closer?

> >   def thing
> >     return 1,2,3
> >   end

> Yes it would.  I wasn't suggesting we eliminate yields primary purpose, just
> that we modify it in one case (that case being when no block is supplied).
> Either to return multiple values as you have shown above by collecting them into
> an array and returning that object, which would probably be easier to implement,
> or to do what the CL values does and return them as true seperate values (which
> would allow you to take the first and ignore the rest), does Perl have something
> similar to this?  Having yield collect everything into an array (when no block
> is supplied) would save typing in all those cases where that's all you were
> really using the iterator for anyways.

Side-note: if you want to get just the first from a (possible) array, you can
do:

  def multiple
    return 1,2,3
  end

  a, = multiple   # a is now 1

In Perl you can do:

  ($a) = (1,2,3);  # $a is now 1

and probably 4,000 other things I've now forgotten :-)

Anyway, back to yield.  I have a conceptual problem with grasping what
you're suggesting.  The thing is, yield() yields control to a block,
and the call to yield evaluates to the return value of that block.  So
what exactly could it mean to yield not to a block?  What would
control be being yielded to?

Come to think of it, I believe that in a conversation with Dave Thomas
recently I made sort of the opposite suggestion -- namely, that in
cases where yield was not explicity called, the return value of a
method might be sent to the block, if there is one.  For example:

  def ytest
    return 123
  end

  ytest do |x| print x end   #  prints 123

whereas

  def ytest
    yield(456)
    return 123
  end

  n = ytest do |x| print x end   #  prints 456
  print n                        #  prints 123

David

--
David Alan Black


Web:  http://pirate.shu.edu/~blackdav



Wed, 21 Apr 2004 05:57:48 GMT  
 "yield called out of block"
Hi,

In message "[ruby-talk:24183] "yield called out of block""

|How about any of the following:
|
|  "yield called but no block given"
|  "there is nothing to yield to"
|  "an iterator usually needs to be given something to do" ;-)
|
|Anyway, the current message doesn't quite seem to capture what is wrong.
|My correpondent was convinced there was something wrong with the
|iterator method.

"no block to yield"?

                                                        matz.



Wed, 21 Apr 2004 09:49:17 GMT  
 "yield called out of block"
Hello --

Quote:

> Hi,

> In message "[ruby-talk:24183] "yield called out of block""

> |How about any of the following:
> |
> |  "yield called but no block given"
> |  "there is nothing to yield to"
> |  "an iterator usually needs to be given something to do" ;-)
> |
> |Anyway, the current message doesn't quite seem to capture what is wrong.
> |My correpondent was convinced there was something wrong with the
> |iterator method.

> "no block to yield"?

Maybe:

   no block to yield to

might be clearer.  Or

   yield called in the absence of a block

David

--
David Alan Black


Web:  http://pirate.shu.edu/~blackdav



Wed, 21 Apr 2004 10:56:46 GMT  
 "yield called out of block"

Quote:

> Hi,

> In message "[ruby-talk:24183] "yield called out of block""

> |How about any of the following:
> |
> |  "yield called but no block given"
> |  "there is nothing to yield to"
> |  "an iterator usually needs to be given something to do" ;-)
> |
> |Anyway, the current message doesn't quite seem to capture what is wrong.
> |My correpondent was convinced there was something wrong with the
> |iterator method.

> "no block to yield"?

It would sound fine if you just were to change the "out" in the original
exception to "outside".

--
 Brian Fundakowski Feldman           \  FreeBSD: The Power to Serve!  /



Wed, 21 Apr 2004 11:24:00 GMT  
 "yield called out of block"

Quote:
> This is an interesting idea. I'm uncertain yet
> as to whether I like it. Let me make sure I
> understand you.

> When we iterate over a list of 20 items and
> yield them one at a time (without a block),
> do we get an array back? What if we yield
> them in pairs, i.e. not one at a time?

Based on the syntactic little gem David Alan Black enlightened me with,
I would say yes, return an array, there's no need for anything like the
multiple return values of CL.

If pairs are yielded, then I would say impose structure, so:
yield 1,2
yield 3,4
without a block would return:
[[1,2],[3,4]]

Because it is easier to remove structure later on then it is to impose
it, and because you could then take this resulting array and use it in
much the same way you would have if you had supplied a block in the
first place, even if it's not as flexible as supplying a block and
building up the structure you want, the hope is that it would save you
typing in most (but it wouldn't be suitable for all) cases.


Quote:
> def multiple
> return 1,2,3
> end
> a, = multiple   # a is now 1

Good to know, and I withdraw any thoughts about the benefits of real
multiple return values based on this (see above).

Quote:
> I have a conceptual problem with grasping what
> you're suggesting.  The thing is, yield() yields control to a block,
> and the call to yield evaluates to the return value of that block.  So
> what exactly could it mean to yield not to a block?  What would
> control be being yielded to?

Perhaps it could be thought of as an implicit block that builds up an
array, even if no prebuilt block would work, since if some structure is
to be imposed you need to know how many args yield was called with.  To
say nothing of how this imaginary block would know when to return the
built up array, or even where to return the array to, but then again,
it's only a thought-aid.

Quote:
>  def ytest
>    return 123
>  end

>  ytest do |x| print x end   #  prints 123

> def ytest
>    yield(456)
>    return 123
> end
> n = ytest do |x| print x end   #  prints 456
> print n                        #  prints 123

That's a very interesting idea, but then what if you had:
def ytest
        return [1,2,3].each
end
?


Wed, 21 Apr 2004 13:14:46 GMT  
 "yield called out of block"

Quote:
----- Original Message -----


Sent: Friday, November 02, 2001 9:24 PM
Subject: [ruby-talk:24246] Re: "yield called out of block"


> > Hi,

> > In message "[ruby-talk:24183] "yield called out of block""

> > |How about any of the following:
> > |
> > |  "yield called but no block given"
> > |  "there is nothing to yield to"
> > |  "an iterator usually needs to be given something to do" ;-)
> > |
> > |Anyway, the current message doesn't quite seem to capture what is
wrong.
> > |My correpondent was convinced there was something wrong with the
> > |iterator method.

> > "no block to yield"?

> It would sound fine if you just were to change the "out" in the original
> exception to "outside".

I think I would say "No block specified with iterator call."
Is that misleading in any way?

Hal



Wed, 21 Apr 2004 16:37:57 GMT  
 "yield called out of block"
Hello --

Quote:


> > This is an interesting idea. I'm uncertain yet
> > as to whether I like it. Let me make sure I
> > understand you.

> > When we iterate over a list of 20 items and
> > yield them one at a time (without a block),
> > do we get an array back? What if we yield
> > them in pairs, i.e. not one at a time?

> Based on the syntactic little gem David Alan Black enlightened me with,
> I would say yes, return an array, there's no need for anything like the
> multiple return values of CL.

> If pairs are yielded, then I would say impose structure, so:
> yield 1,2
> yield 3,4
> without a block would return:
> [[1,2],[3,4]]

But you really do get into the problem that Eli Green mentioned, namely
that you're then storing all these things rather than iterating over them.
That could be very costly.

Also, what do you mean by "return"?  Methods still need to have a return
value.  For example:

  def thing
    yield 123
    return 456
  end

In the absence of a block, what would happen to that 123?

I think that's the problem you're touching on here:

Quote:
> > I have a conceptual problem with grasping what
> > you're suggesting.  The thing is, yield() yields control to a block,
> > and the call to yield evaluates to the return value of that block.  So
> > what exactly could it mean to yield not to a block?  What would
> > control be being yielded to?

> Perhaps it could be thought of as an implicit block that builds up an
> array, even if no prebuilt block would work, since if some structure is
> to be imposed you need to know how many args yield was called with.  To
> say nothing of how this imaginary block would know when to return the
> built up array, or even where to return the array to, but then again,
> it's only a thought-aid.

.. but I'm not sure what it all means if it's just a thought-aid :-)

- Show quoted text -

Quote:
> >  def ytest
> >    return 123
> >  end

> >  ytest do |x| print x end   #  prints 123

> > def ytest
> >    yield(456)
> >    return 123
> > end
> > n = ytest do |x| print x end   #  prints 456
> > print n                        #  prints 123

> That's a very interesting idea, but then what if you had:
> def ytest
>    return [1,2,3].each
> end
> ?

You'd get "yield called out of block", or whatever the new wording may
be :-)  (That would come from the call to #each.)

David

--
David Alan Black


Web:  http://pirate.shu.edu/~blackdav



Wed, 21 Apr 2004 17:43:30 GMT  
 "yield called out of block"

Quote:

>    no block to yield to

is good.

Tobi

--
Tobias Reif
http://www.pinkjuice.com/myDigitalProfile.xhtml

go_to('www.ruby-lang.org').get(ruby).play.create.have_fun
http://www.pinkjuice.com/ruby/



Wed, 21 Apr 2004 21:30:46 GMT  
 
 [ 24 post ]  Go to page: [1] [2]

 Relevant Pages 

1. ERROR "Corrupt Block/Unknown Block Freed"

2. "Blocking and non-blocking" assignments

3. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

4. block.call vs. yield

5. Followup to "Fortran calling "c", and "c" calling Fortran

6. Smalllint reporting "Methods with full blocks"

7. "Blocks" in Java

8. Accessing a block's "receiver"

9. "BLOCK DATA" blues

10. threaded tcl "alloc: invalid block" errors

11. HELP - neighbors "block world"

12. Non-blocking Windows "exec"

 

 
Powered by phpBB® Forum Software