Fork me on GitHub
#beginners
<
2021-11-26
>
quan xing03:11:42

HI, I saw the video and type command in the cmd after it's not create project and show error @seancorfield

randomm char05:11:01

you need to create deps.edn file first

seancorfield05:11:00

@U025AG2H55F That sounds like you don't have the :new alias correct in your user deps.edn file? See https://github.com/seancorfield/clj-new#installation-via-depsedn

seancorfield05:11:27

Also, make sure you are using a recent version of the clojure CLI itself, so check clojure -version

seancorfield05:11:56

@UE0T2PKJA You do not need a project deps.edn file for clj-new to work.

quan xing05:11:58

thank you @seancorfield I'll try it

randomm char05:11:39

well with out the deps.edn file it didn't work for me which I found here https://github.com/practicalli/clojure-deps-edn/blob/live/deps.edn

seancorfield05:11:38

@UE0T2PKJA The user deps.edn is automatically created by the Clojure CLI when you first run it. You can add "global" aliases there. You do not need a project deps.edn file to use clj-new once you have :new in your user deps.edn file.

seancorfield06:11:17

There are three deps.edn files that can be in play at any time: the root deps.edn file (which is baked into tools.deps.alpha and, hence, into the Clojure CLI), the user deps.edn file, and the project deps.edn if present. The -Srepro option to the clojure CLI will omit the user deps.edn and just use the root and, if present, the project one.

seancorfield06:11:51

(the user deps.edn file will either be in ~/.clojure/ or ~/.config/clojure/ on XDG systems -- on Windows the location of the ~ folder is not always entirely obvious but on Mac/Linux it's your home directory)

seancorfield06:11:49

If you run clojure -Sdescribe it will tell you where it is looking for the three deps.edn files. For example:

(! 512)-> ls -l deps.edn
ls: deps.edn: No such file or directory
(! 513)-> clojure -Sdescribe
{:version "1.10.3.1029"
 :config-files ["/usr/local/Cellar/[email protected]/1.10.3.1029/deps.edn" "/Users/sean/.clojure/deps.edn" ]
 :config-user "/Users/sean/.clojure/deps.edn"
 :config-project "deps.edn"
 :install-dir "/usr/local/Cellar/[email protected]/1.10.3.1029"
 :config-dir "/Users/sean/.clojure"
 :cache-dir "/Users/sean/.clojure/.cpcache"
 :force false
 :repro false
 :main-aliases ""
 :repl-aliases ""}
Since there is no deps.edn file in the directory I'm in, there is no project file -- just the root and the user files.

seancorfield06:11:27

You can see that -Srepro ignores the user file:

(! 514)-> clojure -Srepro -Sdescribe
{:version "1.10.3.1029"
 :config-files ["/usr/local/Cellar/[email protected]/1.10.3.1029/deps.edn" ]
...

quan xing06:11:28

I add this alias into my deps.edn

:aliases
    {:new {:extra-deps {com.github.seancorfield/clj-new {:mvn/version "1.2.362"}}
        :exec-fn clj-new/create
        :exec-args {:template "app"}}}

seancorfield06:11:28

-X means "execute function", -M means "run clojure.main" (and anything that follows will be passed as arguments to clojure.main/-main)

randomm char06:11:51

for me 2 of the deps.edn are completely commented out and one only has { :paths ["src"] :deps { org.clojure/clojure {:mvn/version "1.10.3"} } :aliases { :deps {:replace-deps {org.clojure/tools.deps.alpha {:mvn/version "0.12.1003"} org.slf4j/slf4j-nop {:mvn/version "1.7.25"}} :ns-default clojure.tools.cli.api :ns-aliases {help }} :test {:extra-paths ["test"]} } :mvn/repos { "central" {:url ""} "clojars" {:url ""} } }

seancorfield06:11:23

That's the root deps.edn, yes.

seancorfield06:11:46

And the user deps.edn is just a minimal example laid down by the first run of the clojure script.

seancorfield06:11:08

;; The deps.edn file describes the information needed to build a classpath.
;;
;; When using the `clojure` or `clj` script, there are several deps.edn files
;; that are combined:
;; - install-level
;; - user level (this file)
;; - project level (current directory when invoked)
;;
;; For all attributes other than :paths, these config files are merged left to right.
;; Only the last :paths is kept and others are dropped.

{
  ;; Paths
  ;;   Directories in the current project to include in the classpath

  ;; :paths ["src"]

  ;; External dependencies
 
  ;; :deps {
  ;;   org.clojure/clojure {:mvn/version "1.10.3"}
  ;; }

  ;; Aliases
	;;   resolve-deps aliases (-R) affect dependency resolution, options:
	;;     :extra-deps - specifies extra deps to add to :deps
	;;     :override-deps - specifies a coordinate to use instead of that in :deps
	;;     :default-deps - specifies a coordinate to use for a lib if one isn't found
	;;   make-classpath aliases (-C) affect the classpath generation, options:
	;;     :extra-paths - vector of additional paths to add to the classpath
	;;     :classpath-overrides - map of lib to path that overrides the result of resolving deps

  ;; :aliases {
  ;;   :deps {:extra-deps {org.clojure/tools.deps.alpha {:mvn/version "0.12.1071"}}}
  ;;   :test {:extra-paths ["test"]}
  ;; }

  ;; Provider attributes

  ;; :mvn/repos {
  ;;   "central" {:url ""}
  ;;   "clojars" {:url ""}
  ;; }
}

seancorfield06:11:28

The expectation is that you edit the user deps.edn to add aliases that you want for "global" usage. My user deps.edn is here: https://github.com/seancorfield/dot-clojure/blob/develop/deps.edn and Quan Xing linked to the Practicalli user deps.edn further up @UE0T2PKJA

seancorfield06:11:56

@U025AG2H55F Did that work with -X:new ?

seancorfield06:11:48

Since Clojure CLI 1.10.3.933 you can also install "tools" globally -- using the clojure -Ttools install command -- and that creates EDN file inside the tools subfolder when your user deps.edn lives. My installed "tools" can be see here: https://github.com/seancorfield/dot-clojure/tree/develop/tools

seancorfield06:11:25

(! 1070)-> clojure -Ttools list
TOOL     LIB                              TYPE  VERSION
antq     com.github.liquidz/antq          :git  1.3.0
clj-new  com.github.seancorfield/clj-new  :git  v1.2.362
new      io.github.seancorfield/deps-new  :git  v0.4.2
nvd      io.github.rm-hull/nvd-clojure    :git  40b2610
poly     io.github.polyfy/polylith        :git  b32f375
tools    io.github.clojure/tools.tools    :git  v0.2.2

quan xing06:11:26

Yes, It's ok. thank you @seancorfield. but why I use clojure -Ttools show error message:

PS D:\e\clojure> clojure -Ttools install com.github.seancorfield/clj-new '{:git/tag "v1.2.362"}' :as clj-new
Execution error (ExceptionInfo) at clojure.tools.deps.alpha.extensions.git/coord-err (git.clj:45).
Library com.github.seancorfield/clj-new has invalid tag: v1.2.362

seancorfield06:11:05

Windows Powershell requires different quoting. I don't remember the details (I use WSL2 with Windows so I don't have to deal with that!).

seancorfield06:11:21

I think it requires either double or triple " instead of just the single one?

seancorfield06:11:21

(very few Clojure users work with Powershell so almost none of the READMEs out there will give you the correct instructions for it -- they all assume macOS/Linux)

quan xing06:11:50

ok I got it. thanks again. sorry I'm taking too much your time :)

seancorfield06:11:58

NP. Happy to help.

seancorfield06:11:16

Hope all of the above information about the various deps.edn is useful @U025AG2H55F @UE0T2PKJA?

randomm char06:11:20

Thanks for taking the time to explain it :)

quan xing12:11:34

I do the next step

PS D:\e\clojure\demo> clojure -M:rebel:reveal:add-libs:test:dev
WARNING: Specified aliases are undeclared and are not being used: [:rebel :reveal :add-libs :dev]
Error building classpath. Unable to fetch C:\Users\xingquan\.gitlibs\_repos\\cognitect-labs\test-runner
fatal: unable to access '': Failed to connect to  port 443: Timed out
error: Could not fetch origin
so Do I need download your deps.edn replace with mine?

seancorfield15:11:58

In order to use any aliases they must be declared in your user deps.edn file. Mine changes all the time (as the README says) so treating my videos as tutorials isn't going to work - you feed to understand the principles behind what I'm showing rather than just trying to follow the details.

seancorfield15:11:07

I've renamed :dev to :dev/repl for example to avoid conflicts with Polylith (which has :dev as a project-level alias).

seancorfield15:11:00

As for the git failure, do you have git installed and on your path? The Clojure CLI (via tools.deps.alpha) assumes it can resolve git deps by shelling out to git.

seancorfield15:11:47

I think you need to follow some tutorial material first to understand the basics. Make sure you understand the basics of the CLI, make sure git deps work on your system.

randomm char22:11:41

You wouldn't happen to know of any good tutorial ?

seancorfield23:11:46

Very hard for me to know what's good for a beginner, at this point, I'm afraid. I'd start here: https://clojure.org/guides/deps_and_cli

seancorfield23:11:23

Also look at the Practicalli web site -- I think that has a bunch of tutorial stuff, including some focusing on deps.edn and the CLI...?

Skiamakhos11:11:05

Hey, does anyone know about this, I wonder: I'm using Emacs and cider-repl to do a course on Clojure, and I notice that when the teacher types in his REPL some Java class like Math, if he types Math/ it gives him a vertical scrolly list of methods one can invoke that are available on the Java Math class. How does one set that up? I've been doing a fair bit of setup with Emacs lately so quite happy to get my hands dirty with e-Lisp.

Benjamin12:11:42

completion-at-point should work out of the box with cider. - doesn't really work in repl buffers for me but I only type in file buffers anyway. For the dropdown ui there is https://github.com/company-mode/company-mode there is also https://github.com/minad/corfu which is more minimalistic

Skiamakhos13:11:59

Ha, thanks folks - got it working. One thing I didn't realise was it needed me to hit tab where I wanted the suggestions, and as I'm using Windows I had to pop in

(setq tab-always-indent 'complete)
but aside from that, all sorted. Muchas gracias!

Muhammad Hamza Chippa12:11:20

I have this type of map how I can iterate through such type of map and print key and value? ({:2017 [["20170512 170000" 126.51 126.5 126.5 126.51 793574 105508] ["20170512 160000" 126.545 126.38 126.54 126.5 684653 143106] ["20170512 150000" 126.8 126.51 126.8 126.545 501867 47260] ["20170512 140000" 126.8 126.67 126.77 126.79 440753 36702] ["20170512 130000" 126.8 126.7 126.75 126.75 393599 43973] ["20170512 120000" 126.81 126.58 126.62 126.75 337083 69559] ["20170512 110000" 126.71 126.22 126.39 126.61 251083 110687] ["20170512 100000" 126.87 126.14 126.81 126.32 123486 113476]]} {:2018 []} {:2019 []} {:2020 [["20200512 200000" 280 280 280 280 933430 300] ["20200512 170000" 281.68 281.68 281.68 281.68 916230 103501] ["20200512 160000" 286.4525 280.73 286.25 281.7 812334 205195] ["20200512 150000" 287.32 285.97 287.315 286.43 511068 50263] ["20200512 140000" 288 286.18 287.97 287.39 436296 48815] ["20200512 130000" 288.63 287.5 287.64 288.4175 367249 28523] ["20200512 120000" 289.68 287 288.56 287.51 314195 39964] ["20200512 110000" 288.71 285.43 285.43 288.52 246569 80284] ["20200512 100000" 290 283.62 290 285.42 119933 82122] ["20200512 090000" 287.842 287.842 287.842 287.842 490 153]]} {:2021 [["20210512 170000" 400.51 397.08 400.04 399.89 2256161 527919] ["20210512 160000" 402.24 398.75 400.09 399.88 1720687 473655] ["20210512 150000" 401.19 397.87 398.28 400.085 1021086 69823] ["20210512 140000" 400.92 397.86 398.63 398.31 894937 76594] ["20210512 130000" 398.88 394.87 395.09 398.88 764491 56277] ["20210512 120000" 399.84 394.65 396.72 395.19 659927 115506] ["20210512 110000" 398.66 394.71 396.34 397.02 469826 148138] ["20210512 100000" 399.99 391.0893 395.05 396.69 236445 160811] ["20210512 090000" 400.42 300] ["20210512 080000" 395 395 395 395 425 100]]})

pyry12:11:22

To get sequences of keys or values, you can use keys and vals

pyry12:11:13

For printing key-value pairs, you can do eg. (doseq [[k v] data] (clojure.pprint/pprint [k v]))

Muhammad Hamza Chippa12:11:42

Execution error (UnsupportedOperationException) at user/eval2386 (REPL:1). nth not supported on this type: PersistentArrayMap

pyry12:11:03

Looks like your data is actually a list (or seq) instead of a map?

Fredrik12:11:33

Since it looks like a list of maps, you need another level of iteration

(doseq [m data]
  (doseq [[k v] m]
    (println k v)))

pyry12:11:17

And you can actually combine the two doseqs into one, like so:

(doseq [m data
          [k v] m]
    (clojure.pprint/pprint [k v]))

🙌 1
Fredrik12:11:07

Yes, that's much cleaner 🙂

Fredrik12:11:39

If you wonder why we got that error, it's because [[k v] data] tried to destructure a map into its first and second element, but maps don't support a notion of sequentiality, ie. you cannot ask a map for it's first element.

Fredrik12:11:16

We can of course iterate on a map, though, which we do all the time with for instance reduce, or doseq as in this case

🙌 2
Muhammad Hamza Chippa12:11:33

that worked brother than you so much

Muhammad Hamza Chippa13:11:15

is there any way to store value and keys in different variable ?

emilaasa13:11:06

Can you say more about what you're trying to do?

Muhammad Hamza Chippa14:11:15

I did that thank you so much for the help

metehan14:11:43

is there any (merge but with conflict resolution. like (merge map1 map2 #(fn "to resolve conflict"))

Fredrik14:11:03

Yes, check out merge-with

metehan14:11:38

thank you

😀 1
Fredrik14:11:09

It is precisely what you're looking for, and takes the function as first argument

😇 1
Muhammad Hamza Chippa15:11:02

I have this error how to filter the range from it i.e from 09300 to 16000 because I can't do less than or greater than comparison from strings ["165000" "160100" "160000" "155900" "155800" "155700" "155600" "155500" "155400" "155300" "155200" "155100" "155000" "154900" "154800" "154700" "154600" "154500" "154400" "154300" "154200" "154100" "154000" "153900" "153800" "153700" "153600" "153500" "153400" "153300" "153200" "153100" "153000" "152900" "152800" "152700" "152500" "152400" "152300" "152200" "152100" "151900" "151800" "151700" "151600" "151500" "151400" "151300" "151200" "151100" "151000" "150900" "150800" "150700" "150600" "150500" "150300" "150200" "150100" "150000" "145900" "145800" "145700" "145600" "145500" "145400" "145300" "145200" "145100" "145000" "144900" "144800" "144700" "144600" "144500" "144400" "144300" "144200" "144100" "144000" "143900" "143800" "143700" "143600" "143500" "143300" "143200" "143100" "142900" "142800" "142700" "142600" "142500" "142400" "142300" "142200" "142100" "142000" "141800" "141600" "141500" "141300" "141200" "141100" "141000" "140900" "140800" "140700" "140600" "140500" "140300" "140100" "140000" "135900" "135800" "135700" "135600" "135500" "135400" "135300" "135200" "135000" "134900" "134700" "134600" "134400" "134300" "134200" "134100" "134000" "133900" "133800" "133700" "133500" "133400" "133300" "133200" "133100" "133000" "132900" "132800" "132700" "132600" "132500" "132400" "132300" "132200" "132100" "132000" "131900" "131800" "131700" "131600" "131500" "131400" "131300" "131200" "131100" "131000" "130900" "130800" "130700" "130600" "130500" "130300" "130200" "130100" "130000" "125900" "125800" "125700" "125600" "125500" "125400" "125300" "125200" "125100" "125000" "124900" "124800" "124700" "124600" "124500" "124400" "124300" "124200" "124100" "124000" "123900" "123800" "123700" "123600" "123500" "123400" "123300" "123200" "123100" "123000" "122900" "122800" "122700" "122600" "122500" "122400" "122300" "122200" "122100" "122000" "121900" "121800" "121700" "121600" "121500" "121400" "121300" "121200" "121100" "121000" "120900" "120800" "120700" "120600" "120500" "120400" "120300" "120200" "120100" "120000" "115900" "115800" "115700" "115600" "115500" "115400" "115300" "115200" "115100" "115000" "114900" "114800" "114700" "114600" "114500" "114400" "114300" "114200" "114100" "114000" "113900" "113800" "113700" "113500" "113400" "113300" "113200" "113100" "113000" "112900" "112800" "112700" "112600" "112500" "112400" "112300" "112200" "112100" "112000" "111900" "111800" "111700" "111600" "111500" "111400" "111300" "111200" "111100" "111000" "110900" "110800" "110700" "110600" "110500" "110400" "110300" "110200" "110100" "110000" "105900" "105800" "105700" "105600" "105400" "105300" "105200" "105100" "105000" "104900" "104800" "104700" "104600" "104500" "104400" "104300" "104200" "104100" "104000" "103900" "103800" "103700" "103600" "103500" "103400" "103300" "103200" "103100" "103000" "102900" "102800" "102700" "102600" "102500" "102400" "102300" "102200" "102100" "102000" "101900" "101800" "101700" "101600" "101500" "101400" "101300" "101200" "101100" "101000" "100900" "100800" "100700" "100600" "100500" "100400" "100300" "100200" "100100" "100000" "095900" "095800" "095700" "095600" "095500" "095400" "095300" "095200" "095100" "095000" "094900" "094800" "094700" "094600" "094300" "094200" "094100" "093900" "093800" "093700" "093600" "093500" "093400" "093300" "093200" "093100" "093000" "092900"],

metehan15:11:01

in your filter function you can convert to int

metehan15:11:16

(filter #(> 100000 (int %)) coll)

metehan15:11:43

btw you can use high and low same time with filter (filter #(> 100000 (int %) 95000) coll)

🎯 1
sova-soars-the-sora16:11:44

How did you get those strings? Do you start w/ strings or did they turn into strings because of another function?

randomm char22:11:11

(int "1234") pop up as an error (Integer. "1234") works though?

metehan22:11:16

@UE0T2PKJA it might be related to clojure. my sample was clojurescript I don't know how it differs in clojure.

Muhammad Hamza Chippa11:11:44

I am getting the string from substring like (subs (first x) 9) which is time like 16000 (*int (subs (first x) 9))is not working on it it is saying "Expected number or character received string" ?* any alternate ?

sova-soars-the-sora02:12:12

(Integer/parseInt n)

dpsutton15:11:16

@mhamzachippa in the future you should just post a snippet of data that is representative of your data. It is not necessary to fill the channel so much

😁 1
9
Stuart17:11:50

Or stick it in a gist

West20:11:54

Not a Clojure question, but I’m trying to work with javascript. What’s the workflow like? Is there any way to get a repl or similar feedback?

seancorfield21:11:26

There is a #javascript channel but I've no idea how active it is. You might also get some insight from folks in the #clojurescript channel?

seancorfield21:11:28

I know that you can interact with JS in the browser via the devtools' console. I don't know if that's the context of your question @U01KQ9EGU79?

West21:11:12

I’m using svelte, so I’m writing javascript files to do certain tasks. I resorted to console.loging everything and seeing what comes out using the node cli.

emccue21:11:00

For what purpose are you writing javascript?

West21:11:36

// src/lib/process-org.js

// filesystem access
import fs from 'fs';

// Uniorg stuff for parsing org text
import unified from 'unified';
import parse from 'uniorg-parse';
import { extractKeywords } from 'uniorg-extract-keywords';
import html from 'uniorg-rehype';
import raw from 'rehype-raw';
import highlight from 'rehype-highlight';
import stringify from 'rehype-stringify';

const processor = unified()
    .use(parse)
    .use(extractKeywords)
    .use(html)
    // .use(raw)
    // .use(highlight)
    .use(stringify);

export function processOrg(filePath) {
    const processedfile = processor.processSync(fs.readFileSync(filePath, 'utf8'));
    // console.log(processedfile);
    return processedfile;
}
To turn org documents into html and metadata.

randomm char22:11:41

there is "Java Shell Tool" jshell should be in your java bin directory ?

West23:11:06

@UE0T2PKJA How would that help exactly? I’m not doing java, I’m doing javascript.

emccue23:11:24

you can use node -i to get yourself an interpreter. I don’t know of any nrepl type things off the top of my head though

Gerome06:11:59

The best dev experience you can get with JS in this respect is Hot Module Reload and Debugging.

Muhammad Hamza Chippa22:11:58

I am trying to make it a dynamic range (range @start-year @end-year) where start-year and end-year is an atom and can be selected from the drop-down when I am printing @start-year and @end-year in the UI it is changing but (range @start-year @end-year) is not changing at all. Any Suggestion regarding it ?

metehan22:11:43

I guess you are using reagent. If it's the case you can use (r/with-let so whenever you change atoms view will be affected.

Muhammad Hamza Chippa22:11:13

Yes I am using reagent let me see

metehan22:11:27

and atoms must be r/atom

Muhammad Hamza Chippa22:11:50

so instead of defining start-year with r/atom I am suppose to define it with r/with-let ?

metehan22:11:51

I just copied a sample from my codebase:

(defn account-picker
  [{:keys [id label values tooltip errors class]}]
  (r/with-let [state (r/atom {:show-picker false :subject {:title ""} :value ""})]

metehan22:11:29

so instead of let you use r/with-let and instead of atom you use r/atom

Muhammad Hamza Chippa22:11:08

I am using r/atom as (def start-year (r/atom "2017")) and (def end-year (r/atom "2021)) and it can be changed with drop down and it is changing as well. My problem is that (range @start-year @end-year) is static it is not changing whether @start-year or @end-year changing

metehan22:11:19

can you show me your react component

Muhammad Hamza Chippa22:11:39

(defn select [field] [:div {:class (if (nil? (:class-name @field)) style/bootstrap-input-container-class (:class-name @field)) :key (str "container-" (:id @field))} (when (:label @field) [:label {:for (:id @field) :class "control-label" :key (str "label-" (:id @field))} (:label @field)]) [:select {:key (:id @field) :class "form-control" :id (:id @field) :on-change #(select-on-change field (-> % .-target .-value) ) :value (if (:value @field) (:value @field) (:value (first (:options @field)))) :disabled (if (:disabled @field) "disabled" "")} (doall (map (partial select-option (:value @field) field) (:options @field)))] [:label {:class "message-label" :key (str "label-message-" (:id @field)) } (if (nil? (:message @field)) "" (:message @field))]])

Muhammad Hamza Chippa22:11:58

as I mentioned value of start-year and end-year is changing only range is static

metehan23:11:15

there is nothing in your code which tracks state changes. it would be better if you wrap :div with r/with-let and put your start and end years inside this let definition

Muhammad Hamza Chippa23:11:50

irrelevant question but can use material-ui library of react in clojure it will make my job easier ?

metehan23:11:06

libraries are always useful I don't know your exact use case so I wouldn't like to guide you in a wrong direction

Muhammad Hamza Chippa23:11:56

I am working in a UI which is badly badly coded by the bad coders (made back in 2015) and I am paying the price of the bad practices

Muhammad Hamza Chippa23:11:27

I am asking whether I use these using hiccups syntax ?

metehan23:11:11

you can use it with hiccup syntax and here are you can find cool ui elements https://github.com/search?q=clojurescript+ui and of course it will help a lot

Muhammad Hamza Chippa23:11:55

thanks a lot brother

🍻 1