Evaling forms that require

8 views
Skip to first unread message

Phil Hagelberg

unread,
Sep 30, 2010, 1:31:50 AM9/30/10
to clo...@googlegroups.com
The following form fails in Clojure 1.0, but was fixed in 1.1:

(eval '(do (require 'clojure.inspector) clojure.inspector/inspect))

It used to fail because it tried to compile the whole quoted form, but
it couldn't compile the inspect reference because the require hadn't
been run yet. I think it's great that it works in 1.1, but I'm boggled
as to how it works. Does the compiler split apart certain forms like
do and compile/run each form separately? It seems like it wouldn't be
possible to make this work without multiple passes, but I'm curious
how it's done.

-Phil

Laurent PETIT

unread,
Sep 30, 2010, 2:02:18 AM9/30/10
to clo...@googlegroups.com


2010/9/30 Phil Hagelberg <ph...@hagelb.org>

Yes, "do" is given special treatment, I've meet this part of code a while back. It basically just is converted into as many eval() as there are exprs in the do.
 

-Phil

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Phil Hagelberg

unread,
Sep 30, 2010, 11:57:20 AM9/30/10
to clo...@googlegroups.com
On Wed, Sep 29, 2010 at 11:02 PM, Laurent PETIT <lauren...@gmail.com> wrote:
>> The following form fails in Clojure 1.0, but was fixed in 1.1:
>>
>>    (eval '(do (require 'clojure.inspector) clojure.inspector/inspect))
>
> Yes, "do" is given special treatment, I've meet this part of code a while
> back. It basically just is converted into as many eval() as there are exprs
> in the do.

Fascinating; thanks.

It's a shame that forms with implicit "do" don't get treated
similarly, but I suppose that's a sidetrack for which it would be very
difficult to get all the edge cases for very little gain.

(eval '(when true (require 'clojure.inspector) clojure.inspector/inspect))

Exception in thread "main" java.lang.ClassNotFoundException:
clojure.inspector (core.clj:6)

-Phil

Laurent PETIT

unread,
Sep 30, 2010, 2:01:24 PM9/30/10
to clo...@googlegroups.com
There it is : http://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L5984

The magic only happen for dos which are top level forms

2010/9/30 Phil Hagelberg <ph...@hagelb.org>

-Phil

Reply all
Reply to author
Forward
0 new messages