Screencast: Clojure + Emacs + slime + swank + cake + Overtone

476 views
Skip to first unread message

Sam Aaron

unread,
Jun 16, 2011, 11:16:23 AM6/16/11
to clo...@googlegroups.com
Hi there,

I just finished making a screencast primarily for new Overtone users on how to get set up with Emacs as a primary editor:

http://vimeo.com/25190186

It turns out that this should be pretty useful for Clojure hackers in general as it's really a screencast on how to set up a Clojure environment using Emacs slime, swank and cake. Just s/Overtone/your-project/

Of course, it's also great if you're interested in making music with programming languages :-)

Sam

---
http://sam.aaron.name

John Toohey

unread,
Jun 17, 2011, 3:21:38 PM6/17/11
to clo...@googlegroups.com
Excellent screencast.

> --
> 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

--
~JT

looselytyped

unread,
Jun 19, 2011, 4:33:54 PM6/19/11
to Clojure
Agreed. This is a very informative screencast.

Thanks Sam.

Raju

Lee Spector

unread,
Jun 21, 2011, 11:09:04 PM6/21/11
to clo...@googlegroups.com

Sam,

Thanks so much for this. It's quite nice and it worked for me almost without a glitch (the one glitch being that I had to move a pre-existing .emacs to prevent an error). If I could be excused for briefly looking a gift horse in the mouth I'd also say that as a teacher I think it would be even more fabulous if someone could put together packages (presumably platform-specific packages) that allowed one to do this all in one or two steps, rather than five or six... Installing all of the pieces in one automated process, and also adding the needed lines to the project.clj files etc. Users will want to update/tweak these later, but in the same spirit of this overall package I think it'd be nice to have something that works by default with as few steps as possible. In any event, I do think that this is already quite a nice advance.

I have two (related?) questions about working in a REPL in the resulting configuration:

- When I have a split screen with a source file and a REPL I can't seem to get the REPL into the namespace of the source file. I can do C-c C-k to evaluate the file and that produces overtone output as expected (and printed output goes to the REPL), but when I then try to do (in-ns overtoneproject.core) in the REPL [overtoneproject.core is the name I used in the ns form in the file] I get a ClassNotFoundException.

- I also can't get (load "core"), or any variant that I could think of, when typed in the REPL to find the file. When I look at the classpath with (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader))) I see some of my project's files there, so it "knows" about the project, but it doesn't find my file in the src directory that cake created.

Any pointers would be appreciated.

Thanks,

-Lee


lambdatronic

unread,
Jun 23, 2011, 10:08:10 AM6/23/11
to Clojure
Lee,

You're just making a simple typo. To get the REPL to switch to the
source file's namespace, you have several options:

1) With the point in the source file, press C-c M-p <ENTER>

2) With the point in the REPL, type ,in <ENTER> overtoneproject.core
<ENTER>

3) With the point in the REPL, type (in-ns 'overtoneproject.core)

Your mistake was to not quote overtoneproject.core, which made the
clojure compiler look up the value of the symbol as a Java class
(which it isn't unless you added a :gen-class to the ns form). By
quoting it, in-ns gets the symbol overtoneproject.core, which is what
it uses to look up namespaces:

clojure.core/in-ns
([name])
Sets *ns* to the namespace named by the symbol, creating it if
needed.

Happy hacking,
~Gary

Lee Spector

unread,
Jun 23, 2011, 10:24:54 AM6/23/11
to clo...@googlegroups.com

Thanks so much, Gary. The quoting error is something that I should have seen but didn't :-(, and the two other methods are also great to know about.

I'm still having no luck getting "load" to find things, but I suspect that that is a similarly basic mistake...

-Lee

On Jun 23, 2011, at 10:08 AM, lambdatronic wrote:

> Lee,
>
> You're just making a simple typo. To get the REPL to switch to the
> source file's namespace, you have several options:
>
> 1) With the point in the source file, press C-c M-p <ENTER>
>
> 2) With the point in the REPL, type ,in <ENTER> overtoneproject.core
> <ENTER>
>
> 3) With the point in the REPL, type (in-ns 'overtoneproject.core)
>
> Your mistake was to not quote overtoneproject.core, which made the
> clojure compiler look up the value of the symbol as a Java class
> (which it isn't unless you added a :gen-class to the ns form). By
> quoting it, in-ns gets the symbol overtoneproject.core, which is what
> it uses to look up namespaces:
>
> clojure.core/in-ns
> ([name])
> Sets *ns* to the namespace named by the symbol, creating it if
> needed.
>
> Happy hacking,
> ~Gary
>
> On Jun 21, 11:09 pm, Lee Spector <lspec...@hampshire.edu> wrote:
>> On Jun 16, 2011, at 11:16 AM, Sam Aaron wrote:
>>
>>> I just finished making a screencast primarily for new Overtone users on how to get set up with Emacs as a primary editor:
>>
>>> http://vimeo.com/25190186
>>>
>>
>>

Lee Spector

unread,
Jun 23, 2011, 7:55:43 PM6/23/11
to clo...@googlegroups.com

I wrote (below) about being unable to get "load" to work from the slime repl after completing the emacs/cake/swank/slime setup that Sam presented in helpful video.

Now I think it's a more general problem of not setting the classpath correctly. If I try to :use something in the ns form in a file, for which I have a .clj file in the same directory as the core.clj that cake created, then when I evaluate the buffer in emacs the required file is not found.

How and where do I set up the classpath so that this will work (using emacs/cake/swank/slime)? If possible I'd like to set it up so that it always finds anything anywhere in the cake project directory, including .clj files in src/.

Thanks,

-Lee


>> On Jun 21, 11:09 pm, Lee Spector <lspec...@hampshire.edu> wrote:
>>> On Jun 16, 2011, at 11:16 AM, Sam Aaron wrote:
>>>
>>>> I just finished making a screencast primarily for new Overtone users on how to get set up with Emacs as a primary editor:
>>>
>>>> http://vimeo.com/25190186
>>>>
>>>

lambdatronic

unread,
Jun 24, 2011, 4:11:26 PM6/24/11
to Clojure
The way that cake and lein behave is generally this:

1) Search up the file tree starting from the directory in which cake
or lein is called until a project.clj file is encountered. Consider
this to be the project root.

2) Start a JVM in this directory with the classpath set to contain any
files in src or lib.

When you are starting a new library, place it under the src directory
of your project. Then give it a namespace name in the ns form that
corresponds to its position beneath src, using . as a directory
separator.

So if your project file tree looks like this:

|-- LICENSE
|-- build
|-- classes
|-- lib
| |-- byte-spec-0.2.0-20100821.141701-1.jar
| |-- clojure-1.2.0.jar
| |-- clojure-contrib-1.2.0.jar
| |-- deps.clj
| |-- java-osc-cvs-20100502.112537-4.jar
| |-- jna-3.2.4.jar
| |-- midi-clj-0.2.0-20100821.141701-1.jar
| |-- miglayout-3.7.3.1.jar
| |-- osc-clj-0.3.0-20101217.045604-1.jar
| |-- overtone-0.1.5.jar
| |-- scsynth-jna-0.1.2-20100502.112537-1.jar
| `-- vijual-0.2.1.jar
|-- pom.xml
|-- project.clj
|-- src
| `-- overtone_test
| `-- core.clj
`-- test

Then your core.clj file should begin with an ns form like this:

(ns overtone-test.core
(:use [overtone.live]
[overtone.inst.synth]))

At compile-time, the Clojure compiler will look for your libraries
beneath your classpath (as established by lein or cake in the way I
described above) with names like overtone/live.clj and overtone/inst/
synth.clj.

And that, as they say, is that.
~Gary

Lee Spector

unread,
Jun 24, 2011, 4:50:30 PM6/24/11
to clo...@googlegroups.com

Thanks Gary. With this I'm able to get :use to work correctly -- FWIW the part I wasn't getting right (again :-() was the association between the namespace names and the directory structure. In the context of your example I was doing something like (ns core ...) rather than (ns overtone-test.core ...), for a file in the same location. I now see that I can name it just core (or whatever I want) if I put it up one level, just in src/ rather than in src/overtone-test. FWIW I've been down a similar path and figured out something about the namespace/directory structure mapping before, in the context of some other tools, but forgot... I guess I still don't find this very intuitive.

One thing that I'd like to know more about: when you say "Start a JVM in this directory with the classpath set to contain and files in src or lib" I'm not 100% sure that I know how you mean to do that. I am starting a JVM in that directory by saying "cake swank", and this seems to work now that I have the namespace names and file locations matched up. But how? Is the classpath being set to contain files in src and lib automatically by cake? Where does one specify this? It's not in my project.clj or anywhere else that I see. So even though it's currently working it still seems mysterious.

BTW also I still can't seem to get "load" to work... it never seems to find the files.... I'd sort of like to know how to do that, to help dispel more of the foggy classpath mysteries, but I guess that now that I can get :use to work I can have a reasonable workflow one way or another.

-Lee

Lee Spector

unread,
Jun 24, 2011, 4:56:05 PM6/24/11
to clo...@googlegroups.com

Oops: Ignore my last "BTW" -- now load works for me too. Not sure why it didn't previously. I'd still like to know where it is specified that src and lib are on the classpath, but I guess I have everything working now.

Thanks,

-Lee

lambdatronic

unread,
Jun 26, 2011, 4:30:33 PM6/26/11
to Clojure
The classpath is specified in the lein and cake scripts respectively.
lein is a shell script, and cake is a ruby script, so pop them open in
your favorite text editor and take a look.

~Gary

Lee Spector

unread,
Jun 26, 2011, 5:01:58 PM6/26/11
to clo...@googlegroups.com

Ah. Non-obvious, but now I'm beginning to see how this works -- I found and looked into the cake script.

Thanks!

-Lee

> --
> 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

--
Lee Spector, Professor of Computer Science
Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspe...@hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438

Reply all
Reply to author
Forward
0 new messages