Namespaces

6 views
Skip to first unread message

puzzler

unread,
Oct 13, 2009, 8:22:23 PM10/13/09
to enclojure
So I'm trying to get the REPL to "see" the variables and the functions
defined in my files, and I'm not having any luck. I have tried both
the IDE REPL and the standalone REPL, with no success.

Even weirder, when I try to change namespaces with in-ns, the REPL
ends up in a weird state that I can't seem to break out of (typing
anything causes an error about not being able to find eval).

Can someone please explain how namespaces interact with the Netbeans
projects, and give a concrete example of how to write functions that
are visible at the REPL?

Thanks.

Eric Thorsen

unread,
Oct 14, 2009, 9:41:23 AM10/14/09
to enclojure
Not sure what you mean when you say 'see' your functions. I'm
assuming you are either talking about the REPL having the functions
loaded in the JVM that the REPL is talking to or being seen by the
completion engine.
1. Loading code into the JVM
When you start a project REPL, it uses the classpath defined by the
project and it's dependancies to start a remote JVM, creates a REPL
window within the Netbeans instances and connects to the remote JVM
via a socket. At that point only the default Clojure code is loaded
and no code from the project is loaded. You can highlight a set of
files, right-click and load them. I also plan on having the ability
to load all files at the Project level. That will be in the next
release:
https://www.assembla.com/spaces/enclojure/tickets/21-Be-able-to-load-ALL-files-within-a-project-into-a-running-repl-with-a-single-command-
When I start a project REPL I'm usually interested in working on some
code in a particular file or starting up a new file. I start the
REPL, open the file and load it. Clojure will find any dependancies
and load them as well. At that point, assuming there are no errors,
you have your code and functions loaded and they can be 'seen' within
the REPL (connected to the remote JVM where the code was actually
loaded).
There are several hotkeys for loading code in the REPL which you can
get to and see the bindings by right-clicking in an edit window of a
Clojure source file.

2. Completion Engine
The completion engine currently works with static analysis of source
by using the (ns ...) node of the current file open in the editor to
load the context for completion at the REPL. It will work just like
the code in the editor meaning that:
:use, :require, :refer and any aliases will work exactly as they code
in the source.
Consider:
(ns org.enclojure.ide.repl.repl-manager
(:use org.enclojure.repl.main)
(:require [org.enclojure.commons.c-slf4j :as logger]
[org.enclojure.commons.validation :as validation]
[org.enclojure.ide.repl.repl-data :as repl-data])
(:import (java.util.logging Logger Level)
(java.io PipedOutputStream PipedInputStream LineNumberReader
InputStreamReader File)
(org.apache.commons.exec CommandLine ExecuteResultHandler
PumpStreamHandler DefaultExecutor ExecuteException
ExecuteWatchdog)))

Here all the symbols within the repl-manager file and
org.enclojure.repl.main will be available in the REPL for completion
with no qualification.
The namespaces in the :require are defined with aliases so they
require qualification...so for functions within
org.enclojure.commons.c-slf4j you would use:
logger/<func>

Also, any functions defined at the REPL prompt are 'visible'.

I was unable to reproduce any problems with 'in-ns.
You do have to be in front of the prompt in order to type anything in
the REPL. If you are behind it, there is no edit capability.

Let me know if this answers your questions.
Thanks,
Eric

Mark Engelberg

unread,
Oct 14, 2009, 7:49:19 PM10/14/09
to encl...@googlegroups.com
> I was unable to reproduce any problems with 'in-ns.
> You do have to be in front of the prompt in order to type anything in
> the REPL. If you are behind it, there is no edit capability.

OK, let me give the steps I do.
Start up Netbeans (it opens the skeleton clojure project I created).
Start a REPL (problem happens on either standalone or IDE REPL).
Type: (in-ns 'testing) [note that testing is NOT one of the
namespaces declared anywhere in my project]
Type (+ 1 2) [or any expression at all, it doesn't matter]

I get the message:
#<CompilerException java.lang.Exception: Unable to resolve symbol:
eval in this context (NO_SOURCE_FILE:9)>

Once in this state, I can't type anything without getting this error,
and I can't change the namespace back either. Speaking of which, how
do I completely kill/restart the REPL? When I close the window and
open it again, it seems to just resume where it left off.

Thanks for the explanation about the need to explicitly load files
into the REPL. I had just assumed that was done automatically, and
didn't see the context menu for doing it explicitly. I'll explore
that more. Is there a tutorial somewhere that I missed?

Thanks,

Mark

Eric Thorsen

unread,
Oct 19, 2009, 10:34:44 AM10/19/09
to enclojure
Mark,
This was perfect. I was able to reproduce right away. I've created a
ticket to address this:
https://www.assembla.com/spaces/enclojure/tickets/25-Problem-in-repl-when-(in-ns--not-yet-defined-namespace)-is-called
As a workaround you can simply call:
(ns testing)
Or if you are worried about trouncing on a previously defined ns:
(if (find-ns 'testing) (in-ns 'testing) (ns testing)))

"Speaking of which, how
do I completely kill/restart the REPL? "
There is a reset-repl button at the bottom of the toolbar. This will
reset the remote JVM which the REPL is connected to. You may want to
look at:
http://www.enclojure.org/Anatomy+of+the+Enclojure+Repl+Panel

Thanks again for the report,
Eric
Reply all
Reply to author
Forward
0 new messages