REPL not updating the code remotely - Clojure - clojure

I am experiencing an API issue where a partner is trying to do a POST request to my server but it looks like it is loading the previous code from my server.
The previous code contained an error:
#'clj-time.coerce/ICoerce found for class: java.time.LocalDateTime
But it has been fixed and released through REPL.
Here is the previous code:
(defn- parse-data [{:keys [name start-date bestbefore-date]}]
{:product name
:start-date (timec/to-string start-date)
:bestbefore-date (timec/to-string bestbefore-date)})
Here is the fix from the previous code:
(defn- parse-data [{:keys [name start-date bestbefore-date]}]
{:product name
:start-date (.toString (.format start-date formatter))
:bestbefore-date (.toString (.format bestbefore-date formatter))})
The code was working perfectly but it stopped after a few months as it seems to be loading the previous code containing the error mentioned above.
On my end, I tried to run the affected method from the request through REPL, and it is working just fine.
The server is built in Clojure language.
I have no other error logs aside from the partner error response as it is working fine on my server.
The server has not been restarted, so the fix should have been still there. Thus, I have again do an REPL with the code fix but it looks like it is not taking any effect.
As I am pretty new to Clojure, and I am thinking that it might be a cache issue. REPL concept is still pretty vague to me and perhaps I am doing something wrong.
I would like to know if some of you already experienced this kind of issue? And what would be the solution to it? Or perhaps any advice?
I wish to thank you in advance for your responses.

Kind a weird issue but I have been able to resolve this.
I was unsure what was going, so I just re-built the code and restarted the server.

Related

Simple Clojure and CouchDB example for web app

I want to experiment writing a web app with Clojure and CouchDB, but I can't find many examples to help me get started. Searching around the web a bit I see that I could use this combination of libraries:
https://leiningen.org/
http://www.luminusweb.net/
https://github.com/clojure-clutch/clutch
The first two seem popular, but what about clutch, it doesn't look actively developed -- is it a good choice?
Assuming I use clutch, I'm struggling to find much example code, this seems to work, but is it the right approach?
Project creation:
lein new luminus couchdb-test
Add this in project.clj in :dependencies:
[com.ashafa/clutch "0.4.0"]
Run project:
lein run
And then in the REPL:
(require ['com.ashafa.clutch :as 'clutch])
;; Test connection to DB - I've created one called wiki
(clutch/get-database "wiki")
;; Get a list of all documents
(clutch/with-db "wiki"
(clutch/all-documents))
;; Output all docs with contents
(clutch/with-db "wiki"
(clutch/all-documents {:include_docs true}))
;; Output titles of all docs that have one
(map (fn [result] (:title (:doc result)))
(clutch/with-db "wiki"
(clutch/all-documents {:include_docs true})))
Any corrections, hints, or pointers to better examples would be great.

How can I communicate with the backend using ClojureScript and Figwheel?

Note: I'm a moderately experienced programmer in general and using clojure but have never done serious web development.
I set up a basic ClojureScript project using Chestnut and walked through the "Hello World" steps just fine. However I would really like to talk to my backend as well. For this purpose I redefined the Reagent code to be
(defn greeting []
[:input {:type "button"
:value (:text #app-state)
:on-click #(http/get {})}])
Which gets a 404 response when clicked. So at least I'm talking to somebody. I can also see evidence of my get-requests in the server.log file. However at this point I'm struggling with a number of conceptual points.
First of all http/get is a function defined in clj-http.client, which wasn't part of the Chestnut setup. It feels like I'm already off track if I have to go hunting for libraries to send something as basic as a get-request.
Secondly the file for the user namespace has the following lines predefined by Chestnut:
(def http-handler
(wrap-reload #'mypage.server/http-handler))
(defn run []
(figwheel/start-figwheel!))
I can't see any place where the http-handler is ever used. So I don't understand what that definition even does.
Also the way I understand Figwheel, when I call "run" it'll spin up a new web server which then a) serves the index.html and b) connects to my browser via some TCP port and starts pumping new JavaScript through that connection. This second part is very speculative on my part. If this is actually what happens my next question would be if Figwheel also needs to sit on the other side of that connection or if browsers have some common API that allows code reloading from the outside.
Lastly I can kinda tell that the ring routes and http-handler defined in the mypage/server.clj file (below) are being called somehow, since modifying these changes the error from the get-request, however it's a complete mystery to me how this works. The way I understand it the get-request I'm sending from the browser is sent to the Figwheel-server, the origin of the site. I have no reason to believe that Figwheel knows anything about the http-handlers I've defined in the server file.
(defroutes routes
(GET "/" _
{:status 200
:headers {"Content-Type" "text/html; charset=utf-8"}
:body (io/input-stream (io/resource "public/index.html"))})
(resources "/"))
(def http-handler
(-> routes
(wrap-defaults api-defaults)
wrap-with-logger
wrap-gzip))
For a ClojureScript project (i.e. not Clojure), I believe you want this: https://github.com/r0man/cljs-http
I don't have a complete answer, but I do have a couple points that might help.
Clojurescript ultimately compiles down to JavaScript, and makes heavy use of (and has access to) the Google Closure library. So if you really want to, you can use JavaScript interop to just make an AJAX call from the client-side, just like you would in JS. The closure library provides a wrapper for this---see docs here https://developers.google.com/closure/library/docs/xhrio . But there are also several easy http and Ajax libraries for clojurescript, so why not use them? Another part of the joy and magic of clojurescript is that the Google closure optimizations that get applied do lovely things like strip out dead code, so I believe (and someone else can correct me if I'm wrong) that there is little (no?) production cost to putting some extra libraries in.
Figwheel is ultimately dev, not production, and doesn't depend on the http server that you set up for production use. Indeed, there are templates out there for front-end-only cljs projects that still use figwheel--- here's one example. Figwheel spins its own server to push changes to the browser, I'm not quite sure how it works.

Compojure Ring Server Generated By 'lein ring server' Acting Oddly

So I was coding and I got an exception. I fixed the exception and then went back to check that things were working. Instead of seeing my fixes I instead saw the website that was generated prior to the exception having been thrown. Like my previous code had been cached and now it was being used. I double checked this intuition by commenting everything out and trying to put in a string instead of the web page and this still resulted in no changes to my site. So I went ahead and tried restarting the server. This didn't fix things. So then I tried running lein clean. This didn't fix things either. What the hell is going on here and how do I fix it?
I'm pretty sure my code is irrelevant, because I'm getting the same problem no matter what code I use. For those that are wondering the initial exception was that the function clojure.string/replace was already being used at clojure.core/replace or in other words I had a naming conflict. I resolved this by (:require [clojure.string :as string]).
Hmm, so I ended up restarting my computer and the problem was solved. The actual reason I had this problem I'm not so sure of.

Clojure: Minimal ClojureScript Two Person Chat

EDIT 01
Sounds like web sockets is what I want.
Technical Background:
I am familiar Clojure + ring + composure.
I am starting to learn ClojureScript. (Have lein-cljsbuild setup; have also spent time installing ClojureScript "manually" just to see how it works.) Have the basic (alert (greeting "ClojureScript")) demo working.
What I want to create:
I want to create a basic two person Notepad (i.e. Instant Messenger, or two-person IRC channel). I want there to be a Clojure Server. When a client connects it shows it a text bok; the user types in some words, the clojure updates to the other user.
Question
I need some help getting started on this. Google Closure is a big library, I would like to understand things like:
(1) how do I setup a basic connection to get my cljs code and my clj code to send each other data
(2) once my cljs code received new data, how do I get it do update the DOM?
I think these are the two main things -- and if I had this, it would provide a framework for understanding the rest of clojurescript.
Thanks!
I wrote an example app that does this using clojurescript, ring, and websockets via a Webbit server:
https://github.com/aiba/clojurescript-chat-example
Hope this helps!
You (I) probably want WebSockets.
More to be updated (if I produce actual working code.)

Troubles Importing Clojure Libs in Paradise

I occasionally get this problem, and generally work around it, but it's rather frustrating.
I have all of Incanter (check it out if you don't know it: it's superb) on my classpath. I try to import it (through a Slime REPL) like this: user> (use 'incanter.core), but fail.
Doing this: user> (use 'clojure.contrib.def) works just fine, and this file is in the same place–on my classpath.
Regardless, the error isn't anything about classpath: it's this:
Don't know how to create ISeq from: clojure.lang.Symbol
[Thrown class java.lang.IllegalArgumentException]
You can see my entire terminal here (a screenshot.)
I don't know what's going on here, and it's really frustrating, as I really would like to use Incancter, and I can from the Incanter binary's REPL. I definitely don't want to develop from that–and this should work.
Any help would be much appreciated.
EDIT:
It appears as though Incanter requires Clojure 1.2, and lein swank gives me Clojure 1.1. This might be the cause of my problems: if so, is there a way to continue to use Swank & Lein with Clojure 1.2?
Thanks again!
EDIT:
Apparently if you start using Clojure-1.1 and lein swank, you're stuck with it unless you make a new project.
If future people have this problem, this article helped me out, but also, at least for me, you must start a new lein project if you had begun it using leink swank and Clojure-1.1. Simply changing your project.clj file and then lein swanking again doesn't work.
Yes, you can use Leiningen and swank-clojure with Clojure 1.2. You might need to use a recent version of Leiningen (I'm not sure if a certain old limitation affected lein repl only or was it lein swank as well; anyway, try the 1.2-RC2 which you'll find in the downloads section on GitHub). You will also need to use a recent-enough swank-clojure; I use a bleeding edge checkout myself, get yours here.
Other than that, simply use 1.2 jars for Clojure and contrib. (Lein uses it's own Clojure, separate from the one used for lein swank, for its internal workings and you never need to care about it; swank-clojure has no AOT'd namespaces and doesn't particularly care about the Clojure version, except once in a (long!) while something breaks, a patch is applied and joy is restored.)
I hope the above helps, but if it doesn't: your problem description is not entirely sufficient for me to get a clear picture of what is happening. Could you add information on what it means for "all of Incanter" to be on your classpath (do you mean the jars? sources? where do you get them? how do you set your classpath?). Without knowing this, it'll be hard to replicate your setup to try to track down the source of the problem.
Of course if bumping some versions fixes things, please disregard my current confusion. ;-)