From: Cody Brocious <cody.brocious@gmail.com>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:25571] Implicit block argument in Procs
Date: Mon, 14 Sep 2009 18:57:14 +0900 [thread overview]
Message-ID: <4987c3660909140257g58c1f6e3keba9e312020a4a89@mail.gmail.com> (raw)
I ran into some block behavior I thought was a bit odd. Calling a
Proc (via .call or any other means) with a block causes the block to
be silently dropped unless the Proc has an explicit block argument.
This occurs even when taking a block as an explicit argument to
another method and then calling that Proc. Below is a small bit of
code which shows the issue in two ways:
# Raw Proc
proc = Proc.new { |&block|
block.yield
}
proc.call {
puts 'test'
}
# 'Block' Proc
def set(&block)
$block = block
end
set {
yield
}
$block.call {
puts 'test'
}
From a quick glance at the source (specifically proc.c), the issue
seems to be that in proc_call() there's the following line:
if (BUILTIN_TYPE(iseq) == T_NODE || iseq->arg_block != -1) {
Inside of that block the code that handles block passing. The
iseq->arg_block != -1 check seems to prevent passing blocks unless
they're explicitly named.
Is this behavior intentional? If not, is there a limitation in
rb_vm_invoke_proc() which makes passing an implicit block a problem?
It seems that killing the arg_block check would solve the issue if
there's no problem in rb_vm_invoke_proc().
Thanks,
- Cody Brocious
next reply other threads:[~2009-09-14 9:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-14 9:57 Cody Brocious [this message]
2009-09-14 10:07 ` [ruby-core:25572] Re: Implicit block argument in Procs Nobuyoshi Nakada
2009-09-14 10:13 ` [ruby-core:25573] " Cody Brocious
2009-09-15 12:28 ` [ruby-core:25601] " Nobuyoshi Nakada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4987c3660909140257g58c1f6e3keba9e312020a4a89@mail.gmail.com \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).