@roelof https://practicalli.github.io/clojure/clojure-tools/projects/add-libraries.html covers adding dependencies. Its the same as Leiningen, with a slightly different keyword and hash-map rather than a vector of vectors.
thanks and another one
Caused by: Unable to resolve var: app in this context
@roelof Can be caused if you use app before it's defined, or you haven't evaluated the expression that defines app
oke\
then I have to find out where app is defined here
(ns practicalli.banking
(:gen-class)
(:require [org.httpkit.server :as app-server]
[compojure.core :refer [defroutes GET]]
[ring.util.response :refer [response]]))
(defonce app-server-instance (atom nil))
(defn app-server-start
"Start the application server and log the time of start."
[http-port]
(println (str (java.util.Date.)
" INFO: Starting server on port: " http-port))
(reset! app-server-instance
(app-server/run-server #'app {:port http-port})))
(defn app-server-stop
"Gracefully shutdown the server, waiting 100ms. Log the time of shutdown"
[]
(when-not (nil? @app-server-instance)
(@app-server-instance :timeout 100)
(reset! app-server-instance nil)
(println (str (java.util.Date.)
" INFO: Application server shutting down..."))))
(defn app-server-restart
"Convenience function to stop and start the application server"
[http-port]
(app-server-stop)
(app-server-start http-port))
(defn welcome-page
[request]
(response "Banking on Clojure"))
(defroutes app
(GET "/" [] welcome-page))
(defn -main
"Select a value for the http port the app-server will listen to
and call app-server-start
The http port is either an argument passed to the function,
an operating system environment variable or a default value."
[& [http-port]]
(let [http-port (Integer. (or http-port (System/getenv "PORT") "8888"))]
(app-server-start http-port)))
(comment
;; Start application server - via `-main` or `app-server-start`
(-main)
(app-server-start 8888)
;; Stop / restart application server
(app-server-stop)
(app-server-restart 8888)
;; Get PORT environment variable from Operating System
(System/getenv "PORT")
;; Get all environment variables
;; use a data inspector to view environment-variables name
(def environment-variables
(System/getenv))
;; Check values set in the default system properties
(def system-properties
(System/getProperties))
)
@roelof it's not very helpful to paste large amount of code into slack as it has no line numbers to refer to. Using GitHub Gists is preferred if the project is not in GitHub or GitLab
sorry here a gists : https://gist.github.com/RoelofWobben/6fe33b9d6c69be9c4943d06bd936054c
There is a def
expression that defines app, this should be towards the top of the code.
The last part of line 22 in your gist. Unfortunately the gist is not showing line breaks, so hard to read.
oops. I see it
you mean the defroutes
part
It's essential an order issued. You have defined functions that use app before it's defined. Clojure does single pass parsing of code in a file, although when using the repl as long as something is defined the it will work. Ordering should be maintained eventually, or the Clojure program will not run as an application on the command line
Yes. It should be ordered like this https://github.com/practicalli/banking-on-clojure-webapp/blob/live/src/practicalli/banking_on_clojure.clj
oke,
thanks, I will use that code then to follow the tutorial
Apologies to all that I wasnt able to give a broadcast today. My flu symptoms seem to be a bit better this afternoon. I should be back to broadcasting next week. If there are any specific things you would like to me to see, please let me know (deciding what is interesting is usually the hard part)
I decided to take an look at the status of Language server protocol, particularly for Emacs. This issue documents the current status and issues I've experienced over the last few months. https://github.com/practicalli/spacemacs-content/issues/287 In summary clojure-lsp has a lot of potential, especially around refactoring code. There are challenges to resolve and some documentation to help people set up clojure-lsp, lsp-mode and CIDER to work effectively without conflicting or replacing CIDER features with less capable results. It seems the addition of LSP features to VS Code & Calva is helping improve clojure-lsp in general and hopefully lsp-mode will get some more attention soon.
I have been looking for a good approach to using Vim with Calva (VS Code). VSpaceCode seems to be my preferred approach so far, it gives a very Spacemacs-like experience especially with the which-key like menu (using the normal VS Code command pallete, but with Vim-style key bindings) I have started creating the key bindings for VSpaceCode to support Clojure development with Calva. I am defining the keys for a Clojure context specific menu (like major mode in Emacs). Its fairly simple to add keys, just a bit fiddly as the config is in json and I keep missing commas or adding commas where not needed - and I cant add comments 😢
and another problem in the text :
(ns practicalli.banking-on-clojure
(:gen-class)
(:require [org.httpkit.server :as app-server]
[compojure.core :refer [defroutes GET]]
[ring.util.response :refer [response]]
[practicalli.request-handler :as handler]))
(ns practicalli.banking-on-clojure
(:gen-class)
(:require [org.httpkit.server :as app-server]
[compojure.core :refer [defroutes GET]]
[ring.util.response :refer [response]]
[practicalli.request-handler :as handler]))
yep, I did it but I also type everything as desribed in the tutorial
I renamed the file to request_handler.clj
but still the same problem
no one for some help ?
Can you share the code on GitHub or GitLab? I can't think what else could be wrong if the names are okay.
of course : https://github.com/RoelofWobben/banking_on_clojure
The issue is https://github.com/RoelofWobben/banking_on_clojure/blob/master/src/practicalli/banking_on_clojure.clj#L6
Namespaces should use the -
(dash) in multi-part names within the source code, however, the corresponding file name should be an _
underscore. This is due to a limitation of the Java virtual machine class loader and a small annoyance that we've all had to be come accustom too.
This namespace does not match the file name, so will not be found from the :require
directive in the backing-on-clojure namespace
https://github.com/RoelofWobben/banking_on_clojure/blob/master/src/practicalli/request_handlers.clj#L1
I do get the impression from your posts across several slack channels that you are trying to learn a great many things at once. This often leads to getting easily tripped up on small issues like this. I had given you the answer to this issue 5 days ago. I appreciate it can be frustrating learning something new and would encourage you focus just a few aspect of Clojure at a time. Good luck.
If you can describe the problem you are having I may be able to help. Just pasting code in doest help anyone help you.
sorry, I thought I did paste the errror message
Syntax error macroexpanding at (banking_on_clojure.clj:1:1).
Caused by: Could not locate practicalli/request_handler__init.class, practicalli/request_handler.clj or practicalli/request_handler.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
this is what I see when compiling
Did you check this instruction in the error?
Please check that namespaces with dashes use underscores in the Clojure file name.
Due to a limitation with the Java virtual machine, filenames must use an underscore to hold code that is in a namespace with dashes in the name.