On Thu, 27 Apr 2006, Joel VanderWerf wrote:

>
> I'm really confused about the rest of the examples (it looks to me like
> task uidgen is sometimes acting as a "singleton service" and sometimes
> as a "parametric service"), but I think I understand this one:

yes.  basically what i'm showing is that by implementing the tsort on top of a
cache it fails if any task is called from outside the dependancy graph it can
potentially break the call chain.  make sense?

> This means that we are just using different code :)
>
> Here's mine (pls. excuse the module_eval string argument, it is very old
> code), with a stripped down version of T's task code:
>
> module Task
>  def cache(method_name)
>    module_eval %{
>      alias :__compute_#{method_name} :#{method_name}
>      def #{method_name}
>        if @#{method_name}_cached
>          @#{method_name}
>        else
>          @#{method_name}_cached = true
>          @#{method_name} = __compute_#{method_name}
>        end
>      end
>    }
>  end
>
>  def task( args, &action )
>    if Hash === args
>      raise ArgumentError, "#{args.size} for 1" if args.size != 1
>      name, *deps = *(args.to_a.flatten)
>      name = name.to_sym
>      deps = deps.compact.collect{ |e| e.to_sym }
>    else
>      name, deps = args.to_sym, []
>    end
>
>    (@task_dependencies||={})[ name ] = deps
>
>    (class << self; self; end).class_eval do
>      define_method( name ) do
>        deps.each{ |d| send(d) }
>        action.call if action
>      end
>      cache name
>    end
>  end
> end
>
> include Task
>
> task :b => :a do puts "b" end
> task :a => :b do puts "a" end
>
> b()

ah.  i see.  that a bit limiting though eh?  we can't even have tasks like
this then

   task :c do |path| IO.read(path) end

or, if we could, the caching would break.

essentially what i was saying is that if your caching is more general, meaning
it's also based on method arguments, and you sort implicitly by relying on
such a cache, the call graph explodes if any code anywhere calls a task
externally or internally with the arguments that cause a collision in the
cache hash.  maybe i'm making it too hard but it seems like an unreasonable
constraint that tasks cannot call other tasks outside the auto-derived
dependancy graph.

anyhow - i think trans' point was that this is interesting and there i think
we all agree.

cheers.

-a
-- 
be kind whenever possible... it is always possible.
- h.h. the 14th dali lama