Fork me on GitHub
#beginners
<
2020-06-02
>
Michael W04:06:38

I have a function that I need help simplifying. I cannot figure out how to reduce the duplication here and it's driving me nuts. query+ here: https://github.com/michaelwhitford/clojure-swapi/blob/b1bed07bd2c69fda528875b0314163f73de05daa/src/swapi/core.clj#L27 It's a simple toy I am using to learn clojure.

seancorfield04:06:59

You could write a function that accepts a string and does the three defs, and then run! that function over a list of all the things you want the shortcuts for.

seancorfield04:06:59

(it might be easier to do it with a macro since def is a special form, but you could use intern instead I think)

Michael W04:06:48

I guess I don't understand where the string would come from

Michael W04:06:15

I'm thinking about the duplication of the let expressions in query+ I think I should be able to simplify that duplication down to just the function I create for the future.

seancorfield04:06:30

@UAB2NMK25 what about this

(defn query+
  "asynchronous query to swapi.dev
    `action` required: people planets films starships vehicles species
    `id` optional"
  [pool action & args]
  (let [deferred (d/deferred pool)
         id (first args)
         chain (d/chain deferred #(future (if id (query! action %) (query! %))))]
    (d/success! deferred (or id action))
    chain))

Michael W00:06:05

That is exactly what I was trying to think of, I forget that if is just another expression and not a special form like in other languages.

seancorfield01:06:59

Cool. Yeah, that shift from statements and special forms in some languages to a very uniform expression-based approach in Clojure can be a big shift. I actually have problems when I have to go the other way and deal with some non-Clojure code.

seancorfield01:06:45

We have a legacy code base that I still have to work in from time to time and I quite often write something that is too "Clojure-y" for that language's compiler 🙂

Michael W03:06:50

Thanks again for the help, I updated github with the changes and my first macro. I am really liking this language.

seancorfield03:06:42

I'm very happy we made the change to Clojure ten years ago. I've never been happier with a language in my 35+ years of software development!

Michael W04:06:38

It works perfectly the way it is but that duplication just bugs my ocd.

seancorfield04:06:01

Which duplication are you trying to get rid of then? Sorry, I thought you meant all those triple def expressions.

seancorfield04:06:32

I wasn't trying to solve any duplication inside query+ sorry 🙂

Spaceman04:06:02

For some reason my docker file with lein uberjar in it gives the following error on a push

[Enumerating objects: 1986, done.
Counting objects: 100% (1984/1984), done.
Delta compression using up to 16 threads
Compressing objects: 100% (1901/1901), done.
Writing objects: 100% (1942/1942), 28.23 MiB | 1.87 MiB/s, done.
Total 1942 (delta 646), reused 0 (delta 0)
remote: Compressing source files... done.        
remote: Building source:        
remote: === Fetching app code
remote: 
remote: === Building web (Dockerfile)        
remote: 
remote: =!= Dockerfile parse error line 40: unknown instruction: LEIN        
remote: Verifying deploy...
remote: 
remote: !	Push rejected to vendomarch.        
remote: 
To 
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ''

seancorfield04:06:59

@pshar10 Dockerfile parse error line 40: unknown instruction: LEIN is probably a big clue...

Spaceman04:06:18

@seancorfield lein works in the console directly

Spaceman04:06:36

I thought that would be obvious

seancorfield04:06:45

Your Dockerfile is invalid according to that error.

Spaceman04:06:16

@seancorfield you know docker? Here you go:

# We will use Ubuntu for our image
FROM ubuntu:latest

# Updating Ubuntu packages

ARG CLOJURE_TOOLS_VERSION=1.10.1.507


RUN apt-get -qq update && apt-get -qq -y install curl wget bzip2 openjdk-8-jdk-headless \
    && curl -sSL  -o /tmp/miniconda.sh \
    #    && curl -sSL  -o /tmp/miniconda.sh \
    && bash /tmp/miniconda.sh -bfp /usr/local \
    && rm -rf /tmp/miniconda.sh \
    && conda install -y python=3 \
    && conda update conda \
    && curl -o install-clojure  \
    && chmod +x install-clojure \
    && ./install-clojure && rm install-clojure \
    # no need to install lein
    && wget  \
    && chmod a+x lein \
    && mv lein /usr/bin \


    && apt-get -qq -y autoremove \
    && apt-get autoclean \
    && rm -rf /var/lib/apt/lists/* /var/log/dpkg.log \
    && conda clean --all --yes



ENV PATH /opt/conda/bin:$PATH

RUN conda create -n pyclj python=3.7 && conda install -n pyclj numpy mxnet \
    && conda install -c conda-forge opencv
## To install pip packages into the pyclj environment do
RUN conda run -n pyclj python3 -mpip install numpy opencv-python

FROM openjdk:8-alpine
lein uberjar
COPY target/uberjar/vendo.jar /vendo/app.jar

EXPOSE 3000

CMD ["java", "-jar", "/vendo/app.jar", "--server.port=$PORT"]

seancorfield04:06:39

Don't post walls of text into Slack -- they're unreadable.

seancorfield04:06:53

Can you post a link to this code on GitHub instead?

seancorfield04:06:11

That way we can see line numbers and also clone it to look at.

Spaceman04:06:28

it's not on it. Just read it @seancorfield.

picard-facepalm 12
👎 23
seancorfield04:06:41

Don't be rude. I'm trying to help you.

seancorfield04:06:59

Your Dockerfile has a syntax error. Read teh error yourself.

seancorfield04:06:07

Look at line 40 -- it is NOT valid.

dpsutton04:06:16

You call “lein uberjar” but every other she’ll command is behind a RUN syntax

seancorfield04:06:08

Hey! I pointed out what the error was in your file.

👆 20
seancorfield04:06:36

You are being very rude.

solf09:06:52

I feel compelled to tell you that when I first started learning clojure 1-2 years ago, I was really impressed by how often you helped new people, me included. And I'm astonished that after all that time, you still do it. Really big thanks!

❤️ 28
raspasov04:06:52

come on guys, keep it civil 🙂

Murf05:06:09

brand new to Clojure! Any help would be much appreciated on best resources to get started at? Videos, articles, guides, etc. Thanks in advance! I am a PowerShell / .NET / VB scripter with some PHP and javascript experience and now wanting to learn Clojure as I have heard so much good stuff about it 🙂

raspasov05:06:00

This was the first Clojure/Rich Hickey talk I watched back in 2013 https://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey/

raspasov05:06:04

I highly recommend it

Murf05:06:32

awesome thanks! I will take a look. Then where do you recommend I start with the basics of learning clojure and experimenting? Any good trainings/tutorials/youtube channels/videos/guides etc.?

raspasov05:06:06

Depends on your style of learning… I picked up a book and started typing in examples

raspasov05:06:48

After a few weeks/months of practice, tried to make a working backed API with it; that’s where you learn the most

👍 4
raspasov05:06:35

This is a very good guide IMO

raspasov05:06:14

It’s a bit dated

raspasov05:06:31

but very good

Murf05:06:19

thanks I actually have that on my list from another recommendation so x2 means I should definitely start there at clojure from the ground up. Appreciate it.

raspasov05:06:22

“bit dated” I mean that you don’t really need to use “lein” nowadays, you can just “brew install clojure” (on Mac)

raspasov05:06:52

(not sure what you environment is)

raspasov05:06:01

But the apart from the build tools, the advice in Aphyr’s guides is very solid and probably will never be dated as far as Clojure the language is concerned

Murf05:06:49

I am on Windows... I know people will probably laugh at me 😉

raspasov05:06:44

No they won’t; I was a long-time Windows user myself before I switched to Linux and MacOS later

raspasov05:06:35

I can’t be of much help with Windows specifically nowadays, but other than that, happy to help!

Murf06:06:26

Ok so I wanted to organize the "from the ground up" course and I notieced that there were plans in the 2nd to last post titled Roadmap of a bunch more stuff and then it seemed to end with the "debugging" chapter? Do you know if that is the case? or did it finish / continue somewhere else?

Murf06:06:37

I have the following: 1. Welcome 2. Basic types 3. functions 4. sequences 5. macros 6. state 7. logistics 8. modeling 9. *roadmap* 10. debugging And then it kind of suddenly ended?

seancorfield06:06:33

I suspect the author thought it was a "good enough" guide to get folks started and just hoped he might come back to it and extend it some day...

seancorfield06:06:07

Just seen your comment about Windows -- that will definitely make your Clojure learning journey harder: most of the tooling and books / tutorials are written for macOS/Linux. There is a lein.bat for Windows -- I can't remember how smooth that process is (I haven't really used Leiningen for years now).

seancorfield06:06:59

Since you are comfortable with Powershell, you might consider going the Scoop installer route and using the Clojure CLI / deps.edn stuff that is described on http://clojure.org https://www.clojure.org/guides/getting_started but using the Scoop installer described at the bottom of https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows#questions

seancorfield06:06:57

I use Scoop on Windows and the Clojure CLI / deps.edn stuff (on macOS/Linux, I use Homebrew -- but still the Clojure CLI / deps.edn stuff).

seancorfield06:06:30

At least with Scoop, it also makes it easy to install a JDK (Java/JVM) and various other useful Clojure tools (like clj-kondo the command line linter behind the linter-kondo package for Atom).

raspasov06:06:51

@samdynamicsllc yea it’s not a complete end-to-end guide but it’s enough to get you started; it’s more like quality vs quantity type of thing

practicalli-johnny08:06:00

@samdynamicsllc I have over 70 hours of videos on Clojure at https://practicalli.github.io/ and a few books to help too.

Murf13:06:27

Wow @U05254DQM that’s amazing! Thanks! Do you have a recommendation where to start? There Is alot there!

practicalli-johnny13:06:08

It depends what you want to learn. I have a collection of play lists that separate the videos into groups, see the list of playlists on https://practicalli.github.io/ To practice Clojure and learn some of the clojure.core library, then http://4Clojure.com is a great site. I have guides that walk through the first 60 or so challenges, but try solve them yourself first, especially the first 20 challenges 🙂 If you want to build something, then there is the webapps playlist and I will dig out some of the ClojureScript single page apps videos and create a playlist for those too. I am also updating the practicalli Clojure book, which should give a more clearer structure to learning Clojure. I recommend using deps.edn projects and the Clojure command line tools, although there is nothing wrong with Leiningen, these newer tools I find a bit more flexible and simpler to work with. If you are on developing on Windows, then I recommend the #clj-on-windows channel for help with some Clojure tooling if you get stuck, although if you have powershell everything should work okay. I think https://scoop.sh/ is the recommended approach for installing Clojure

Murf13:06:52

Amazing! Thanks so much. I just joined that channel and I’ll start digging into all your stuff. Much appreciated.

raspasov05:06:46

@samdynamicsllc very cool… I came to Clojure myself from a PHP background

👍 4
gibb09:06:34

@pshar10 Please be nice to people helping you and everyone else here. Being rude here discourages people helping - don't do it.

🎯 32
futurile09:06:22

Q: I have a small function that uses loop/recur. Inside it I have an if. On the if true path, I want to do more than one thing - I want to print and I want to recur. Is this possible? The function works fine if I just recur, but I can't figure out how to print. I thought I needed do to print and then recur, but can't figure it out.

hindol09:06:49

You can fit multiple things into a single expression using (do ...) . E.g.

(if true
  (do
    (println "")
    ...do something else...)
  (...this is the else part...))

hindol09:06:50

The last thing in the do will be returned.

hindol09:06:31

Function body, let, even loop/recur have an implicit do inside - this is why you can have multiple expressions in them.

hindol09:06:02

If you can post what you have tried, I can check what is going wrong.

futurile09:06:56

@UJRDALZA5 I got it. I must have made a syntax error and didn't see it - and that got me confused - as the do works fine

futurile09:06:14

Oops sorry! (defn read-input [^Terminal terminal] (loop [keystroke (. terminal readInput) result ""] (if (= :enter (key-codes (. keystroke getKeyType))) (str result) (do (put-string terminal (str (. keystroke getCharacter))) (recur (. terminal readInput) (str result (. keystroke getCharacter)) ) ) ) ) )

futurile09:06:54

@UJRDALZA5 thanks, got the rest of it working. Appreciated!

👍 8
sova-soars-the-sora12:06:34

Has anyone made custom filters with Selmer before? I would like to add a filter to do bold or underlined text, but just small segments within larger strings. Like "Hey there :u:world:u:" would underline world ... any advice on how i can go about getting this behavior?

sova-soars-the-sora12:06:05

Or maybe some other way of doing what are effectively custom HTML tags in selmer

timonkot1313:06:33

Hello, I downloaded clojure CLI Tools throught powershell on Windows 10. But when I type "clj", I get that message: "Error: Could not find or load main class clojure.main". Anyone had that problem?

hindol13:06:24

Is your Java setup properly?

timonkot1313:06:48

i set path to JAVA_HOME like that C:\Program Files\Java\jdk1.8.0_251

timonkot1313:06:03

But before it was jre. After seeking the way to resolve problem I installed Jdk, but it not resolve problem

hindol14:06:35

Are you running clj command in a project root directory? EDIT: That should not matter. Just tried on my machine.

timonkot1315:06:50

it is not working for you too? I tryed to call it inside the Modules/ClojureTools, but it not help at all.

seancorfield15:06:44

@U014M4DMY7L When you say you "downloaded clojure CLI Tools" for Powershell, what steps exactly did you take? Scoop is really the easiest way to get it working on Windows (and that can install Java and other tools too).

timonkot1317:06:02

I am just execute this file via powershell as administrator -> https://download.clojure.org/install/win-install-1.10.1.536.ps1.

timonkot1317:06:46

I am tried scoop and all go well until this Creating shim for 'cmd-clojure'. Can't shim 'powershell.exe': File doesn't exist. https://github.com/littleli/scoop-clojure <- I was followed that instruction, but when i got this on "scoop install clojure". Why it can't find powershell.exe?

seancorfield17:06:10

Hmm, that is odd... can you jump into #clj-on-windows and provide some details and tag @UBLU3FQRZ there in your question? (he's more likely to see it in that channel and there are a bunch of Windows users there who might be able to help in more detail)

Clark Urzo15:06:33

Going through a bunch of Clojure books right now after being fed up with JS for the nth time

Clark Urzo16:06:47

Really, really minor thing, but I just wanted to ask: why does indexing in anonymous functions start from 1 instead of 0?

Clark Urzo16:06:40

Like, I expected #(* %0 %1) would work but apparently the first argument is indeed bound to %1

Clark Urzo16:06:59

Does %0 carry a special meaning in other contexts? E.g., the name of the file being called like in Bash, or...?

Michael J Dorian16:06:40

I don't think it's always wrong to index starting at one. I would say "the first argument" if I were speaking about it. There may or may not be a specific rational but it feels natural to me

👍 4
delaguardo16:06:16

there are no reasons to start indexing with 0 ) in any context or language )

Michael J Dorian16:06:43

I wouldn't say that either. 🤷 https://xkcd.com/163/

delaguardo16:06:39

> Does `%0` carry a special meaning in other contexts? the answer would be - no, there are no special meaning for %0 in clojure

👍 4
Clark Urzo16:06:46

But it really is just a minor thing and I don’t want to start a fight so...yeah thanks! Load off my mind.

delaguardo16:06:09

it is just a convention syntax, that’s all

noisesmith16:06:32

I think the fact that in a shell $0 is the function / script itself, and $1 is the first arg could be related to #() args starting with %1

noisesmith16:06:52

but % has no meaning outside #() blocks

noisesmith16:06:45

mod could have been named % but clearly wasn't

Clark Urzo16:06:55

@noisesmith Yeah, that was my first guess as well.

Clark Urzo16:06:09

But I guess maybe I’m just reading into it too much

noisesmith16:06:33

conventions come from a lot of places and the only rule is that things seem familiar and unsurprising

noisesmith16:06:46

and once it's implemented, you need to stick with it for simple compatibility reasons

delaguardo16:06:07

there is one thing that surprise me a bit when I first saw it: you can use % and %1 in the same lambda and they both will stand for “first argument” (#(prn % %1 %2) 1 2)

Cas Shun16:06:41

Is there a function to to go from :ns/key to "ns/key", or do I need to do something like (subs (str :ns/key) 1)

noisesmith16:06:59

user=> (symbol :foo/bar)
foo/bar
if you call str on the symbol you get what you expect

noisesmith16:06:09

bonus, this also works with non-namespaced keywords

Cas Shun16:06:41

user=> (symbol :foo/bar)
ClassCastException clojure.lang.Keyword cannot be cast to java.lang.String

hiredman16:06:29

you need a newer version of clojure

hiredman16:06:45

check clojure-version

Cas Shun16:06:56

Ok cool, I see. Project I'm hacking on is on 1.8

Simon16:06:58

Hi everyone, I'm working through Clojure for the Brave and True and have been confused why my implementation of update-in won't work. I figured (nudged by the proximity to the exercise "implement assoc-in") that I could implement it in terms of assoc-in, and attempted to do so with the code block below, but this throws up either ArityException or ClassCastException with everything I test it with. Is there some subtlety I'm missing here?

Kazuki Yokoyama17:06:15

I'm not sure the syntax [& ks] will work as you expect in the parameters list. Since ks is already a collection, you have to do nothing but [m ks f & args] (this is the signature of the update-in method). Another point is that args are collected as a sequence, so you have to "split" them when you call f . One way to accomplish it is with (apply (partial f (get-in m ks)) args) .

Simon17:06:06

thank you, this is very helpful!

👍 4
Simon16:06:16

(defn alt-update-in
  [m [& ks] f & args]
  ((assoc-in m [ks] (f (get-in m ks) args))))

noisesmith16:06:38

@srdocherty ((f)) means "call f, then call whatever f returns"

noisesmith16:06:44

it's pretty much never rarely what you want

noisesmith16:06:48

another way to put it which helped me: (f) in clojure is the same as f() in js etc. so ((f)) is the same as f()()

👁️ 4
noisesmith16:06:36

@srdocherty regarding the exception - this is why you get arity exception:

user=> ({})
Execution error (ArityException) at user/eval191 (REPL:1).
Wrong number of args (0) passed to: clojure.lang.PersistentArrayMap
and this is why you get a class cast exception
user=> (1)
Execution error (ClassCastException) at user/eval193 (REPL:1).
class java.lang.Long cannot be cast to class clojure.lang.IFn (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IFn is in unnamed module of loader 'app')

noisesmith16:06:01

a map is a function, but needs a key when you call it, most other things just aren't functions

noisesmith16:06:34

from another angle (maybe the most intuitive one): parens aren't free in clojure, adding them changes the meaning of the thing you wrapped by attempting some operation

noisesmith16:06:19

also, more subtly, ks is already a collection, putting it in [ks] isn't what you want

Simon17:06:47

Aha, so the first problem is that assoc-in shouldn't be wrapped in its own parentheses for the function body, as it's trying to call the map that assoc-in produces as a function without an argument

noisesmith17:06:12

right - one layer of parens is enough

noisesmith17:06:49

I'm not sure what you meant by "in its own parenthesis" as it already had its own, and extra were added after that

Simon17:06:39

haha yes, that was a bad way of putting it. Thanks for the pointers!

🍻 4
andy.fingerhut17:06:21

In general in all Lisp family languages, including Clojure, parentheses are significant. In the right-hand side of an assignment statement in Java/C/C++, etc., you can often add "redundant parentheses" around parts of an expression, and it still means the same thing. That is not true in Lisps.

noisesmith17:06:07

on the other hand adding an extra () to the right of an expression in those languages is the same error we saw here

noisesmith17:06:45

(or same confusing behavior, when the thing was technically invocable but that wasn't the intention)

Xarlyle019:06:03

Does 4clojure not support lazy sequences? I put an answer to #137 that works in http://repl.it, using a lazy sequence, but results in a "java.lang.ArithmeticException: integer overflow" in 4clojure

seancorfield20:06:29

Did you attempt all of the tests that 4clojure shows for that, when using http://repl.it? A couple of those tests have potential for overflow, depending on your solution...

seancorfield20:06:55

(I don't think 4clojure runs additional tests that it doesn't show)

noisesmith20:06:23

to address the direct question, 4clojure fully supports laziness

noisesmith20:06:11

I'm trying to think of how you'd get integer overflow in one place and not the other - it could be related to 4clojure using 1.5, where some ops might not auto-promote the same way they do now(?)

Xarlyle020:06:06

All test cases work, but the first case produces the overflow on 4clojure

noisesmith20:06:40

do you mind sharing the code?

Xarlyle020:06:03

We'll do it in a thread

Xarlyle020:06:45

(fn [numm base]
  (let [expt   (fn [x n] (reduce * (repeat n x)))
        powers (take-while #(or (<= % numm) (= % 1)) (map #(expt base %) (range)))]
    (second (reduce
      (fn [[value arr] cur] [(mod value cur) (conj arr (quot value cur))])
      [numm []]
      (reverse powers)))))

noisesmith20:06:24

OK - I can replicate that error in 4clojure, and not in my local repl - I am going to try older clojure and see what the actual error is...

noisesmith20:06:24

so this is the stack trace:

noisesmith20:06:24

java.lang.ArithmeticException: integer overflow
        at clojure.lang.Numbers.throwIntOverflow(Numbers.java:1374)
        at clojure.lang.Numbers.multiply(Numbers.java:1738)
        at clojure.lang.Numbers$LongOps.multiply(Numbers.java:442)
        at clojure.lang.Numbers.multiply(Numbers.java:146)
        at clojure.core$_STAR_.invoke(core.clj:951)
        at clojure.core.protocols$fn__5558.invoke(protocols.clj:64)
        at clojure.core.protocols$fn__5543$G__5538__5552.invoke(protocols.clj:11)
        at clojure.core$reduce.invoke(core.clj:5995)
        at clojure.core$reduce.invoke(core.clj:5991)
        at user$f$expt__20.invoke(foo.clj:3)
        at user$f$fn__25.invoke(foo.clj:6)
        at clojure.core$map$fn__3811.invoke(core.clj:2430)
        at clojure.lang.LazySeq.sval(LazySeq.java:42)
        at clojure.lang.LazySeq.seq(LazySeq.java:60)
        at clojure.lang.RT.seq(RT.java:466)
        at clojure.core$seq.invoke(core.clj:133)
        at clojure.core$take_while$fn__3840.invoke(core.clj:2509)
        at clojure.lang.LazySeq.sval(LazySeq.java:42)
        at clojure.lang.LazySeq.seq(LazySeq.java:60)
        at clojure.lang.RT.seq(RT.java:466)
        at clojure.core$seq.invoke(core.clj:133)
        at clojure.core$print_sequential.invoke(core_print.clj:46)
        at clojure.core$fn__4990.invoke(core_print.clj:140)
        at clojure.lang.MultiFn.invoke(MultiFn.java:167)
        at clojure.core$pr_on.invoke(core.clj:3264)
        at clojure.core$pr.invoke(core.clj:3276)
        at clojure.lang.AFn.applyToHelper(AFn.java:161)
        at clojure.lang.RestFn.applyTo(RestFn.java:132)
        at clojure.core$apply.invoke(core.clj:600)
        at clojure.core$pr.doInvoke(core.clj:3282)
        at clojure.lang.RestFn.applyTo(RestFn.java:139)
        at clojure.core$apply.invoke(core.clj:600)
        at clojure.core$prn.doInvoke(core.clj:3309)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invoke(core.clj:600)
        at clojure.core$println.doInvoke(core.clj:3329)
        at clojure.lang.RestFn.invoke(RestFn.java:457)
        at user$f.invoke(foo.clj:7)
        at user$eval32.invoke(283b967690b743aa3c81baf2afdf34941270d357d78e11bc4f8e9c68e1
b9e8f7-init.clj:2)
        at clojure.lang.Compiler.eval(Compiler.java:6465)
        at clojure.lang.Compiler.eval(Compiler.java:6431)
        at clojure.core$eval.invoke(core.clj:2795)
        at clojure.main$repl$read_eval_print__5967.invoke(main.clj:244)
        at clojure.main$repl$fn__5972.invoke(main.clj:265)
        at clojure.main$repl.doInvoke(main.clj:265)
        at clojure.lang.RestFn.invoke(RestFn.java:421)
        at clojure.main$repl_opt.invoke(main.clj:331)
        at clojure.main$main.doInvoke(main.clj:427)
        at clojure.lang.RestFn.invoke(RestFn.java:397)
        at clojure.lang.Var.invoke(Var.java:397)
        at clojure.lang.AFn.applyToHelper(AFn.java:159)
        at clojure.lang.Var.applyTo(Var.java:518)
        at clojure.main.main(main.java:37)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method
)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAc
cessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Delegating
MethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:92)
        at clojure.lang.Reflector.invokeStaticMethod(Reflector.java:225)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method
)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAc
cessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Delegating
MethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:92)
        at clojure.lang.Reflector.invokeStaticMethod(Reflector.java:225)
        at user$eval3.invoke(283b967690b743aa3c81baf2afdf34941270d357d78e11bc4f8e9c68e1b
9e8f7-init.clj:1)
        at clojure.lang.Compiler.eval(Compiler.java:6465)
        at clojure.lang.Compiler.eval(Compiler.java:6455)
        at clojure.lang.Compiler.load(Compiler.java:6902)
        at clojure.lang.Compiler.loadFile(Compiler.java:6863)
        at clojure.main$load_script.invoke(main.clj:282)
        at clojure.main$init_opt.invoke(main.clj:287)
        at clojure.main$initialize.invoke(main.clj:315)
        at clojure.main$null_opt.invoke(main.clj:348)
        at clojure.main$main.doInvoke(main.clj:426)
        at clojure.lang.RestFn.invoke(RestFn.java:421)
        at clojure.lang.Var.invoke(Var.java:405)
        at clojure.lang.AFn.applyToHelper(AFn.java:163)
        at clojure.lang.Var.applyTo(Var.java:518)
        at clojure.main.main(main.java:37)
nil

noisesmith20:06:35

replacing * with *' fixed it

noisesmith20:06:23

unlike , ' auto-promotes - I'm not sure why expt was big enough to overflow though

Xarlyle020:06:38

Huh. Interesting. Was it the clojure version that made the difference as you predicted?

noisesmith20:06:40

oh I bet this is about the chunking behavior of range

noisesmith20:06:17

right, I replicated by using an older clojure, as I recall range used to be more aggressive about chunking, and chunking makes things less lazy

Xarlyle020:06:47

Interesting. I'm truly a beginner but I'm glad my assessment of it being related to laziness wasn't far off. Thanks a lot

noisesmith20:06:13

by adding (println "expt" x n) to expt I figured out that it was chunking

noisesmith20:06:47

expt 10 0
expt 10 1
expt 10 2
expt 10 3
expt 10 4
expt 10 5
expt 10 6
expt 10 7
expt 10 8
expt 10 9
expt 10 10
expt 10 11
expt 10 12
expt 10 13
expt 10 14
expt 10 15
expt 10 16
expt 10 17
expt 10 18
expt 10 19
expt 10 20
expt 10 21
expt 10 22
expt 10 23
expt 10 24
expt 10 25
expt 10 26
expt 10 27
expt 10 28
expt 10 29
expt 10 30
expt 10 31

Xarlyle020:06:55

Good to know

noisesmith20:06:05

so yeah, it was "chunking" - 32 was the magic number for chunked seqs

noisesmith20:06:47

1.10 stops at expt 10 7

noisesmith20:06:13

you can fix your code directly by using *' - but you can also improve it (and make it do less CPU work calculating exponents) by using iterate or reductions instead of map (since each number in the sequence can use the previous total in iterate or reduce, but in map they need to recalculate from the beginning)

Xarlyle020:06:18

that's true. I always try to maximize some metric during each problem (readability, simplicity, etc). In this case, time efficiency was what I was going for because of the intensity of exponents

noisesmith20:06:51

another approach is to always modulo by the base and quotent until 0

noisesmith20:06:01

then you dont' even need the exponentiation

noisesmith20:06:21

the repeated divides are also expensive of course

JoshK22:06:28

Anybody able to point me towards why my lein repl will not function? I am able to start the repl with cider. I am on windows. It just hangs here.

andy.fingerhut23:06:42

You are running a shell inside of an Emacs buffer, and in that shell buffer starting lein repl ? And all of this on Windows?

andy.fingerhut23:06:17

I would wonder whether lein repl works well on any OS when started from within an Emacs shell buffer.

JoshK23:06:11

If I use powershell everything seems to work fine. How do I have the repl in an emacs buffer instead?

noisesmith23:06:39

monroe is meant to be used this way iirc

JoshK23:06:20

Thank you

andy.fingerhut23:06:27

Works fine for at least eval'ing (+ 1 5) on Linux and macOS, so I take back my last comment. I just normally never run lein repl that way.