beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
bcaccinolo 2020-09-29T09:01:11.290600Z

is it possible to embed a clj interpreter (like sci) in a java project to evaluate clj formulas stored in database ? 🙂

borkdude 2020-09-29T09:03:34.291100Z

yes, you can embed sci in java

borkdude 2020-09-29T09:03:50.291400Z

or you can just use Clojure directly, if you trust the code

bcaccinolo 2020-09-29T09:06:05.291800Z

the idea is to create a formula engine

bcaccinolo 2020-09-29T09:07:07.292900Z

clj looks great for that cause it's easy to parse the code stored in a string

bcaccinolo 2020-09-29T09:07:51.293700Z

@borkdude cool , good to know 🙂

borkdude 2020-09-29T09:10:19.294400Z

@benoit.caccinolo yes. you can use load-string from Clojure or eval-string from sci. Sci had a Java interface, but since nobody was using it, I deleted it. https://github.com/borkdude/sci/commit/6bbccc3eec050dd0d4fc9cf017b89577e0269494

borkdude 2020-09-29T09:10:34.294700Z

but it's not so hard to make it yourself

borkdude 2020-09-29T09:11:12.295200Z

Most of the work in the Java API was to create Option classes and convert them into maps. Not a lot of fun

borkdude 2020-09-29T09:11:37.295700Z

So I figure if you want to use sci, make a little Clojure wrapper with your options and then call that from Java

borkdude 2020-09-29T09:12:12.296100Z

Here is info how to call Clojure from Java: https://clojure.github.io/clojure/javadoc/clojure/java/api/package-summary.html

bcaccinolo 2020-09-29T09:12:26.296500Z

Do you mean it would be easier with vanilla clojure ?

borkdude 2020-09-29T09:12:52.297Z

Sci is easier to use from Clojure than from Java. So make a little Clojure wrapper around sci (specific for your use case) that you call from Java, if you want to use sci.

bcaccinolo 2020-09-29T09:13:09.297200Z

ok I look at this

bcaccinolo 2020-09-29T09:13:48.297900Z

thx for the fast answer, I'll look at this.

borkdude 2020-09-29T09:14:18.298400Z

I'm considering removing the JS api from sci as well. Most people need specific options. It's easier to just call it from CLJS specific to a project and then compile that to JS

Audrius 2020-09-29T10:04:56.302100Z

Hi, I have an algorithm to implement that "buys" goods from list of maps [{:name "good 1" :price 12} {:name "good 2" :price 17} ...]. Every good may have a different price. And I want to keep buying until it has no more cash left (some finite amount). Is there an idiomatic way to do it in Clojure? Something like reduce-until :thinking_face:

jsn 2020-09-29T10:38:51.302400Z

I don't think so -- you'll need to carry the state (e.g. cash left) around, it's cumbersome. I think loop is a good fit.

Audrius 2020-09-29T11:32:40.302800Z

I also did not find anything elegant here so my solution:

(def cash-spent (atom 0))
(defn accumulate-price [item limit]
  (swap! cash-spent #(+ % (get item "price")))
  (>= limit @cash-spent))

(take-while #(accumulate-price % cash-available items))

markmarkmark 2020-09-29T11:45:50.303100Z

you can used reduced to duck out of a reduce early. I'm not completely sure that this does what you want, but something like:

(reduce                                  
  (fn [cash-spent item]                  
    (if (>= limit cash-spent)            
      (reduced cash-spent)               
      (+ cash-spent (get item "price"))))
  0                                      
  items)                                 

👍 2
Stas Makarov 2020-09-29T12:23:15.305200Z

What's the magic behind map->ResponseFormat here? https://github.com/JulianBirch/cljs-ajax/blob/master/src/ajax/interceptors.cljc#L223 I expected to find a regular function with such name defined somethere in cljs-ajax codebase but couldn't. Is it some sort of a convention?

✔️ 1
2020-09-29T12:24:57.306100Z

each defrecord defines few functions: ->RecordName and map->RecordName https://github.com/JulianBirch/cljs-ajax/blob/master/src/ajax/interceptors.cljc#L93

Jim Newton 2020-09-29T12:25:08.306700Z

Is there a way to ask the Clojure testing env to tell me which tests are running rather than waiting to the end? One of my tests sometimes takes a very long time. I could do a binary search to find it, but it would be nice if I could just turn on a verbose mode

Stas Makarov 2020-09-29T12:25:41.306800Z

Thank you!

2020-09-29T13:22:58.307300Z

If you are using the clojure.test library for writing tests, there are some ways to write code that is executed at the beginning or end of each deftest form. An example of using that to print a message when each deftest begins, and to print how long in elapsed time each one took to finish, is here: https://github.com/clojure/core.rrb-vector/blob/master/src/test/clojure/clojure/core/rrb_vector/test_utils.clj#L52-L64

2020-09-29T13:32:34.307600Z

It has been a while since I wrote that code, but if I recall correctly, I put that code, and some other "test utility functions", into one namespace defined in that file, and then :require it from all other namespaces in that project that have deftest forms.

👍 1
cljnoob 2020-09-29T15:15:58.312300Z

Hello all, first time joining, so forgive me if this is the wrong place to ask. I am trying to query postgres using clojure.java.jdbc and then trying to put the results into a vector which I then send inside of a json object. When I try to do this, the results vector sent back is empty. Could someone help me identify the problem? My thoughts were that this is a side effects issue, but I tried enclosing things in a do block and I still had the same issue. Here is the code: (defn get-meets [request]

cljnoob 2020-09-29T15:16:08.312600Z

Sorry, the copying got messed up. Trying again.

cljnoob 2020-09-29T15:22:53.315100Z

(defn get-records [request] (let [{limit :limit, offset :offset, type :type} (:params request) results []] (response (try (jdbc/query db-spec ["SELECT * FROM records ORDER BY on_date LIMIT ? OFFSET ?;" (Integer/parseInt limit) (Integer/parseInt offset)] {:result-set-fn (fn [rs] (reduce conj results rs))}) (cheshire/generate-string {:results results}) (catch Exception e (cheshire/generate-string {:error (.getMessage e)}))))))

practicalli-john 2020-09-29T15:29:47.315300Z

Kaocha test runner will tell you which tests too the longest to run https://cljdoc.org/d/lambdaisland/kaocha/1.0.700/doc/1-introduction There is also a reporter plugin to show progress, although my tests run so fast I cant tell if its doing them one by one (I think it does)

practicalli-john 2020-09-29T15:34:39.318Z

Try sharing the code in a GitHub gist file or in a Git repository if you can, it will make it easier (unless its just a few lines of code) Recommend you use the https://github.com/seancorfield/next-jdbc as this replaces clojure.java.jdbc There is also a #sql channel here where you may get specific help. I am also building a website using next.jdbc that talks to H2 and postgresql database which I am documenting here: https://practicalli.github.io/clojure-webapps/projects/banking-on-clojure/ There is also a video series of how I am working through creating this application. Its work in progress, but hopefully you will find it useful

gon 2020-09-29T15:36:05.318300Z

clojure data is immutable, (reduce conj results rs) does not fill up the results vector you have defined above, and the resultset is lost,

(defn get-records [request]
  (let [{limit :limit, offset :offset, type :type} (:params request)
        results []]
    (response
     (try
       (cheshire/generate-string {:results (doall
                  (jdbc/query db-spec
                   ["SELECT * FROM records ORDER BY on_date LIMIT ? OFFSET ?;" (Integer/parseInt limit) (Integer/parseInt offset)]              ))})
       (catch Exception e (cheshire/generate-string {:error (.getMessage e)}))))))
try this, I didn't try but it should work

cljnoob 2020-09-29T16:09:32.318900Z

Wow that worked! Thank you. Also @jr0cket I will keep up with your video series as i'm sure it wil be useful, thank you for that as well.

cljnoob 2020-09-29T16:09:49.319100Z

and from now on I will send things as github files, sorry for clouding up the chat

Jim Newton 2020-09-29T16:25:12.319300Z

Is the idea of kaocha that I still have the code using the normal testing macros, deftest, is, testing, but I need to require something different?

2020-09-29T16:32:31.320300Z

can someone help me figure out how to stop this macro from wrapping the entire result in an extra () ?

(defprotocol MyProtocol (foo [x]))

(defmacro my-extend-helper [prot & extensions] (let [protocol (-> prot resolve deref)
                                                     m (-> protocol :sigs keys first)
                                                     params (-> protocol :sigs first last :arglists first)]
                                                 (for [[atype x] extensions]
                                                   `@(extend-protocol ~prot ~atype
                                                       (~m ~params ~x)))

                                                 ))

(macroexpand '(my-extend-helper MyProtocol [clojure.lang.PersistentVector (first x)]))
=> ((clojure.core/extend-protocol MyProtocol clojure.lang.PersistentVector (:foo [x] (first x))))

teodorlu 2020-09-29T16:36:48.320700Z

@jeffrey.wayne.evans unquote-splicing might be of help, if you haven't seen it: https://clojuredocs.org/clojure.core/unquote-splicing

2020-09-29T16:37:05.321100Z

yeah I was playing with that, but couldn’t quite get it. will refocus there again. thanks!

👍 1
practicalli-john 2020-09-29T17:45:25.322100Z

Kaocha will run clojure.test unit tests and many other things. No changes are required to the tests. Some basic examples here https://practicalli.github.io/clojure/testing/test-runners/kaocha-test-runner.html

👍 1
practicalli-john 2020-09-29T18:08:03.322300Z

Code of a handful of lines is okay to post here, yours was fine. If you want to post a lot of code then Gist or repo is better.

marciol 2020-09-29T18:16:03.322700Z

Hi all, I

👋 1
marciol 2020-09-29T18:28:10.326Z

I was doing experiments with reducers and somethink caught my attention, the return of reducer functions doesn’t return a IPersistentCollection, so someone knows why? Example:

user=> (let [result (clojure.core.reducers/flatten [1 2 [3 4]])]
         (println "is collection: " (coll? result))
         (println "type: " (type result)))
is collection:  false
type:  clojure.core.reducers$folder$reify__5949
nil

marciol 2020-09-29T18:29:33.327100Z

And the docs of reducers/flatten states that it returns a foldable collection:

user=> (doc clojure.core.reducers/flatten)
-------------------------
clojure.core.reducers/flatten
([] [coll])
  Takes any nested combination of sequential things (lists, vectors,
  etc.) and returns their contents as a single, flat foldable
  collection.
nil

bronsa 2020-09-29T18:31:12.327700Z

a foldable collection, not a collection. i.e. folding/reducing it will produce a collection

✔️ 1
🙏 1
alexmiller 2020-09-29T18:31:32.328100Z

you might want to peruse https://clojure.org/news/2012/05/08/reducers https://clojure.org/news/2012/05/15/anatomy-of-reducer

🙏 1
bronsa 2020-09-29T18:31:50.328400Z

user=> (into [] (clojure.core.reducers/flatten [1 2 [3 4]]))
[1 2 3 4]

marciol 2020-09-29T18:35:58.330Z

> a foldable collection, not a collection. i.e. folding/reducing it will produce a collection (edited) Yes, it’s clear right now, paying attention to foldable qualifier 😄

marciol 2020-09-29T18:36:58.330600Z

> you might want to peruse https://clojure.org/news/2012/05/08/reducers https://clojure.org/news/2012/05/15/anatomy-of-reducer Thank you @alexmiller, I’ll dig deep into this

Daniel Stephens 2020-09-29T18:58:28.338100Z

hi, I'm trying to get started with some deps.edn stuff, I have a problem finding standard dependencies. In my ~/.m2/settings.xml I have just one repository set up which is authenticated for some work stuff. When I try to get a dep in my deps.edn it falls over with a timeout because the configured repo doesn't have the dependency. I've been using lein until now and it finds the dependency fine, I assume that's some hidden defaults so seems a reasonable reaction from deps. Question is, can I add some other repositories to look at into deps.edn, I tried with :mvn/repos which I was hopeful for but still seems to timeout looking in the wrong place.

{:paths ["src"]
 :deps {org.clojure/clojure {:mvn/version "1.10.1"}}
 :aliases {:test {:extra-paths ["test"]
                  :extra-deps {eftest {:mvn/version "0.5.9"}} ;tried with eftest/eftest as well
                  }}
 ;still no luck after adding these 
 ;:mvn/repos {"central" {:url "<https://repo1.maven.org/maven2/>"}
 ;            "clojars" {:url "<https://repo.clojars.org/>"}}
 }
&gt; clojure -M:test
Error building classpath. Failed to read artifact descriptor for eftest:eftest:jar:0.5.9
    at ...
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not transfer artifact eftest:eftest:pom:0.5.9 from/to central (<https://my.private.repo/repository/maven-group>): connect timed out

alexmiller 2020-09-29T19:07:52.339200Z

the "looking in the wrong place" is probably just a misleading error message - it searches all of the repos in order and will typically just report one of those errors (so that can look confusing, but it should be checking all of them)

alexmiller 2020-09-29T19:08:52.339800Z

where is https://my.private.repo/repository/maven-group coming from?

alexmiller 2020-09-29T19:09:53.340600Z

the central and clojars repos are included by default

alexmiller 2020-09-29T19:10:34.341Z

clj -Sdeps '{:deps {eftest/eftest {:mvn/version "0.5.9"}}}' worked for me - downloaded eftest from clojars

alexmiller 2020-09-29T19:11:09.341500Z

I think you've got something funky in your ~/.m2/settings.xml that is causing the problems

Daniel Stephens 2020-09-29T19:12:49.342800Z

ahh interesting thanks, in ~/.m2/settings.xml I have something like:

&lt;settings xmlns="<http://maven.apache.org/SETTINGS/1.0.0>"
          xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>"
          xsi:schemaLocation="<http://maven.apache.org/SETTINGS/1.0.0> <http://maven.apache.org/xsd/settings-1.0.0.xsd>"&gt;
 
  &lt;servers&gt;
    &lt;server&gt;
      &lt;id&gt;x&lt;/id&gt;
      &lt;username&gt;y&lt;/username&gt;
      &lt;password&gt;z&lt;/password&gt;
    &lt;/server&gt;
  &lt;/servers&gt;
 
   &lt;mirrors&gt;
    &lt;mirror&gt;
      &lt;id&gt;x&lt;/id&gt;
      &lt;url&gt;<https://my.private.repo/repository/maven-group>&lt;/url&gt;
      &lt;mirrorOf&gt;*&lt;/mirrorOf&gt;
    &lt;/mirror&gt;
  &lt;/mirrors&gt;
 
&lt;/settings&gt;
sorry I can't share it more fully

alexmiller 2020-09-29T19:13:31.343800Z

yeah, I think it's timing out accessing that mirror

Daniel Stephens 2020-09-29T19:13:32.343900Z

I'll try and look into the xml side more @alexmiller though this was just requested by my work to be used

Daniel Stephens 2020-09-29T19:14:09.345Z

that makes sense, I was hoping I could override that in the deps.edn without changing my xml but I guess not

Daniel Stephens 2020-09-29T19:14:23.345500Z

I suppose lein is just ignoring that setup

alexmiller 2020-09-29T19:14:25.345600Z

if that's a company nexus repo or something like that, you may need to do some other process to get it retrieved and loaded in your nexus

👍 1
alexmiller 2020-09-29T19:14:47.346Z

not uncommon to proxy all maven traffic through things like that

Daniel Stephens 2020-09-29T19:15:13.346500Z

yeah, this was a little personal project I was doing on the side to try out deps, but might not work out

Daniel Stephens 2020-09-29T19:15:44.347Z

well thanks for the help, sounds like nothing wrong with deps at least!

Daniel Stephens 2020-09-29T19:30:15.348400Z

mv ~/.m2/settings.xml ~/.m2/definitely-not-settings.xml working great now 😂

Daniel Stephens 2020-09-29T19:30:23.348600Z

Thanks again Alex

x3qt 2020-09-29T19:54:20.350200Z

Hi there! Can someone explain to me why this is not working?

((resolve (symbol (str "Math" "/sqrt"))) 25)

2020-09-29T19:59:31.353100Z

The big reason is Math/sqrt is a java static method, which the compiler statically figures out

2020-09-29T19:59:48.353700Z

It is not a var in a namespace which is what resolve looks up

x3qt 2020-09-29T20:00:01.353900Z

Oh, got it, thank you

2020-09-29T20:00:43.355400Z

The / is also not part of the symbol name, it just distinguishes the namespace from the name when printing a symbol

x3qt 2020-09-29T20:01:18.356100Z

The reason I am trying to do it is to create a macro to dynamically define routes the following way –

(ns arborist.handler
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [arborist.users :as users]
            [ring.middleware.defaults :refer [wrap-defaults site-defaults]]))

;; TODO: map over collection of http verbs to generate routes and actions
;; with something like ((resolve (symbol "+")) 5)
(defmacro rest-resource [resource]
  (context (str "/" resource) []
    (GET "/" [] (users/index))
    (POST "/" [] (users/create))
    (GET "/:user-id" [user-id] (users/show user-id))
    (PATCH "/:user-id" [user-id] (users/update user-id))
    (DELETE "/:user-id" [user-id] (users/update user-id))))

(defn greet [name] (str "Hello, " name "!"))
(greet "Yury")

(defroutes app-routes
  (GET "/" [] "Welcome to Arborist")
  (GET "/request" request (str request))

  (rest-resource "users")
  (rest-resource "notes")

  (route/not-found "Not Found"))

(def app
  (wrap-defaults app-routes site-defaults))

x3qt 2020-09-29T20:01:30.356400Z

So I want to generate routes from the resource name passed

2020-09-29T20:01:36.356800Z

Nah

x3qt 2020-09-29T20:01:37.356900Z

The code above is working

2020-09-29T20:01:51.357300Z

It is not

x3qt 2020-09-29T20:02:24.358200Z

2020-09-29T20:02:30.358800Z

Like, you aren't getting any errors trying to use it, but you have sort of fallen into a crevasse

2020-09-29T20:02:44.359300Z

Where pretty much any change you make will break it

x3qt 2020-09-29T20:02:58.359800Z

Can you show me how this macro should look?

2020-09-29T20:03:22.360600Z

You don't entirely understand how macros work and mixing up your compile time and runtime

x3qt 2020-09-29T20:03:37.361200Z

Yeah, I got it the first time I tried to do it

2020-09-29T20:03:48.361600Z

I would recommend rewriting it without a macro

2020-09-29T20:04:04.361900Z

You don't need one

x3qt 2020-09-29T20:05:01.363700Z

I am coming from ruby and in rails it is very convenient to generate routes and the rest just from the resource name

2020-09-29T20:05:06.363900Z

rest-resource will work just like it does now if you make it regular function

2020-09-29T20:05:32.365Z

And you won't entangle yourself in runtime vs compile time

x3qt 2020-09-29T20:05:41.365200Z

I’ve tried to write it the following way –

(defmacro rest-resource [resource]
  `(context (str "/" ~resource) []
    (GET "/" [] (users/index))
    (POST "/" [] (users/create))
    (GET "/:user-id" [user-id] (users/show user-id))
    (PATCH "/:user-id" [user-id] (users/update user-id))
    (DELETE "/:user-id" [user-id] (users/update user-id))))

x3qt 2020-09-29T20:05:56.365700Z

But it give me clojure.lang.Compiler$CompilerException Syntax error macroexpanding clojure.core/let at (arborist/handler.clj:24:3).

2020-09-29T20:06:30.366700Z

It is just a normal function, you don't need or want a macro

x3qt 2020-09-29T20:07:23.368200Z

You are right, defn is working too

x3qt 2020-09-29T20:07:59.369300Z

So, is there a way to resolve resource name in a place like this?

(GET "/" [] (users/index))

dharrigan 2020-09-29T20:08:13.369700Z

If I may suggest (and if you're not fixed to use only compojure) here's an example of using dynamic routes with reitit - another (also popular) routing library. I haven't used this myself (the dynamic routing), but the example seems quite straight-forward. There's also a comparison with compojure: <https://cljdoc.org/d/metosin/reitit/0.5.6/doc/advanced/composing-routers>

dharrigan 2020-09-29T20:09:03.370Z

(scroll a bit down to dynamic routing)

x3qt 2020-09-29T20:10:09.370200Z

I’ve tried to use resolve, but I am getting null ptr exception

(GET "/" [] ((resolve (symbol (str resource "/index")))))

x3qt 2020-09-29T20:12:36.370700Z

I started clojure just a few days ago, trying to learn by doing a something simple like todomvc

x3qt 2020-09-29T20:12:49.370900Z

Thank you for the proposal, maybe I’ll try it later

2020-09-29T20:13:57.371200Z

I would really recommend spending some time with some clojure tutorial (not sure what would be best)

x3qt 2020-09-29T20:14:27.371700Z

I’ve done a few chapters from the brave clojure

dharrigan 2020-09-29T20:14:30.371900Z

Sure! It's lots of fun. You'll learn lots! 🙂 I put together a simple example of reitit, some db tech and a few other bits and bobs here: https://git.sr.ht/~dharrigan/startrek/tree. It's a very small project. There's also a startrek-ui which is a nice javascripy frontend that also uses reitit and cljs.

🙌 1
x3qt 2020-09-29T20:14:40.372200Z

It’s not much, but gave me something %)

x3qt 2020-09-29T20:15:09.372800Z

So, is there a way to make it work?

(GET "/" [] ((resolve (symbol (str resource "/index")))))

2020-09-29T20:15:15.373Z

have you read the docstring for symbol?

x3qt 2020-09-29T20:15:31.373300Z

No

x3qt 2020-09-29T20:15:39.373500Z

Do you have a link?

2020-09-29T20:15:48.374Z

do you know how to get doc strings in the repl?

x3qt 2020-09-29T20:15:58.374200Z

Not yet

2020-09-29T20:16:03.374400Z

(doc symbol)

x3qt 2020-09-29T20:16:10.374600Z

Yeah, it is

x3qt 2020-09-29T20:16:14.374800Z

Thank you for reminder

x3qt 2020-09-29T20:16:58.375200Z

user=&gt; ((resolve (symbol "+")) 1 2)
3

x3qt 2020-09-29T20:17:09.375500Z

I just can’t get why example above is working and my is not

2020-09-29T20:17:45.376100Z

what arguments can the function symbol take according to its docstring?

x3qt 2020-09-29T20:18:24.376300Z

Returns a Symbol with the given namespace and name. Arity-1 works on strings, keywords, and vars.

x3qt 2020-09-29T20:18:48.376700Z

Is not “users/index” a string too?

x3qt 2020-09-29T20:18:57.377100Z

Because now I see the following

;; Works
    (GET "/" [] (users/index))
    ;; Not works
    (GET "/" [] ((resolve (symbol (str resource "/index")))))

x3qt 2020-09-29T20:19:49.377800Z

(rest-resource "users")

x3qt 2020-09-29T20:19:56.378200Z

resource is a string

x3qt 2020-09-29T20:20:04.378500Z

/index is a string

x3qt 2020-09-29T20:20:16.379100Z

But after coercion it is not converted to symbol

2020-09-29T20:20:29.379500Z

the key thing you are missing here is the significance of / in a symbol

2020-09-29T20:20:48.379800Z

it absolute is converted to a symbol

2020-09-29T20:20:57.380100Z

just not the symbol you want

x3qt 2020-09-29T20:21:09.380300Z

How can I get the symbol I want?

2020-09-29T20:21:17.380600Z

ah

x3qt 2020-09-29T20:21:19.380900Z

Ie get it dynamically from the name

2020-09-29T20:21:34.381200Z

sorry I forget, symbol actually was extended at some point to make that work

2020-09-29T20:21:46.381500Z

so what I thought was the issue isn't

2020-09-29T20:22:00.381800Z

which means the issue is you aren't loading the code

2020-09-29T20:22:39.382400Z

e.g. for resolving to actually look something up the definition has to have been loaded

x3qt 2020-09-29T20:23:22.382600Z

I am not sure I understand

x3qt 2020-09-29T20:23:43.382900Z

How can’t it be loaded in such case?

x3qt 2020-09-29T20:23:52.383100Z

If the first example works

2020-09-29T20:25:27.383700Z

when you print out resource, what does it print when it doesn't work?

2020-09-29T20:26:30.384100Z

are you seeing stack traces when it doesn't work?

x3qt 2020-09-29T20:27:04.384400Z

Aw

x3qt 2020-09-29T20:27:15.384800Z

Resource was not a string at this point

x3qt 2020-09-29T20:27:30.385200Z

(GET "/" [] ((resolve (symbol (str (str resource) "/index")))))

x3qt 2020-09-29T20:27:32.385400Z

Now it works

x3qt 2020-09-29T20:27:37.385700Z

Thank you very much

2020-09-29T20:27:55.385900Z

:{

x3qt 2020-09-29T20:28:31.386300Z

It is strange a bit, because I am passing it to a method as a string

(rest-resource "users")

x3qt 2020-09-29T20:29:01.386700Z

Maybe compoujure somehow converted it

2020-09-29T20:29:06.387Z

no

x3qt 2020-09-29T20:35:19.387600Z

Can you explain a bit more please?

x3qt 2020-09-29T20:35:28.387800Z

Is not a string was passed to a function?

2020-09-29T20:38:23.388600Z

it could get screwed up in a lot of different wants, hard to say without more information

2020-09-29T20:39:22.389700Z

my guess would be you some how ended up in a mishmash state of the world after I suggested switching from a macro to a function

2020-09-29T20:39:44.390200Z

something was still quoted, or something wasn't evaluated right

2020-09-29T20:40:04.390700Z

so a symbol was being passed in instead of whatever the symbol resolved to

2020-09-29T20:41:13.391600Z

(str (str resource) "/index") is, by the definition of the str function identical to (str resource "/index")

2020-09-29T20:41:24.392Z

so changing one for the other is not what fixed things

2020-09-29T20:41:56.392600Z

but in changing one for the other you had to re-load the code which is likely what fixed things

x3qt 2020-09-29T20:42:56.392900Z

You are right, now it’s broken again

x3qt 2020-09-29T20:43:06.393300Z

Code reloading works a bit strange

2020-09-29T20:43:20.393600Z

I would suggest starting a brand new repl

2020-09-29T20:43:32.393900Z

that will start in you in a clean known state

2020-09-29T20:44:08.394600Z

it is very possible to end up in a state where things are broken in a clean known state but work after reloading

2020-09-29T20:44:25.395Z

that is usually the result of having circular dependencies / definitions

2020-09-29T20:50:13.398900Z

a very common way people get themselves in a very broken place is by forgetting that the repl accumulates state. each definition you send, you have to assume it depends on the state of the repl. which is a very different kind of dev cycle if you are used to running things from scratch everytime. there are some tools that try and do things to reset the repl to a known state, but it limited what they can do

x3qt 2020-09-29T20:50:21.399300Z

So it seems to be running ok in repl but not on the server, even after restart

x3qt 2020-09-29T20:51:04.399800Z

¯\(ツ)

2020-09-29T20:51:23.400100Z

that isn't how resolve works

2020-09-29T20:51:47.400700Z

so you have some other code somewhere (maybe a plugin or something) that is screwing with you

2020-09-29T20:51:54.400900Z

resolve never returns a string

x3qt 2020-09-29T20:52:10.401100Z

Resolve retuned a function

x3qt 2020-09-29T20:52:18.401500Z

After a call it is returned a string

x3qt 2020-09-29T20:52:31.401800Z

Mind the braces

2020-09-29T20:52:57.402100Z

resolve returned a var

2020-09-29T20:53:04.402300Z

#' is var quote

2020-09-29T20:53:46.402700Z

what you say it runs ok in the repl but not on the server, what is the server?

x3qt 2020-09-29T20:54:28.403400Z

I am just running lein ring server-headless

2020-09-29T20:54:38.403600Z

meaning, what is are the differences in context between those two things

x3qt 2020-09-29T20:55:04.404Z

Repl is lauched by cider

x3qt 2020-09-29T20:55:07.404300Z

And server from cli

2020-09-29T20:55:31.404600Z

how does the server know to call you code?

x3qt 2020-09-29T20:56:12.404900Z

I am created a project with lein new compojure arborist

x3qt 2020-09-29T20:56:27.405500Z

I thought it knows how to load itself

x3qt 2020-09-29T20:56:37.405800Z

With lein ring server-headless

2020-09-29T20:56:52.406100Z

no idea

x3qt 2020-09-29T20:57:33.407300Z

I’ll try to defn something in the same scope and try to call it with resolve

2020-09-29T20:58:23.408100Z

are you sure the server is calling your code at all? visiting '/' on the server gets what you'd expect?

2020-09-29T20:58:58.408900Z

lein ring has a bad habit of forcing aot compilation, so you might try running lein clean in case something is stale

x3qt 2020-09-29T20:59:19.409500Z

Yeah, it works correctly without resolve

2020-09-29T20:59:22.409600Z

you should get a stacktrace if your code is actually being hit and the resolve is failing