Interested in metaprogramming?

Hi, I have started writing a guide to metaprogramming called 'the way
of meta'. I have written only a draft intro and a simple example up
to now [1].

I wonder if there is much interest on the topic out there..
I have lots of material on metaprogramming and DSLs that I haven't
posted yet (still in a pretty raw format) and if I get a positive
response I'll start working on it and I will add it to the guide.

[1] http://liquiddevelopment.blogspot.com/2006/03/way-of-meta.html

···

--
Chiaroscuro
---
Liquid Development: http://liquiddevelopment.blogspot.com/

chiaro scuro wrote:

Hi, I have started writing a guide to metaprogramming called 'the way
of meta'. I have written only a draft intro and a simple example up
to now [1].

I wonder if there is much interest on the topic out there..

IMHO there definitely is.

I have lots of material on metaprogramming and DSLs that I haven't
posted yet (still in a pretty raw format) and if I get a positive
response I'll start working on it and I will add it to the guide.

OK, i begin: +1

Cheers,
Peter

Hi, I have started writing a guide to metaprogramming called 'the way
of meta'. I have written only a draft intro and a simple example up
to now [1].

I wonder if there is much interest on the topic out there..

I'm definitely interested in learning more about metaprogramming.

Mark

···

On Wednesday 19 April 2006 09:37, chiaro scuro wrote:

I have lots of material on metaprogramming and DSLs that I haven't
posted yet (still in a pretty raw format) and if I get a positive
response I'll start working on it and I will add it to the guide.

[1] Liquid Development: The Way of Meta

--
Chiaroscuro
---
Liquid Development: http://liquiddevelopment.blogspot.com/

I would definitely like to add my +1

Metaprogramming looks to be extremely useful and interesting, but not
always the easiest thing to wrap your brain around.

Regards,
Brett

···

On 4/19/06, chiaro scuro <kiaroskuro@gmail.com> wrote:

Hi, I have started writing a guide to metaprogramming called 'the way
of meta'. I have written only a draft intro and a simple example up
to now [1].

I wonder if there is much interest on the topic out there..
I have lots of material on metaprogramming and DSLs that I haven't
posted yet (still in a pretty raw format) and if I get a positive
response I'll start working on it and I will add it to the guide.

[1] Liquid Development: The Way of Meta

--
Chiaroscuro
---
Liquid Development: http://liquiddevelopment.blogspot.com/

Nice start
I fail to understand why tou define a method for each synonym though. Would
using method_alias instead not be a better choice?

Cheers
Robert

···

On 4/19/06, chiaro scuro <kiaroskuro@gmail.com> wrote:

Hi, I have started writing a guide to metaprogramming called 'the way
of meta'. I have written only a draft intro and a simple example up
to now [1].

I wonder if there is much interest on the topic out there..
I have lots of material on metaprogramming and DSLs that I haven't
posted yet (still in a pretty raw format) and if I get a positive
response I'll start working on it and I will add it to the guide.

[1] Liquid Development: The Way of Meta

--
Chiaroscuro
---
Liquid Development: http://liquiddevelopment.blogspot.com/

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

two people is already a crowd to me :slight_smile:

I'll let you know when I post more about metaprogramming and DSLs.

thanks for your interest.

···

On 4/19/06, Mark Somerville <mark@scottishclimbs.com> wrote:

On Wednesday 19 April 2006 09:37, chiaro scuro wrote:
> Hi, I have started writing a guide to metaprogramming called 'the way
> of meta'. I have written only a draft intro and a simple example up
> to now [1].
>
> I wonder if there is much interest on the topic out there..

I'm definitely interested in learning more about metaprogramming.

Mark

> I have lots of material on metaprogramming and DSLs that I haven't
> posted yet (still in a pretty raw format) and if I get a positive
> response I'll start working on it and I will add it to the guide.
>
> [1] Liquid Development: The Way of Meta
>
> --
> Chiaroscuro
> ---
> Liquid Development: http://liquiddevelopment.blogspot.com/

--
Chiaroscuro
---
Liquid Development: http://liquiddevelopment.blogspot.com/

the synonym is just an example, but it still serve a purpose, though.
alias clones a method, whereas synonym wraps it.
if the original method gets changed, synonym reflects this change,
whereas alias would ignore it.

···

On 4/19/06, Robert Dober <robert.dober@gmail.com> wrote:

On 4/19/06, chiaro scuro <kiaroskuro@gmail.com> wrote:
>
> Hi, I have started writing a guide to metaprogramming called 'the way
> of meta'. I have written only a draft intro and a simple example up
> to now [1].
>
> I wonder if there is much interest on the topic out there..
> I have lots of material on metaprogramming and DSLs that I haven't
> posted yet (still in a pretty raw format) and if I get a positive
> response I'll start working on it and I will add it to the guide.
>
> [1] Liquid Development: The Way of Meta
>
> --
> Chiaroscuro
> ---
> Liquid Development: http://liquiddevelopment.blogspot.com/
>
>
Nice start
I fail to understand why tou define a method for each synonym though. Would
using method_alias instead not be a better choice?

Cheers
Robert

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

--
Chiaroscuro
---
Liquid Development: http://liquiddevelopment.blogspot.com/

} two people is already a crowd to me :slight_smile:
}
} I'll let you know when I post more about metaprogramming and DSLs.

I only skimmed what you've written so far, but I noticed that you've used
class_eval. It is preferable to avoid any form of eval whenever possible.
In your post you can replace...

Array.class_eval do
  synonym :size => [ :count, :n_elements ]
end

...with...

Array.send(:synonym, :size => [ :count, :n_elements ])

...to avoid the class_eval.

} thanks for your interest.
[...]
} Chiaroscuro
--Greg

···

On Wed, Apr 19, 2006 at 06:31:47PM +0900, chiaro scuro wrote:

It is preferable to avoid any form of eval whenever possible.

Out of curiosity, why is this better?

--Meador

Hi --

···

On Wed, 19 Apr 2006, Gregory Seidman wrote:

On Wed, Apr 19, 2006 at 06:31:47PM +0900, chiaro scuro wrote:
} two people is already a crowd to me :slight_smile:
}
} I'll let you know when I post more about metaprogramming and DSLs.

I only skimmed what you've written so far, but I noticed that you've used
class_eval. It is preferable to avoid any form of eval whenever possible.
In your post you can replace...

Array.class_eval do
synonym :size => [ :count, :n_elements ]
end

...with...

Array.send(:synonym, :size => [ :count, :n_elements ])

...to avoid the class_eval.

I don't think instance_eval and class_eval, in their block forms, have
the same issues as plain eval(string). class_eval is really just a
closure cousin of the class keyword.

David

--
David A. Black (dblack@wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" PDF now on sale! Ruby for Rails
Paper version coming in early May!

Could not agree more but I am desperately looking for a way to replace this
which I use *very* often

class Mine
     eval <<-EOS
     def #{name}( value, &block )
           do_something( &block ) if block_given?
    end
   EOS
end
I'd *love* to do it with define_method, but I do not get around the "&block"
parameter.

Anybody help?

Thx
Robert

···

On 4/19/06, Gregory Seidman <gsslist+ruby@anthropohedron.net> wrote:

On Wed, Apr 19, 2006 at 06:31:47PM +0900, chiaro scuro wrote:
} two people is already a crowd to me :slight_smile:
}
} I'll let you know when I post more about metaprogramming and DSLs.

I only skimmed what you've written so far, but I noticed that you've used
class_eval. It is preferable to avoid any form of eval whenever possible.
In your post you can replace...

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

It's harder to get information on buggy eval-ed code than just plain code.

···

On 4/19/06, Meador Inge <meadori@gmail.com> wrote:

>It is preferable to avoid any form of eval whenever possible.
Out of curiosity, why is this better?

--Meador

--
Chiaroscuro
---
Liquid Development: http://liquiddevelopment.blogspot.com/

what about using define_method from ruby1.8.4 ? it also accepts a
block as argument..
alternatively it will look nicer to use the eval %{ .... } notation
than the HEREDOC.

if you use heredoc you coud do it this way, to convey the meaning that
the sting represents code:

  eval <<-CODE
                sdjifklsdnkdfksd
                dlòsdklòlòfsdòs
             CODE

···

On 4/19/06, Robert Dober <robert.dober@gmail.com> wrote:

On 4/19/06, Gregory Seidman <gsslist+ruby@anthropohedron.net> wrote:
>
> On Wed, Apr 19, 2006 at 06:31:47PM +0900, chiaro scuro wrote:
> } two people is already a crowd to me :slight_smile:
> }
> } I'll let you know when I post more about metaprogramming and DSLs.
>
> I only skimmed what you've written so far, but I noticed that you've used
> class_eval. It is preferable to avoid any form of eval whenever possible.
> In your post you can replace...

Could not agree more but I am desperately looking for a way to replace this
which I use *very* often

class Mine
     eval <<-EOS
     def #{name}( value, &block )
           do_something( &block ) if block_given?
    end
   EOS
end
I'd *love* to do it with define_method, but I do not get around the "&block"
parameter.

Anybody help?

Thx
Robert

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

--
Chiaroscuro
---
Liquid Development: http://liquiddevelopment.blogspot.com/

Could not agree more but I am desperately looking for a way to replace this
which I use *very* often

wait for 2.0

class Mine
     eval <<-EOS
     def #{name}( value, &block )
           do_something( &block ) if block_given?
    end
   EOS
end

moulon% cat b.rb
#!/usr/bin/ruby
class Mine
   define_method(:a) {|a, &b|
      do_something(a, &b)
   }
   def do_something(a)
      if block_given?
         yield a
      else
         puts "no block #{a}"
      end
   end
end

Mine.new.a(12) {|x| puts "block #{x}" }
Mine.new.a(24)
moulon%

moulon% ruby -v b.rb
ruby 1.9.0 (2006-04-08) [i686-linux]
block 12
no block 24
moulon%

Guy Decoux

what about using define_method from ruby1.8.4 ? it also accepts a
block as argument..

which is...
not the problem.
The problem is that the block -used to define the method- does not accept a
&block parameter for the method I want to define.
BTW it seems to me there was a post on this, but I failed to find it, sorry
if I am wasting bandwith.

Sorry if I was not clear on this.
Are we now chiari or still scuri?

Ciao

···

On 4/19/06, chiaro scuro <kiaroskuro@gmail.com> wrote:

>
> - Albert Einstein
>
>

--
Chiaroscuro
---
Liquid Development: http://liquiddevelopment.blogspot.com/

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

> Could not agree more but I am desperately looking for a way to replace
this
> which I use *very* often

wait for 2.0

Great, I just started

moulon% cat b.rb
#!/usr/bin/ruby
class Mine
   define_method(:a) {|a, &b|

                                        ^
                                         >
Here we go -----------------------+

      do_something(a, &b)

···

On 4/19/06, ts <decoux@moulon.inra.fr> wrote:

   }

Guy Decoux

Thank you, at lease I will stop trying in 1.8

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

quite chiari, but the answer is still scura :slight_smile:

I'd like to look into that but I've got to run to catch an airplane in
a few hours.

I'll look into it when I'm back if nobody has come up with an answer
by that time.

···

On 4/19/06, Robert Dober <robert.dober@gmail.com> wrote:

On 4/19/06, chiaro scuro <kiaroskuro@gmail.com> wrote:
>
> what about using define_method from ruby1.8.4 ? it also accepts a
> block as argument..

which is...
not the problem.
The problem is that the block -used to define the method- does not accept a
&block parameter for the method I want to define.
BTW it seems to me there was a post on this, but I failed to find it, sorry
if I am wasting bandwith.

Sorry if I was not clear on this.
Are we now chiari or still scuri?

Ciao

> >
> > - Albert Einstein
> >
> >
>
>
> --
> Chiaroscuro
> ---
> Liquid Development: http://liquiddevelopment.blogspot.com/
>
>

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

--
Chiaroscuro
---
Liquid Development: http://liquiddevelopment.blogspot.com/

define_method(:a) {|a, &b|

                                        ^
                                         >
Here we go -----------------------+

      do_something(a, &b)

Well you have also this

moulon% cat b.rb
#!/usr/bin/ruby
class Mine
   c = 24
   define_method(:a) {|a, &b; c|
      p a, b ,c
   }
end

Mine.new.a(12) {|x| puts "block #{x}" }

moulon%

moulon% ruby -v b.rb
ruby 1.9.0 (2006-04-08) [i686-linux]
b.rb:4: warning: shadowing outer local variable - c
12
#<Proc:0xb7e394e8@b.rb:9>
nil
moulon%

Guy Decoux

Ok let's all stop talking about ruby 1.8 it is too boring, just kidding.
Ty for the enlightment :wink:

Cheers
Robert

···

On 4/19/06, ts <decoux@moulon.inra.fr> wrote:

>> define_method(:a) {|a, &b|

> ^
> >
> Here we go -----------------------+

> do_something(a, &b)

Well you have also this

moulon% cat b.rb
#!/usr/bin/ruby
class Mine
   c = 24
   define_method(:a) {|a, &b; c|
      p a, b ,c
   }
end

Mine.new.a(12) {|x| puts "block #{x}" }

moulon%

moulon% ruby -v b.rb
ruby 1.9.0 (2006-04-08) [i686-linux]
b.rb:4: warning: shadowing outer local variable - c
12
#<Proc:0xb7e394e8@b.rb:9>
nil
moulon%

Guy Decoux

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein