"compile" vs. "call"

12 views
Skip to first unread message

Dr. Ernie

unread,
Dec 18, 2009, 2:20:04 PM12/18/09
to Guardians of the Temple
> A compiler is simply a class which has a method called #compile which takes one arguments.

> Very much like you have middlewares in Rack, you use compilers in Temple (except everything is a compiler in Temple):

So, let me ask the obvious question: why not be like rack and name the
method "call", so we can uses lambdas as compilers?

That would also avoid some of the semantic confusion around using the
term "compile" for parsers and generators.

Thoughts?

-- Ernie P.

Magnus Holm

unread,
Dec 18, 2009, 3:18:03 PM12/18/09
to guardians-o...@googlegroups.com
Good points. The naming is a bit unfortunately, but (of course) makes
totally sense in my head :P

Currently a compiler has to be a class, so you can't really use a
lambda. I think, the only reason for this is because I prefer the
options in the initialize-method ("use C, :foo => :bar" == "C.new(:foo
=> :bar)", but maybe we could support both, like:

if C.is_a? Class
C.new(:foo => :bar).call(str)
elsif C.respond_to?(:compile)
C.call(str, :foo => :bar)
else
raise "IMMA LET YOU FINISH, BUT ERUBIS IS THE GREATEST COMPILER OF ALL TIME"
end


//Magnus Holm

Ernest Prabhakar

unread,
Dec 18, 2009, 3:24:26 PM12/18/09
to guardians-o...@googlegroups.com
Hi Magnus,

On Dec 18, 2009, at 12:18 PM, Magnus Holm wrote:
> Good points. The naming is a bit unfortunately, but (of course) makes
> totally sense in my head :P
>
> Currently a compiler has to be a class, so you can't really use a
> lambda. I think, the only reason for this is because I prefer the
> options in the initialize-method ("use C, :foo => :bar" == "C.new(:foo
> => :bar)", but maybe we could support both, like:
>
> if C.is_a? Class
> C.new(:foo => :bar).call(str)
> elsif C.respond_to?(:compile)
> C.call(str, :foo => :bar)
> else
> raise "IMMA LET YOU FINISH, BUT ERUBIS IS THE GREATEST COMPILER OF ALL TIME"
> end

Okay, I'm showing my ignorance here, but how does Rack handle this? Does it accept instances or classes?

-- Ernie P.

Magnus Holm

unread,
Dec 18, 2009, 3:36:20 PM12/18/09
to guardians-o...@googlegroups.com
Rack handles middlewares and endpoints differently (or not really, but
they are different concepts).

First of all: An endpoint (aka. application) is just a object.respond_to?(:call)

Middlewares are just a convention where you set
Middleware.new(prev_endpoint) as your endpoint. If Middleware has a
#call, it will look exactly as an endpoint to a Rack server/handler,
and it doesn't have to worry about that it's a middleware at all.

In Temple however, we only send output from one compiler as input to
another compiler. Since input/output is the "same" thing, while a
request/response in Rack are completely different.

I'm definitely in for renaming the word "compiling" if it seems to
confuse people though. But, it might actually be a good thing to teach
people that a compiler really isn't magic at all, but only something
which takes some input and generates some output.

//Magnus Holm

Magnus Holm

unread,
Jan 4, 2010, 11:02:59 AM1/4/10
to Guardians of the Temple
Hm… Maybe #process is a better name. That's what SexpProcessor and
friends uses (ParseTree, Unifier, Ruby2Ruby etc.)
Reply all
Reply to author
Forward
0 new messages