On Tue, 2006-05-02 at 09:52 +0900, chiaro scuro wrote:
> And it is a bit whimsical.. can you think of a better word than "the" for a
> DSL?
> 

Hmm, not really. I guess if you really have to have the superfluous
(from the user point of view) word in there, you might add a new layer
of madness and do:

require 'facet/binding'

def shopping_list recipe = nil
  return Binding.of_caller {|b|b} unless recipe
  shopping_binding = yield
  ingredients = {}
  eval("local_variables" , shopping_binding).each do |var|
    ingredients[var] = eval "#{var}" , shopping_binding
  end
  report recipe, ingredients
end

shopping_list "banana milkshake" do
  milk = 1
  bananas = 2
shopping_list end

which is longer, but less whimsical IMHO.

(Btw another problem with this approach is that it plays havoc with
vim-ruby's auto indentation :( )

> On 5/2/06, Ross Bamford <rossrt / roscopeco.co.uk> wrote:
> >
> > On Tue, 2006-05-02 at 09:27 +0900, chiaro scuro wrote:
> > > Not sure about the ATs. even if I don't mind them that much... if I
> > unfocus
> > > my eyes they look like bullet points ;-)
> > >
> > > I have got this one working.. see if you can guess how..
> > >
> > > recipe "eggs and bacon" do
> > >   eggs = [2,:big]
> > >   bacon = 3
> > > the end
> > >
> > > I posted my solution here:
> > >
> > http://liquiddevelopment.blogspot.com/2006/04/way-of-meta-part-iv-hijacking-local.html
> > >
> >
> > Without looking, I'd guess def the; binding; end ? (Quick look, done
> > with alias, same difference I guess).
> >
> > It's a clever solution but it'd make the DSL sound a bit whimsical for
> > my taste. Plus, I'd be either forgetting to put 'the' or resenting that
> > I had to... :)
> >
> > Also, I think it might give unexpected results in some situations, e.g:
> >
> > some_other_var = :oops
> >
> > shopping_list "english breakfast" do
> >   tomatoes = 2, :green
> >   sausages = 3
> >   eggs = 2, :big
> >   bacon = 4
> > the end
> >
> > shopping_list "banana milkshake" do
> >   milk = 1
> >   bananas = 2
> > the end
> >
> > Gives output:
> >
> > to make english breakfast you should buy:
> > * 2 green tomatoes
> > * 3 sausages
> > * oops some_other_var
> > * 4 bacon
> > * 2 big eggs
> >
> > to make banana milkshake you should buy:
> > * 2 bananas
> > * 1 milk
> > * oops some_other_var
> >
> > Granted in a DSL this is less likely to occur, but guaranteed to leave
> > users scratching their heads if (when?) it does. Generally I prefer if I
> > can preserve normal, predictable behaviour for those times when you (or
> > some power user of your system) might need it.
> >
> > --
> > Ross Bamford - rosco / roscopeco.REMOVE.co.uk
> >
> >
> >
> 
> 
> --
> Chiaroscuro
> ---
> Liquid Development: http://liquiddevelopment.blogspot.com/
> 
> --
> This email has been verified as Virus free
> Virus Protection and more available at http://www.plus.net
-- 
Ross Bamford - rosco / roscopeco.REMOVE.co.uk