hello world question !!!

463 views
Skip to first unread message

Damien Mattei

unread,
Oct 13, 2017, 10:22:06 AM10/13/17
to Clojure
hello,

i'm new to clojure, just installed it on a CentOS box,

and try to compile the code below from tutorial, but it does not work, i searched a lot before posting, no answer... i do not want to use leiningen at this stage,later perheaps...

just want to compile and run

user=> (ns clojure.examples.hello
    (:gen-class))
nil
clojure.examples.hello=>
clojure.examples.hello=> (defn -main
  [greetee]
  (println (str "Hello " greetee "!")))
#'clojure.examples.hello/-main
clojure.examples.hello=> (compile 'clojure.examples.hello)
FileNotFoundException Could not locate clojure/examples/hello__init.class or clojure/examples/hello.clj on classpath:   clojure.lang.RT.load (RT.java:443)

help greatly appreciated (because i'm just one step to leave Clojure and continue using  Kawa or Bigloo i already use or dive into ABCL , but Clojure has a so good reputation, i cannot imagine being sticked here by a simple hello world!)

damien

James Reeves

unread,
Oct 13, 2017, 10:48:40 AM10/13/17
to clo...@googlegroups.com
Maybe this is a dumb question, but do you have a file "clojure/examples/hello.clj" on the classpath? Since that's what the exception is complaining about.

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
James Reeves

Justin Smith

unread,
Oct 13, 2017, 11:29:39 AM10/13/17
to clo...@googlegroups.com

To pedantically specific, clojure compiles all of your coffee to be code in memory, but the 'compile' function expects to find a file on disk, and create a class file on disk. Using gen-class in the repl is a no-op.



For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
James Reeves

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

For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.

Justin Smith

unread,
Oct 13, 2017, 11:30:53 AM10/13/17
to clo...@googlegroups.com

Sorry for the auto correct fail, it compiles all of your code to byte-code

Damien Mattei

unread,
Oct 13, 2017, 1:13:32 PM10/13/17
to Clojure
i did not have , i just follow the tutorial:
https://clojure.org/reference/compilation
i made the file but still the same problem:

[mattei@moita ~]$ export CLASSPATH=.:./clojure/examples
[mattei@moita ~]$ clojure
Clojure 1.5.1
user=> (compile 'clojure.examples.hello)

FileNotFoundException Could not locate clojure/examples/hello__init.class or clojure/examples/hello.clj on classpath:   clojure.lang.RT.load (RT.java:443)
user=> ^C[mattei@moita ~]$

[mattei@moita ~]$ cat clojure/examples/hello.clj
(ns clojure.examples.hello
    (:gen-class))


(defn -main
  [greetee]
  (println (str "Hello " greetee "!")))


For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
James Reeves

Justin Smith

unread,
Oct 13, 2017, 1:23:24 PM10/13/17
to Clojure
paths have to reflect the package and be relative to the class path, so if "clojure/examples" is on the classpath, and the namespace is clojure.examples.hello, the file needs to be in "clojure/examples/clojure/examples/hello.clj"

Justin Smith

unread,
Oct 13, 2017, 1:24:58 PM10/13/17
to Clojure
also you don't need to do any of this for a basic example, you can just type code into the repl and run it, or create a proper project with a dependency manager when you want something more organized

Andy Fingerhut

unread,
Oct 13, 2017, 1:37:08 PM10/13/17
to clo...@googlegroups.com
Just a note that at the top of the documentation page you mention, it says: "Clojure compiles all code you load on-the-fly into JVM bytecode, but sometimes it is advantageous to compile ahead-of-time (AOT)."

I would venture an estimate that most people who use Clojure do so without using AOT compilation.  Many would advocate against using AOT compilation, unless you are in a particular situation that requires it.

Andy


For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.

Damien Mattei

unread,
Oct 13, 2017, 1:55:07 PM10/13/17
to Clojure
yes i had tested . (point) in classpath and later added clojure/example which is not a good idea as the namespace is already clojure.examples.hello, already clojure.examples will be converted in clojure/examples but what must i do then? where must i put this hello.clj:
(ns clojure.examples.hello
    (:gen-class))

(defn -main
  [greetee]
  (println (str "Hello " greetee "!")))

to compile it with this command:

[mattei@moita ~]$ clojure
Clojure 1.5.1
user=> (compile 'clojure.examples.hello)

for example in Kawa i put this in a Scheme class file:
(module-name "eu.oca.kawafunct.Counter")

and the class is compiled in
eu/oca/kawafunct

what will be the good CLASSPATH so ?

Damien Mattei

unread,
Oct 13, 2017, 2:05:32 PM10/13/17
to Clojure
but i am in this situation, i wrote application in Scheme (Kawa,Bigloo) ,LisP that ran on an apache tomcat server, the application is deplyed in war files , they are precompiled ,with Kawa or Bigloo Scheme, and also use regular Java class compiled with Java8.
They never ran in REPL ,all the test and debug must be done on the host that run tomcat web server in Java 8, here is the site : https://sidonie.oca.eu/ 

James Reeves

unread,
Oct 13, 2017, 3:12:55 PM10/13/17
to clo...@googlegroups.com
The docstring for compile says that "The source for the lib must be in a proper
classpath-relative directory", so unfortunately you can't just create the namespace in the REPL and compile it from there. The tutorial on the Clojure site doesn't make that as clear as it could be.

In your revised example, you're setting the classpath incorrectly. The classpath should contain the root of your file tree. For example, if you have the file path "src/clojure/examples/hello.clj", then the classpath should be set to "src".

I'm not sure how the "clojure" script you're running works, but you might find Leiningen to be a better starting point. In Clojure 1.9, an official "clj" script is going to be introduced, which might make this process easier. Until then, Leiningen is probably the safer bet.


For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
James Reeves

Andy Fingerhut

unread,
Oct 13, 2017, 4:13:24 PM10/13/17
to clo...@googlegroups.com
I haven't deployed an application written in Clojure to a server as a WAR file before, so can't speak from experience, but I am sure others here probably can.  Hey, others, have you deployed a Clojure application via a WAR file without using AOT compilation, with only Clojure source code packaged in the WAR file?  Is that something that works?

Andy


For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.

Damien Mattei

unread,
Oct 13, 2017, 5:06:12 PM10/13/17
to Clojure
@james
i also try to set the CLASSPATH at src but it does noot work, i will try Leiningen monday
Regards,

Damien

Damien Mattei

unread,
Oct 13, 2017, 5:22:11 PM10/13/17
to Clojure
@andy
to deploy the WAR file , i also use Netbeans to create it with java files, the .scm scheme, files are .class files ( https://github.com/damien-mattei/Jkawa/tree/master/eu/oca/kawafunct )precompiled with Kawa scheme ( https://github.com/damien-mattei/Jkawa )and ,Bigloo scheme ( https://github.com/damien-mattei/Jbigl )compilers to JVM byte code and after packaged in .jar files , also i need to add the runtime library of each language, one for kawa and another for bigloo, they must be packaged in .jar files (not .zip) also;  i have a draft that explain this:
https://sidonie.oca.eu/Sidonie/technical-doc.html
i almost sure that if i got some clojure source file that i can compile it to JVM .class files and make .jar files of them they can be exported in a .war files as a library in my Netbeans project the way it was for Kawa and Bigloo, if clojure use a runtime library (and i suppose it's yes) this library should be packaged in a.jar file and add also in the .war file

John M. Switlik

unread,
Oct 13, 2017, 7:59:03 PM10/13/17
to Clojure
Damien, 

This is just an aside. Thanks for the question. 

I have not even tried Clojure, yet. So, this is good for me to follow. BTW, I have done Java (since the '90s) and so know of the 'coffee' stains everywhere. Yet, given the Lisp basis, I want to see how to make Clojure easier for the causal user. In fact, I got engineers to use Lisp (it was easy); I know of a whole category that don't want to cowboy code; to me, Clojure looks like a natural fit. Too, I am also now aware of serious Clojure work and successes. 

Already, I am thinking that I will have to have my developers and their user's systems call out to a server (various options) where my developers control all of that. But, I do not want to get ahead of things. Paying for the delay will be worth avoidance of the 'jar-like' issues. Again, not jumping ahead. But, Python was so easy to install. 

And so, I'm creating a basis (control, if you would). Take JavaScript (please). With only SeaMonkey (and its Composer), in about an hour, I coded a system that I had thought about, for a while. Write the code in Composer; re-load the file in the browser. With no IDE, it got tedious, as there is no feedback. But there are ways to handle the strain (decades of development work). We have become too IDE dependent. Of course, Emacs is there, but I am trying to target the occasional, and very much casual, developer (a very large class) with something other than toy stuff. 

I have a couple more to do; all of these will be matched against Clojure when the ducks get in order. Of course, the comparison will be with using Clojure as a frontend extension. 

Yet, the ease was that great. Code JavaScript; load the file (having split the JavaScript into a js file - one could embed the code in the HTML). I had to install nothing (except SeaMonkey to get its little editor). I did grab some time by using those interpreter windows at the tutorial sites. Nice feature. You code and modify. Just remember to pull the text down to your file. 

Wait! Yes, I did do that at one of the Clojure tutorial sites. Wrote my own stuff and tried it out. 

There are different hats to be worn for admin versus coding versus knowing how parameter mixes match up. 

When you get this settled, will you summarize for us newbies? 

James Gatannah

unread,
Oct 13, 2017, 11:38:15 PM10/13/17
to Clojure
This is really "just" a +1 for using Leiningen.

TL;DR: Just start with `lein new app hello-world` and get an editor integrated with your REPL quickly. Come back to these sorts of things later, if/when you still think they're worthwhile.

I came to clojure from the python/c++ world, with just enough common lisp to know that I really wanted to understand how this all works.

And just enough java to know that I never wanted to learn about CLASSPATH.

This sort of thing kept me from giving clojure a serious chance for at least a year or two. The only reason I kept trying was that I kept hearing such good things about it from people who seemed like they'd put in enough time and effort to have good, solid opinions.

Leiningen was the secret sauce that finally let me quit worrying about the java nonsense that I just didn't want to care about so I could start poking away at the language to see if I could find ways to bend it to my will.

Both of those attitudes were wrong. The "java nonsense" is one (many?) of the best parts, though it took me a long time to realize that (and lots of it *are* hard to swallow). And it was more a matter of me learning a better way to program than any amount of getting clojure to work the way I wanted/expected.

I think it's a little sad that setting up a toy project is this painful. Then again, clojure really isn't *for* toy projects.

Regards,
James

James Gatannah

unread,
Oct 13, 2017, 11:44:51 PM10/13/17
to Clojure
It's been a couple of years, but (from what I remember) it works great.

Immutant (or maybe it's wildfly?) has an option to deploy "exploded .WAR files." 

I'm very fuzzy on the details, but it seems like the basic choices were either:
1) deploy an uberwar with AOT (advantage: faster startup time)
2) deploy the exploded version, which was really the source tree. This approach let you update the .clj files on the fly.

We had problems with the AOT version. I think they stemmed from library version conflicts, but it's been long enough that I can't swear to it.

Alan Moore

unread,
Oct 13, 2017, 11:55:24 PM10/13/17
to Clojure
Lolz, I actually liked the coffee to code autocorrect... the autocorrect machine learning algorithm was probably trained on the old joke about that very thing. Thanks for the laugh after the week I’ve endured...

Alan

John M. Switlik

unread,
Oct 14, 2017, 11:07:08 AM10/14/17
to clo...@googlegroups.com
James, 

Thanks. I saw a writeup mentioning Leiningen that I will go back to. 

It is not the 'toy' issue that concerns me. It is that all sorts of browsers exist as well as a whole slew of different types of users. And, if I am going to push something down to a remote device, I want to expect that it would be handled in a nice manner. 

As for example projects, these are prime; but, they are supported by working professionals. So, Clojure does have a lot to offer. 


I am sure that I'll look back and see that it was easy. But, this seems like an opportunity to step through the thing (that is, the hugely complicated world of the muddy cloud) and see how things evolved. Those little interpreters are up there as a lure in the meantime. 

Cheers, 
John

Damien Mattei

unread,
Oct 15, 2017, 4:43:36 AM10/15/17
to Clojure
thanks for the answers and comments of John, James and others,
the discussion has opened many aspect of web application development and it is is positive.

about the IDE, i'm not using Netbeans with Scheme or LisP exclusively, in fact Netbeans was used in the office just to create web service in Java,
this thing can be done by hand in command line too, Kawa Scheme also can do it itself :
 https://www.gnu.org/software/kawa/Servlets.html

from the discussion i see now many solution to test ,I will install Leiningen, also i see in the doc of Immutant that it is possible to generate some war files :
http://immutant.org/documentation/current/apidoc/guide-wildfly.html#h3386

i hope i could use Clojure for that because it seems a really fun and solid LisP dialect.
I will post updates when i have a concrete usable solution.

Regards,

Damien

te...@ceteo.no

unread,
Oct 16, 2017, 2:10:24 AM10/16/17
to Clojure
Damien: A good starting point for a simple web server might be to use

lein new pedestal-service

Then you can do lein uberjar to get a jar ready to run. Or check the README for running local dev with a local REPL.

If instead you want a WAR, you can switch from pedestal.jetty to pedestal.immutant in project.clj and add the Immutant plugin:

:plugins [[lein-immutant "2.1.0"]]

Then do a lein immutant war to get your WAR for deployment to e.g. WildFly 10.

If you also want a nREPL to repl directly into the running server, have in project.clj e.g.:

:plugins [[lein-immutant "2.1.0"] [cider/cider-nrepl "0.15.1"]]
:immutant {:war {:nrepl {:port XXXX}}}

and do a lein immutant war --nrepl-start when making your WAR (check your security on the nREPL port).

Cheers,
Terje

(Haven't looked at WildFly 11 RC yet and don't know if Immutant works with it. Considering moving some of our services from WildFly to separate Jetty services instead, but WildFly 10 has worked very well.)

Damien Mattei

unread,
Oct 16, 2017, 9:36:39 AM10/16/17
to Clojure
following this tutorial : https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md#tutorial
i succeed with leiningen to build a project,run it and after make a jar file :

lein new app my-stuff
cd my-stuff
lein uberjar
lein run
or : cd target; java -jar my-stuff-0.1.0-SNAPSHOT-standalone.jar

with some simplified from tutorial files:

project.clj

(defproject my-stuff "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.8.0"]]
 
  :main my-stuff.core
  :aot [my-stuff.core])

core.clj

(ns my-stuff.core
  (:gen-class))

(defn -main [& args]
  (println "Welcome to my project! These are your args:" args))

the jar file in target/ could be loaded in the netbeans project Netbeans as a library/jar file and i can see the classes and definition in the netbeans IDE,
so it seems ok, note that at this point i can test it (on the tomcat server) but it should work (if i add also the clojure.jar runtime library i suppose)
also i do not need to make a full .war file from scratch, so it is more easy.

thank for your help

Damien

Justin Smith

unread,
Oct 16, 2017, 12:22:27 PM10/16/17
to Clojure
the uberjar option bundles clojure.jar (as well as any other dependencies you specify in your project.clj) into the output jar for you

--

Didier

unread,
Oct 20, 2017, 1:17:46 PM10/20/17
to Clojure
I think you can use lein-ring or lein-uberwar to package any ring based clojure web app into a War.

But, a War is just a zip file with a known set of files and directory structure. So depending on your needs, you could create it yourself too.

Didier

unread,
Oct 20, 2017, 1:23:37 PM10/20/17
to Clojure
I also suggests if you want to understand how to compile Clojure without thw help of tools loke boot or lein, to read those two short tutorials:

1. http://www.flyingmachinestudios.com/programming/how-clojure-babies-are-made-the-java-cycle/

2. http://www.flyingmachinestudios.com/programming/how-clojure-babies-are-made-lein-run/

Gregg Reynolds

unread,
Oct 20, 2017, 4:23:11 PM10/20/17
to clo...@googlegroups.com
There once was a man named Gustava
Whose Clojure code smelled just like Guava
He tried to use gen-class
Which made it smell stink-ass
So he went back to working in Java

Hardy-har-har.  Containers long for bytecode on disc. You can minimize it, but you have to have it to bootstrap the Clojure runtime.

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

For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.

Damien Mattei

unread,
Oct 30, 2017, 3:34:16 AM10/30/17
to Clojure
thank, i have not  read it in depth now but seems really interesting about both Java and Clojure

Damien

John M. Switlik

unread,
Oct 30, 2017, 9:28:03 AM10/30/17
to clo...@googlegroups.com
Hey, clojure world, your work got this old Lisp guy excited. Keep up the good work. It has been three weeks so far since I first saw the paper showing clojure as being (well, they said marginally, but I think more) better (in a quality sense) than most. What I have seen in terms of usage, and potential, calms the raging soul. This approach is powerful (more below). 

I am still treading through the lower regions marking issues. Also, trying to learn how to argue for locality (to be explained). The nebulous approach taken to the cloud (which became muddy) is the result of unrestrained abstraction'ism and has caused a mess which impacts humanity. 

Now, after getting past the initial glow, what crops up? Same issues as we faced fifteen years ago, plus or minus a few. Since then, there have been many choices that I think are exacerbating the problems. How to clean this up needs to be discussed? Structure, that we can find naturally, is the key. 

But, that is another forum, and clojure is an example of how to approach things technically. 

Keep up the good work.Soon, I will see how the initial build toward having something effective for me compares with the ease of Python. In the sense of modeling (to be discussed), clojure will win. How to demonstrate that is the key (note: it deals with much more than performance which the issues of locality would trump). 

John M. Switlik

unread,
Oct 30, 2017, 9:31:24 AM10/30/17
to clo...@googlegroups.com

Didier

unread,
Oct 30, 2017, 10:46:05 PM10/30/17
to Clojure
I will see how the initial build toward having something effective for me compares with the ease of Python.

Python's focus is on making things easy, not simple. Clojure's focus is on simplicity.

Lisp's syntax is simple, not easy. So Clojure uses it.
Macros extend the language in simple ways, but are not easy. The simple Lisp syntax makes them simple.
Immutability is simple, but doesn't work as we're used too, requiring us to think in terms of reduction and recursion. This is not as easy, but a lot simpler.
Shared state through managed references simplify their use, but learning about all the different reference types isn't as easy as an unmanaged pointer.
Abstractions make things simpler, but understanding new abstract construct isn't easy.

Clojure also values performance, python does not, delegating to C for performance use cases. Performance is not easy.

Learning about each datastructures and the distinct ways in which their functions work based on their performance characteristic is not easy, but helps make things performant.
Threads are not easy, parallelization and concurrency is hard. Simple abstractions exist, and Clojure leverages them such as futures, channels, stms, etc. But they help tremendously for performance.
Lazy evaluation is not easy, but improves performance and saves on memory. It can also be used for building abstractions.
The JVM isn't easy, not as easy as a simple interpreter for sure, but its wonderfully performant.

Clojure also values practicality, which I'd say Python does too.

Java interop is neither easy, nor simple, but so practically useful that Clojure welcomes it with open arms.
Impure functions aren't simple, but there are time where they're practically simpler then the workarounds in the overall.

Hope this helps you understand a bit better why Clojure is the way it is.

John M. Switlik

unread,
Oct 31, 2017, 9:22:28 AM10/31/17
to clo...@googlegroups.com
Thanks. I have been using clojure, as an example, on discussions on Quora. In essence, extrapolating from Lisp, pre-web, to clojure. Now, is that a huge leap? I don't expect so. I saw the approximation of something built on Lisp re-done (or attempted, anyway) via objective-C. The trade offs were obvious. Then, I well remember how the markup language maturity allowed us to refactor. And, we appreciated that. 

Yet, I love roll-your-own (in more ways than one ;>). That industry that I know and respect is into clojure confirms the thing. 

I am trying to see how to introduce locality (to be described). A proper control format would very much be supported by clojure. Actually, in the many readings of the past three weeks, I saw, at least, one suggestion that ML/DL needs clojure (or its type). 

BTW, let me just say that one can appreciate code as much as write it. In fact, the view that I am talking about is necessary as code is a filter, yet the mind can move around those (a human talent seemingly barely understood). And, code, being a filter, restrains the mind. This can be demonstrated (believe me). Lisp, being more free form, allowed a closer move toward the domain. In this sense: I think that Lisp gave us an open-ended, contextual database with attachments. Domains need context, though, CS might love their context-free views. 

Over and out. I'll take this to Quora and other platforms. It was real nice to find out about this work. 
Reply all
Reply to author
Forward
0 new messages