practicalli

https://practicalli.github.io/ http://yt.vu/+practicalli (youtube)
practicalli-john 2021-01-02T00:13:01.329700Z

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

roelof 2021-01-02T10:23:38.330Z

thanks and another one

roelof 2021-01-02T10:23:42.330400Z

Caused by: Unable to resolve var: app in this context

practicalli-john 2021-01-02T11:05:47.332400Z

@roelof Can be caused if you use app before it's defined, or you haven't evaluated the expression that defines app

roelof 2021-01-02T11:17:11.332600Z

oke\

roelof 2021-01-02T11:17:23.333Z

then I have to find out where app is defined here

roelof 2021-01-02T11:17:27.333300Z

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

  )

practicalli-john 2021-01-02T11:45:57.336100Z

@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

roelof 2021-01-02T11:47:51.337600Z

sorry here a gists : https://gist.github.com/RoelofWobben/6fe33b9d6c69be9c4943d06bd936054c

practicalli-john 2021-01-02T11:48:00.337900Z

There is a def expression that defines app, this should be towards the top of the code.

practicalli-john 2021-01-02T11:50:00.339900Z

The last part of line 22 in your gist. Unfortunately the gist is not showing line breaks, so hard to read.

roelof 2021-01-02T11:51:51.342900Z

oops. I see it

roelof 2021-01-02T11:52:04.343700Z

you mean the defroutes part

practicalli-john 2021-01-02T11:52:54.345100Z

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

practicalli-john 2021-01-02T11:54:37.346300Z

Yes. It should be ordered like this https://github.com/practicalli/banking-on-clojure-webapp/blob/live/src/practicalli/banking_on_clojure.clj

roelof 2021-01-02T11:55:10.346600Z

oke,

roelof 2021-01-02T11:55:28.347Z

thanks, I will use that code then to follow the tutorial

practicalli-john 2021-01-02T16:20:31.353Z

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)

practicalli-john 2021-01-02T16:22:51.354Z

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.

practicalli-john 2021-01-02T16:28:42.359700Z

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 😢

👍 1
roelof 2021-01-02T19:47:09.360500Z

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

🤷 1
roelof 2021-01-02T19:47:25.360800Z

(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]))

roelof 2021-01-03T09:25:39.362300Z

yep, I did it but I also type everything as desribed in the tutorial

roelof 2021-01-03T09:36:10.362500Z

I renamed the file to request_handler.clj but still the same problem

roelof 2021-01-06T16:17:04.362900Z

no one for some help ?

practicalli-john 2021-01-06T21:31:24.363200Z

Can you share the code on GitHub or GitLab? I can't think what else could be wrong if the names are okay.

roelof 2021-01-07T08:29:26.363400Z

of course : https://github.com/RoelofWobben/banking_on_clojure

practicalli-john 2021-01-07T16:10:12.363700Z

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

practicalli-john 2021-01-07T16:15:13.364Z

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.

practicalli-john 2021-01-02T20:55:48.361Z

If you can describe the problem you are having I may be able to help. Just pasting code in doest help anyone help you.

roelof 2021-01-02T21:10:48.361200Z

sorry, I thought I did paste the errror message

roelof 2021-01-02T21:10:52.361400Z

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.

roelof 2021-01-02T21:11:09.361600Z

this is what I see when compiling

practicalli-john 2021-01-02T23:49:03.361800Z

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.