beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
2021-03-04T05:42:25.145700Z

hi, there's much efficient method than this, but I'm stuck with this. any advice? the code is 1. creating a sequence of prime numbers 2. then pairs it 3. then calculate the gap/difference between pairs 4. if the condition met with the pairs' difference it'll return the 1st list of the pairs

(defn is-prime? [n]
  (and (< 1 n)
       (not (some #(= 0 (mod n %)) (range 2 n)))))

(defn prime-seq [from to]
  (filter is-prime? (range from (inc to))))


(defn gap [g m n]
  (first (remove nil?
                  (for [i (vec (partition 2 1 (prime-seq m n)))]
                    (if (= g (- (second i) (first i)))
                      i)))))

2021-03-04T09:32:43.151900Z

(defn gap [g m n]
  (let [primes (prime-seq m n)]
    (for [[m' n'] (map vector primes (next primes))
          :when (= g (- n' m'))]
      m')))
this is not an optimization, but a slight refactoring of the gap function

Sebastian 2021-03-04T06:50:55.146200Z

What exactly is the desired output you are looking for?

Sebastian 2021-03-04T06:52:02.146400Z

If the pair (3 5) meets the condition, you only want to return 3 or a list of the first elements of all pairs that meet the condition?

2021-03-04T06:53:07.146600Z

could the gap function can be optimized more? to give quicker time processed? the code I wrote, is already running okay, but i look for more efficient method

2021-03-04T06:54:05.146800Z

the result is to : return list of the first elements of all pairs that meet the condition

2021-03-04T08:09:42.149800Z

Hi, i got an error with this function

Syntax error (IllegalArgumentException) compiling recur at (*cider-repl 3. Clojure\Practice Learning:localhost:51246(clj)*:59:13).
Mismatched argument count to recur, expected: 2 args, got: 1
What i want to do is like this
(defn searchings
  [y somevec]
  (when (< y (count somevec))
    (if (not (nil? (get somevec y)))
      (get somevec y)
      (recur (inc y)))))
so i can do something like this (searchings 0 [nil nil '(3 5) nil]) and return (3 5) , how to modify the function?

Sebastian 2021-03-04T08:24:36.150800Z

You need to recur with both arguments, currently you only provide y in your recursive call. You need to include somevec as well

Sebastian 2021-03-04T08:25:04.151Z

(defn searchings
  [y somevec]
  (when (< y (count somevec))
    (if (not (nil? (get somevec y)))
      (get somevec y)
      (recur (inc y) somevec))))

โœ… 1
dharrigan 2021-03-04T09:01:31.151200Z

also, the idomatic way is to do (if-not ,,,)

dharrigan 2021-03-04T09:02:20.151400Z

additionally, get will return nil if nothing found, so you could shorten it further

dharrigan 2021-03-04T09:02:55.151600Z

i.e., (if (get somevec y) ,,,)

2021-03-04T11:12:06.152800Z

@sebastian.veile: oooo okay noted. @dharrigan if-not noted.. I'll try... Thanks a lot!

Zรณ 2021-03-04T11:53:51.155100Z

I'm starting to read How to Design Programs and wanted to know how different is Scheme and Clojure. Can I use clojure to follow the book?

2021-03-04T12:23:37.157200Z

Hi everyone, I've tried to solve this, and the code works fine, but it said execution time out 12000 ms which I should revise & made it more efficient. https://www.codewars.com/kata/561e9c843a2ef5a40c0000a4/train/clojure here's my code, any idea how to make this more efficient? I'm kinda stuck here.

(defn is-prime? [n]
  (and (< 1 n)
       (not (some #(= 0 (mod n %)) (range 2 n)))))

(defn prime-seq [from to]
  (doall (filter is-prime? (range from (inc to)))))


(defn gap [g m n]
  (first (remove nil?
        (for [i (vec (partition 2 1 (prime-seq m n)))]
          (if (= g (- (second i) (first i)))
            i)))))

2021-03-04T12:40:07.157400Z

just remove doall from prime-seq function

pavlosmelissinos 2021-03-04T12:48:39.157600Z

(if (get somevec y))
  (get somevec y)
  (recur (inc y) somevec))
can further be shortened to: (or (get somevec y) (recur (inc y) somevec))

raspasov 2021-03-04T12:49:56.157900Z

Not a Scheme expert, but I think quite different. Even though general good software principles are transferable from language to language, you might have a hard time following unless you know both languages quite well. If you really want to read the book, I would stick with Scheme for the time being. If you want to do Clojure, thereโ€™s probably better books out there to teach good Clojure program design.

2021-03-04T12:50:27.158200Z

i've tried that, same result, still time out

raspasov 2021-03-04T12:51:42.158400Z

Perhaps this comment by Rich Hickey is relevant to this discussion https://groups.google.com/g/clojure/c/jyOuJFukpmE/m/aZjWHBnsQ74J

2021-03-04T12:55:02.158600Z

also algorithm is not really eficient I can recommend to read that article - https://www.thesoftwaresimpleton.com/blog/2015/02/07/primes

2021-03-04T12:58:24.159100Z

allrite will read that, and try it on... thank you for sharing

2021-03-04T14:38:50.164300Z

Your isprime is VERY slow. For a start you are checking its not a multiple of all the numbers from 2 to n, you only need to check up to the square root of n. You could also do a check if the number is even and if it is you can exit out early with false.

Fernando de Paula Carvalho 2021-03-04T14:40:57.166Z

Hello. I have a list of maps. Between these maps can have duplicate keys. And I need to "concat" the values of the maps with duplicated keys. List example: (def a '({"a" {"x" "xxx"}} {"b" {"y" "yyy"}} {"a" {"z" "zzz"}})) I need to transform it into: '({"a" {"x" "xxx" "z" "zzz"}} {"b" {"y" "yyy"}}) I'm trying to use "map" with "merge-with" to make it, but it generates a list-result with the same duplicated "a" key. Anyone can help-me?

2021-03-04T14:41:35.166100Z

Maybe faster to generate all the primes under the limit for n, stick them in a set and check against that set when you need to?

tvirolai 2021-03-04T14:44:13.166500Z

(apply merge-with into a) should do it

๐Ÿ’ฏ 1
Fernando de Paula Carvalho 2021-03-04T14:55:23.166700Z

Thanks, solved my problem!!

2021-03-04T16:05:58.169800Z

Whatโ€™s a good way to use Clojure for scripting? What type of setup? My easiest way to start using the language in the real world is to make small file processing scripts. Right now Iโ€™m writing them in Cursive using a regular old project and running them with the repl but once Iโ€™m done I would like to use them as command line scripts I could eg pipe file content to etc. How do I go about that?

dharrigan 2021-03-04T16:09:06.170100Z

wouldn't babashka help?

borkdude 2021-03-04T16:09:32.170300Z

babashka is designed for this use case

borkdude 2021-03-04T16:10:03.170800Z

@anders152 Here is an example: https://twitter.com/RameezKhanSA/status/1367378656679632897

Eamonn Sullivan 2021-03-04T16:21:37.171Z

I've been writing command-line utilities for the last year or so at work -- dev-op kinda things. Lately, I'm a convert to babashka, but sometimes you're doing something a bit more complicated and it isn't yet supported in babashka, like using an internal, private lib or something. I do the following: โ€ข Generate an uberjar โ€ข Write a shell script that you can put on a path somewhere. It should basically just run java -jar <your-uberjar>.jar $@ (the last $@ thing just passes on the args). We have a Homebrew repo at work that automates this for colleagues. They just have to run brew install <my-awesome-cli> and the above steps are done for them. And they don't need to know they were written in Clojure...

Eamonn Sullivan 2021-03-04T16:22:42.171200Z

I haven't yet done this yet, but presumably I should be able to write many of these in babashka now and just make bb a dependency in my Homebrew formulas.

grazfather 2021-03-04T16:26:19.171600Z

#babashka for sure

Hagenek 2021-03-04T16:28:25.172400Z

Hi you lovely people. Does ayoone know: How do I add this library https://docs.datomic.com/on-prem/javadoc/datomic/Util.html to my classpath using Leiningen? I am basically going to use it to read edn-data from a file and turn it into a clojure data structure

dpsutton 2021-03-04T16:31:02.172900Z

is you goal to read a local edn file and turn it into Clojure datastructures?

Hagenek 2021-03-04T16:31:27.173100Z

Yes exactly

Hagenek 2021-03-04T16:31:33.173300Z

Found this now: https://clojure.github.io/clojure/clojure.edn-api.html

dpsutton 2021-03-04T16:31:45.174Z

yup. that's where i was going to point you

๐ŸŽ‰ 1
Hagenek 2021-03-04T16:32:18.174800Z

Letโ€™s see if I can get it to work with IO now ๐Ÿ˜ƒ

raspasov 2021-03-04T16:33:14.175100Z

(clojure.edn/read-string (slurp "deps.edn"))

dpsutton 2021-03-04T16:34:39.175800Z

lots of examples here too: https://grep.app/search?q=edn/read. You can browse to see how people use io/reader in addition to the handy read-string

2021-03-04T16:34:47.176200Z

Will bb support packages from the โ€œofficialโ€ channels?

dpsutton 2021-03-04T16:35:14.176800Z

<http://grep.app|grep.app> is my go-to to find examples. How does a pushbackreader get constructed, etc

Hagenek 2021-03-04T16:37:18.177300Z

Will check it out โ€” Down the rabbit hole I go!

Eamonn Sullivan 2021-03-04T16:44:15.177400Z

I'm barely conversant on babashka still, but on your next CLI, I would just try and see how far you get. For me, running the jar files was working well enough that I hadn't even glanced in babashka's direction. Plus my CLIs are somewhat chunky, so I still think that was the correct approach. For example, I wrote a CLI to query our hundreds of microservices to find those using a particular runtime environment or dependency. That involved combined several different APIs (internal and external) and the tooling for a full-blown Clojure JVM app is just better for that. But if I'm trying to do something that could almost be accomplished with a bash script, but where the script would get into dozens of lines, then I'll use babashka. Best bet: ask in #babashka about your particular use cases.

dharrigan 2021-03-04T17:12:41.177800Z

Be sure to come up for air now and again

telekid 2021-03-04T18:17:51.179400Z

Iโ€™d estimate that a 500 line babashka CLI app is saving my team 1h per person per week, and Iโ€™ve put less then ~5 hours into the script in the last year. Itโ€™s a serious game changer.

Seb 2021-03-04T19:41:15.180500Z

Hello! Just started learning about Clojure this past week. Quick question for anyone: Iโ€™m looking to find an example/project tutorial that walks through building an app that has a clojure backend and a clojurescript frontend

seancorfield 2021-03-04T19:56:04.183600Z

If you're just getting started, you might want to start with a small, purely Clojure web app using just the Ring and Compojure libraries before you also try to learn about ClojureScript tooling -- it is a bit overwhelming for some beginners, depending on their background.

seancorfield 2021-03-04T19:56:43.184500Z

There are no beginner-friendly frameworks in Clojure/Script like there are with many other languages. What are you familiar with @seb.wildwood?

Seb 2021-03-04T19:59:19.185200Z

With regards to programming in general, Iโ€™ve got years of experience in Python/JS/Go and newish experience with Elixir

Seb 2021-03-04T19:59:41.185500Z

Whatโ€™s the best, minimal Clojure stack for a simple REST API that youโ€™d recommend @seancorfield?

seancorfield 2021-03-04T20:08:06.186700Z

I recommend starting with Ring (for the web server abstraction) and Compojure (for routing), and then look at Hiccup (generating HTML from Clojure data) and/or Selmer (Django-style templating).

seancorfield 2021-03-04T20:09:23.187900Z

I often point beginners to this example project https://github.com/seancorfield/usermanager-example but the readme also links to an implementation that uses Reitit for routing (and Integrant instead of Component for managing the start/stop lifecycle of pieces of the app).

seancorfield 2021-03-04T20:10:21.189Z

It's not intended as a step-by-step tutorial, but it is meant to be a well-commented example of what a small, server-side rendered, database-backed Clojure web app might look like.

๐Ÿ™ 1
seancorfield 2021-03-04T20:12:56.190500Z

I don't know what state this online book/tutorial is right now, but it might be a good place to look when you want to start exploring ClojureScript https://practicalli.github.io/clojurescript/ (be aware that the cljs world has a lot of options for how you build stuff). This will probably be helpful for (server-side) Clojure web apps: https://practicalli.github.io/clojure-webapps/

seancorfield 2021-03-04T20:14:00.191500Z

For REST, rather than HTML responses, you could look at compojure-api which builds on top of Compojure to focus on REST API features.

seancorfield 2021-03-04T20:15:19.192900Z

@jr0cket is usually very responsive if you have questions about his online books/tutorials (and he has a great deps.edn file to learn from, for the Clojure CLI). There's also a #practicalli channel to dive deeper into his material.

๐Ÿ‘ 2
Seb 2021-03-04T20:22:58.193100Z

Thanks for the guidance! Much appreciated

Jim Strieter 2021-03-04T21:22:09.194900Z

Hey, I'm a noob. I'm trying to instantiate a class from a local Java jar. The jar is a package which contains more layers of packages, then of course classes.

Jim Strieter 2021-03-04T21:22:38.195500Z

I already added the path to the local jar in :resource-paths in project.clj

Jim Strieter 2021-03-04T21:23:09.196200Z

lein repl starts with no error, so I take that to mean the import statement is correct

Jim Strieter 2021-03-04T21:23:47.197Z

When it comes to instantiate a class from the jar, that's where existing posts (from other forums) don't seem to be relevant

2021-03-04T21:23:54.197400Z

what import? adding to path is not importing and isn't an error if the path specified doesn't exist

Jim Strieter 2021-03-04T21:24:05.197700Z

I'm getting there

2021-03-04T21:24:22.198400Z

instantiating a class is just a question of using it, import is only a convenience so you don't have to type out the full name

2021-03-04T21:24:31.198600Z

classes are loaded when referenced

Jim Strieter 2021-03-04T21:25:54.199100Z

one class in the jar is called AccountValue

Jim Strieter 2021-03-04T21:26:04.199500Z

So in at the repl, I expect to be able to type:

2021-03-04T21:26:13.199900Z

are you trying to create an object of that class, or use a static method?

Jim Strieter 2021-03-04T21:26:19.200100Z

create an object

2021-03-04T21:26:53.200500Z

I didn't meant to interrupt, please do share what you tried and what the error was

Jim Strieter 2021-03-04T21:27:03.200700Z

np

Jim Strieter 2021-03-04T21:27:30.201400Z

Since the repl seems to know the names of things in the namespace, I figure I ought to be able to type 'A', tab

Jim Strieter 2021-03-04T21:27:39.201700Z

and then the repl will offer AccountValue as one of the options

Jim Strieter 2021-03-04T21:27:42.202Z

But that is not happening

2021-03-04T21:27:48.202300Z

a repl won't do that

Jim Strieter 2021-03-04T21:27:52.202600Z

gotcha

Jim Strieter 2021-03-04T21:27:54.202900Z

okay

2021-03-04T21:27:57.203100Z

because you haven't done anything that loads the class

Jim Strieter 2021-03-04T21:28:05.203300Z

ok how do i load the class

2021-03-04T21:28:38.204Z

(foo.bar.AccountValue. arg1 arg2 ...) (replace foo.bar with the real package, and figure out the args you need to the constructor)

2021-03-04T21:28:59.204500Z

or use (import foo.bar.AccountValue) then (AccountValue. ...)

2021-03-04T21:29:45.204900Z

you'd need the import before the "A" autocompletes

Jim Strieter 2021-03-04T21:30:00.205100Z

SUH WEET

Jim Strieter 2021-03-04T21:30:04.205300Z

Thank you man ๐Ÿ™‚

Jim Strieter 2021-03-04T21:30:16.205600Z

:partywombat:

Jonathan Dannel 2021-03-04T21:58:22.206500Z

hey guys, can anyone tell me how i can deal with a response after a POST request with the clj-http package? i honestly can't find anything after googling

ghadi 2021-03-04T22:00:04.206800Z

what did you try @usixjad?

ghadi 2021-03-04T22:00:37.207400Z

post what you evaluated, and what it evaluated to?

Jonathan Dannel 2021-03-04T22:04:01.207700Z

(defn translate [body]
  (let [lang (body "language")
        text (body "text")
        resp (client/post watson
                          {:content-type :json
                           :body "{\"text\":[\"Hello, how are you today?\"],\"model_id\":\"en-es\"}"})]
    resp))

(defroutes app-routes
  (POST "/translate" {body :body}
    (response (translate body))))

Jonathan Dannel 2021-03-04T22:04:05.207900Z

just getting the 500 stacktrace

ghadi 2021-03-04T22:04:24.208200Z

post that

ghadi 2021-03-04T22:04:28.208500Z

in a snippet, please

ghadi 2021-03-04T22:04:34.208700Z

CMD-shift-enter

Jonathan Dannel 2021-03-04T22:05:07.209200Z

the 500 is just the default ring/compojure 500

Jonathan Dannel 2021-03-04T22:05:49.210Z

get requests work fine, and sending back some dummy data to postman in json is fine, but i'm not sure if client/post takes a callback or anything

2021-03-04T22:06:07.210500Z

a 500 sounds like an error on the server side

2021-03-04T22:06:19.210900Z

are you logging stacktraces?

2021-03-04T22:07:02.212100Z

the 500 error that clj-http throws will likely include the stacktrace in the :body

ghadi 2021-03-04T22:07:22.212800Z

posting the error will show whether the 500 is from your route doing something wrong, or a 500 from the endpoint that your route calls

2021-03-04T22:07:27.213Z

alternatively put a try/catch around your call to translate and print any exceptions

2021-03-04T22:08:38.214900Z

very likely translate is throwing an error because whatever body is isn't callable as a function

ghadi 2021-03-04T22:08:41.215Z

another good thing to practice is separating the process of gathering input to a process (here an external call) and making the call itself consider making translate only return the argument to client/post

ghadi 2021-03-04T22:08:55.215400Z

then you can inspect that at the REPL to ensure it's legit

ghadi 2021-03-04T22:09:04.215600Z

then... make the call

ghadi 2021-03-04T22:10:01.216500Z

but back to the errors, they're not some annoyance from Java, they contain useful context

ghadi 2021-03-04T22:11:07.217500Z

I am not (yet) sure from your description that you are drawing the right conclusion https://clojurians.slack.com/archives/C053AK3F9/p1614895507209200

Jonathan Dannel 2021-03-04T22:13:21.217900Z

ah, give me a moment

Jonathan Dannel 2021-03-04T22:37:59.218500Z

okay, sorry about that. i was using my API key wrong, and i've gotten it to work with postman; you're right -- the request was failing because i wasn't authenticated

Jonathan Dannel 2021-03-04T22:38:05.218800Z

(defn translate []
  (let [resp
        (client/post watson
                     {:content-type :json
                      :basic-auth ["apikey" apikey]
                      :body "{\"text\":[\"Hello, how are you today?\"],\"model_id\":\"en-es\"}"})]
    (response resp)))

(defroutes app-routes
  (POST "/translate" {body :body}
    (translate)))

Jonathan Dannel 2021-03-04T22:38:26.219300Z

i've modified my code so that i'm not actually taking any request params or anything now, just sending a simple string to the API

Jonathan Dannel 2021-03-04T22:38:37.219800Z

my question still stands with how to get the response back. here's the stacktrace

Jonathan Dannel 2021-03-04T22:38:52.220100Z

ghadi 2021-03-04T22:39:49.221100Z

it's important to structure your code so that you can bang on stuff while you write working dough vs. setting into motion a large Rube Goldberg machine by dropping a marble

Jonathan Dannel 2021-03-04T22:40:10.221400Z

yep ๐Ÿ˜› very new to clojure still so..

ghadi 2021-03-04T22:40:41.221900Z

what is the main error you see?

Jonathan Dannel 2021-03-04T22:40:46.222200Z

in the stacktrace, it's clear that i'm binding the actual http client object to a variable

ghadi 2021-03-04T22:41:42.222600Z

nope

ghadi 2021-03-04T22:42:15.223100Z

call (translate), then inspect your result

ghadi 2021-03-04T22:42:21.223400Z

break the problem down

ghadi 2021-03-04T22:43:16.223900Z

com.fasterxml.jackson.core.JsonGenerationException
Cannot JSON encode object of class: class org.apache.http.impl.client.InternalHttpClient: org.apache.http.impl.client.InternalHttpClient@2e20c4f7

ghadi 2021-03-04T22:43:38.224400Z

that's the main cause listed in the trace

ghadi 2021-03-04T22:44:11.225Z

the JSON generator appears to be trying to serialize the HTTP Client itself into the payload

ghadi 2021-03-04T22:44:37.225500Z

I should be clearer: call (translate) from within your REPL

Jonathan Dannel 2021-03-04T22:57:41.227700Z

ah, finally

Jonathan Dannel 2021-03-04T22:57:44.228Z

(defn translate []
  (let [resp
        (client/post watson
                     {:content-type :json
                      :basic-auth ["apikey" apikey]
                      :body "{\"text\":[\"Hello, how are you today?\"],\"model_id\":\"en-es\"}"})]
    (get resp :body)))

(defroutes app-routes
  (POST "/translate" []
    (response {:result (translate)}))
  (route/not-found "&lt;h1&gt;Page not found&lt;/h1&gt;"))
  

Jonathan Dannel 2021-03-04T22:58:32.228600Z

the response map being nil was the problem, i guess

ghadi 2021-03-04T23:01:42.229100Z

great, but don't guess!

Jonathan Dannel 2021-03-04T23:02:41.230100Z

yeah, still trying to figure out exactly why..

ghadi 2021-03-04T23:02:58.230600Z

translate used to return the whole response from clj-http -- but now you're picking out a particular piece of it (`:body`)

Jonathan Dannel 2021-03-04T23:03:34.231600Z

and sending the actual hash map for it to be valid json

ghadi 2021-03-04T23:03:36.231700Z

I haven't looked at clj-http in a while, but there must have been some additional stuff being returned that the JSON serializer didn't know how to handle

Jonathan Dannel 2021-03-04T23:03:44.232Z

{:result xxx}

ghadi 2021-03-04T23:04:08.232600Z

vs {:result whole-response-from-clj-http}

Jonathan Dannel 2021-03-04T23:04:27.232800Z

ahh, i see what i was doing incorrectly

Jonathan Dannel 2021-03-04T23:04:41.233100Z

is this generally the way to deal with responses from post requests?

ghadi 2021-03-04T23:05:02.233500Z

maybe? depends on the http library being used

ghadi 2021-03-04T23:05:12.233900Z

this is generally the way I debug any issue though

Jonathan Dannel 2021-03-04T23:05:28.234500Z

i'm so used to promises in javascript.. will execution halt until there is a success/failure?

ghadi 2021-03-04T23:05:36.234800Z

break it down, evaluate in my editor, put it back together

ghadi 2021-03-04T23:05:46.235100Z

correct, this library happens to be synchronous

ghadi 2021-03-04T23:06:26.235800Z

there are options to provide a callback, or you can run it in a future, or use a different lib

Jonathan Dannel 2021-03-04T23:07:07.236600Z

i asked the question initially because i honestly couldn't find anything saying that client/post may accept a callback

Jonathan Dannel 2021-03-04T23:07:17.237Z

guess i didn't look hard enough

ghadi 2021-03-04T23:07:28.237300Z

yeah clj-http is one of the oldest libs out there, it's accrued piecemeal design over time

Jonathan Dannel 2021-03-04T23:08:15.238100Z

i usually pride myself in my debugging, but learning clojure is kind of throwing me for a loop tbh

Jonathan Dannel 2021-03-04T23:08:21.238300Z

guess i'll take it slower

ghadi 2021-03-04T23:08:59.238700Z

when I started with Clojure, it took me about 6 months to "get it"

ghadi 2021-03-04T23:09:12.239100Z

I was pretty new to programming at the time, and I had to unlearn all the OOisms

ghadi 2021-03-04T23:09:31.239500Z

but yeah, working with the REPL like you're working dough

Jonathan Dannel 2021-03-04T23:10:19.240600Z

speaking of that, i actually wasn't able to get into my repl

ghadi 2021-03-04T23:10:33.240900Z

it's super fun, much more productive than set up magic entry point that prearranges the world -> compile -> wait -> pray

ghadi 2021-03-04T23:11:14.241800Z

so this is something i'm noticing with a lot of Clojure developers, even experienced ones

ghadi 2021-03-04T23:11:20.242Z

...not using the REPL

ghadi 2021-03-04T23:11:35.242500Z

doing something like lein test every time you save a file, etc.

Jonathan Dannel 2021-03-04T23:11:51.243100Z

so, i run lein repl and immediately get pages of errors

Jonathan Dannel 2021-03-04T23:12:02.243600Z

and i don't actually know how to load the namespace

Jonathan Dannel 2021-03-04T23:12:06.243900Z

lol

ghadi 2021-03-04T23:12:07.244Z

post em in a snippet

ghadi 2021-03-04T23:12:11.244200Z

don't give up ๐Ÿ™‚

ghadi 2021-03-04T23:12:23.244500Z

which editor are you using?

ghadi 2021-03-04T23:12:53.245600Z

you really don't want to use the terminal REPL (but still shouldn't have any stacktrace from it)

dpsutton 2021-03-04T23:13:00.245900Z

and there's a general truism, don't make loading namespaces do work. makes it close to impossible to not be able to get into a repl or require namespaces. this can often be why things break before you can get at them

Jonathan Dannel 2021-03-04T23:13:37.246100Z

dpsutton 2021-03-04T23:14:11.247Z

you probably have an old cider/cider-nrepl in your ~/.lein/profiles.clj

ghadi 2021-03-04T23:14:18.247200Z

I gotta run -- but there are hundreds of people here that can continue helping -- happy trails!

Jonathan Dannel 2021-03-04T23:14:27.247400Z

thanks so much @ghadi, really appreciate it ๐Ÿ˜„

Jonathan Dannel 2021-03-04T23:14:42.247800Z

@dpsutton i'll check my profiles file

dpsutton 2021-03-04T23:15:04.248300Z

or somehow you're getting cider related stuff into the project

Jonathan Dannel 2021-03-04T23:15:38.248500Z

this is my profiles.clj

Jonathan Dannel 2021-03-04T23:15:42.248800Z

{:user {:dependencies [[nrepl "0.8.3"]
                       [cljfmt "0.5.1"]]
        :plugins [[cider/cider-nrepl "0.25.5"]
                  [lein-cljfmt "0.7.0"]]}}

Jonathan Dannel 2021-03-04T23:16:32.249300Z

not sure why i have both nrepl and cider-nrepl

Jonathan Dannel 2021-03-04T23:16:39.249600Z

i think i might have added it for vim functionality

Jonathan Dannel 2021-03-04T23:20:23.249900Z

removing the cider plugin seems to have solved that

Jonathan Dannel 2021-03-04T23:21:19.250200Z

ty @dpsutton

dpsutton 2021-03-04T23:22:50.250900Z

excellent. if you need those back, there was an issue with that version of cider-nrepl. replacing it with "0.25.9" should fix it

omendozar 2021-03-04T23:40:51.252Z

hi, how can I turn this seq (\0 \0 \1 \1 \4 \0 \1 \7 \8 \0 \0 \1 \6) into a number 11401780016 ?

2021-03-04T23:45:11.252600Z

shortest path is probably (-&gt;&gt; your-input (apply str) (Long/parseLong))

2021-03-04T23:45:39.253200Z

but usually if you have a seq of characters like that you started with a string, and that's something that can go to parseLong

omendozar 2021-03-04T23:49:00.255100Z

I have this string โ€œ0011401780016Xโ€ and I would like to separate the last digit (which is always a letter) and the numbers to do some arithmetic operations

dpsutton 2021-03-04T23:52:47.255500Z

(let [input "0011401780016X"] (Long/parseLong (subs input 0 (dec (count input)))))

1
omendozar 2021-03-04T23:52:56.255700Z

Got it with subs and nth

dpsutton 2021-03-04T23:53:15.256Z

just beware of empty strings. subs can be brutal

omendozar 2021-03-04T23:54:17.256800Z

Iโ€™m performing a regex validation before I get to this point, thank you

๐Ÿ‘ 1
2021-03-04T23:56:49.257200Z

reduce would be more fun

2021-03-04T23:58:19.257700Z

user=&gt; (reduce (fn [n digit] (+ (* n 10) (Character/digit digit 10))) 0 '(\0 \0 \1 \1 \4 \0 \1 \7 \8 \0 \0 \1 \6))
11401780016
user=&gt;