Skip to content


Subversion checkout URL

You can clone with
Download ZIP


want access to arguments within the block of a macro #136

HamletDRC opened this Issue · 4 comments

3 participants


I'd like to provide a String.eachChar method that expands out and lets
you execute a block for each char in the String.
My first revision is this:
macro def eachChar(value, &block)
quote {
value.toCharArray.each do | my_char |
eachChar('laat de leeeuw niet in zijn hempie staan') do | my_char |
puts my_char
This works... but only because the block parameter is called "my_char"
and the macro references the same "my_char" parameter name.

I want Mirah to provide a way to lookup the "my_char" parameter name and bind it into the macro.


I think what we really want here is to be able to do:

macro def each_char &block
  quote { toCharArray.each `block` }

I can imagine someone wanted access to the parameters though. For instance, maybe someone wants to modify the parameters somehow. How does Lisp solve this?


I don't know how Lisp deals with this.

You can access the params AST nodes through Block#args. So, in theory--it doesn't work currently--, you could do something like

quote do
   something_that_takes_a_block do |`block.args`|
    puts "Hey"

args is an AST::Arguments node, so you can get it's children etc.


Is there a resolution for this? I'd like to generate unit tests based on a pattern, and need access to the parameters just like Hamlet describes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.