This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-18
Channels
- # announcements (19)
- # babashka (30)
- # beginners (51)
- # biff (12)
- # calva (20)
- # cider (27)
- # clara (20)
- # clj-kondo (19)
- # clojure (128)
- # clojure-canada (1)
- # clojure-dev (5)
- # clojure-europe (29)
- # clojure-nl (1)
- # clojure-norway (48)
- # clojure-uk (5)
- # clojurescript (6)
- # clr (37)
- # core-async (17)
- # cursive (2)
- # data-oriented-programming (2)
- # datahike (1)
- # datomic (5)
- # emacs (22)
- # exercism (1)
- # funcool (17)
- # humbleui (15)
- # jobs (1)
- # malli (44)
- # off-topic (11)
- # podcasts-discuss (1)
- # pomegranate (1)
- # react (1)
- # remote-jobs (1)
- # shadow-cljs (25)
- # tools-build (12)
- # tools-deps (70)
- # xtdb (24)
I have a https://docs.oracle.com/javase/8/docs/api/java/nio/file/DirectoryStream.html, but I am not sure how to work with this java Iterable. I'd like to reduce
over it and produce a sequence of objects read from the files returned by the iterator. How can I use this with reduce
?
If you call the iterator method you should get an iterator and reduce may work on that out of the box these days
Did you try reduce directly? That class has Iterable as a parent, which are natively reducible
Hi, how to enable namespace form auto generation when creating a new file? For vscode/calva I found this: https://calva.io/namespace-form-auto-creation/ but it does not work out of the box on my machine, nor can I find a setting where to enable that. Adding "calva.newFile.createNamespaceForm": true
did not work either.
Should work out of the box in Calva. Are you creating files with .clj, .clcs, .cljc extension?
I think it's LSP under the hood that generates the new ns form so maybe your LSP setup isn't working right for your project. I'd suggest asking in #CBE668G4R with details about your project setup...
A way to check if it is the project configuration or something else, is to try it with a minimal project. For Clojure CLI that would be a folder with.`./deps.edn` containing an empty map {}
. Then open this folder in VS Code. Then create a file ./src/hello/core.clj
it should get a namespace form (ns hello.core)
.
(If you create the deps.edn file in VS Code clojure.lsp will complain loudly. Just add the empty map and reload the VS Code window, Developer: Reload Window.)
Thanks for the tips! Looks like it’s a workspace issue, ns creation works as expected on another project.
You are welcome! The clojure-lsp status item pops up a menu with three options that could prove useful. • Show server info. A map with clojure-lsp info about the project and the lsp server status. • Open the clojure-lsp server log. You might find messages in there that can help pinpoint what's wrong. • Open trace level settings. The communication between Calva's clojure-lsp client and the server can be traced in the Output channel Clojure Language Client. This is disabled by default. Mostly useful for attaching to questions and asks for help. You'll find people who knows how to read those logs in the #CPABC1H61 channel.
How do I import an external library into the REPL? I want to do this:
(ns user (:require [feedparser-clj.core] [clojure.string :as string]))
but of course I don't have that library installed yet. I don't have a project set up yet - just looking to play around in the REPL first.
I tried this:
$ clj -X:deps find-versions :lib feedparser-clj.core
Downloading: org/clojure/tools.deps.cli/0.9.10/tools.deps.cli-0.9.10.pom from central
Downloading: org/clojure/tools.deps/0.16.1260/tools.deps-0.16.1260.pom from central
Downloading: org/clojure/tools.deps.cli/0.9.10/tools.deps.cli-0.9.10.jar from central
Downloading: org/clojure/tools.deps/0.16.1260/tools.deps-0.16.1260.jar from central
Execution error (NullPointerException) at java.util.regex.Matcher/getTextLength (Matcher.java:1769).
Cannot invoke "java.lang.CharSequence.length()" because "this.text" is null
Full report at:
/var/folders/rp/_1s4ggdd65sf_y4y5nzp6w2s2s874j/T/clojure-7897925417238007337.edn
that looks like a Clojure namespace, not a library name (groupId/artifactId)
I assume you're trying to use https://github.com/scsibug/feedparser-clj ?
% clj -X:deps find-versions :lib org.clojars.gnzh/feedparser-clj
Downloading: org/clojars/gnzh/feedparser-clj/maven-metadata.xml from clojars
{:mvn/version "0.6.0"}
{:mvn/version "0.6.1"}
% clj -Sdeps '{:deps {org.clojars.gnzh/feedparser-clj {:mvn/version "0.6.1"}}}'
Downloading: org/clojars/gnzh/feedparser-clj/0.6.1/feedparser-clj-0.6.1.pom from clojars
Downloading: net/java/dev/rome/rome/1.0.0/rome-1.0.0.pom from central
Downloading: net/java/dev/rome/rome/1.0.0/rome-1.0.0.jar from central
Downloading: org/clojars/gnzh/feedparser-clj/0.6.1/feedparser-clj-0.6.1.jar from clojars
Clojure 1.11.1
user=> (ns user (:require [feedparser-clj.core] [clojure.string :as string]))
nil
most libraries are a little more forthcoming with their lib name (here org.clojars.gnzh/feedparser-clj
) - I found it in the project.clj in the github repo, but really should be in the readme
Thanks! Very helpful. I really need to better understand the various CLI switches and when to use them
Clojure Day 3 for me
What did I do wrong here? Should ns
have returned nil
?
❯ clj -X:deps find-versions :lib org.clojars.gnzh/feedparser-clj
Downloading: org/clojars/gnzh/feedparser-clj/maven-metadata.xml from clojars
{:mvn/version "0.6.0"}
{:mvn/version "0.6.1"}
❯ clj -Sdeps '{:deps {org.clojars.gnzh/feedparser-clj {:mvn/version "0.6.1"}}}'
Downloading: org/clojars/gnzh/feedparser-clj/0.6.1/feedparser-clj-0.6.1.pom from clojars
Downloading: net/java/dev/rome/rome/1.0.0/rome-1.0.0.pom from central
Downloading: jdom/jdom/1.0/jdom-1.0.pom from central
Downloading: jdom/jdom/1.0/jdom-1.0.jar from central
Downloading: net/java/dev/rome/rome/1.0.0/rome-1.0.0.jar from central
Downloading: org/clojars/gnzh/feedparser-clj/0.6.1/feedparser-clj-0.6.1.jar from clojars
Clojure 1.11.1
user=> (ns user (:require [feedparser-clj.core] [clojure.string :as string]))
nil
user=> (def f (parse-feed " "))
Syntax error compiling at (REPL:1:8).
Unable to resolve symbol: parse-feed in this context
user=>
> Should ns
have returned nil
?
yes
Ok cool. Just not sure what that REPL:1:8 error is
require causes the namespace to be loaded and all of it's symbols are then available as fully qualified symbols feedparse-clj.core/parse-feed
got it
(ns user (:require [feedparser-clj.core :as fp] [clojure.string :as string]))
(def f (fp/parse-feed " "))
that worked
if you want to use it as a shorter name you can either: 1. Alias the namespace 2. "Refer" the symbol so that it can be used unqualified in your current namespace
i did the alias - not sure what refer is
oh, right
so because it's aliased, you can use the aliased form like you did
or you could:
(ns user (:require [feedparser-clj.core :refer [parse-feed]] [clojure.string :as string]))
(def f (parse-feed " "))
generally, most of the time, it's better to alias
ah i see - yes i can see where that can get confusing
it's useful for cases where you have tightly coupled namespaces, or namespaces that provide things that look like "syntax"
ok another dumb newbie question:
(ns main
(:gen-class)
(:require (feedparser-clj.core :as fp)))
(defn parse-feed []
(def f (fp/parse-feed " "))
)
(parse-feed)
Execution error (IllegalArgumentException) at main/eval138$loading (main.clj:1).
Don't know how to create ISeq from: clojure.lang.Keyword
i suspect i'm doing ns
wrong
I believe you need square brackets instead of parentheses around [feedparser-clj.core :as fp]
I absolutely hate IntelliJ for this. It literally won't let me type )
or ]
.
That might be IntelliJ with some Clojure editing mode/package that does something called paredit? Not sure, as I haven't used paredit myself.
I'm having better luck with VS Code + Calva
right you are
its working nicely now:
(ns main
(:gen-class)
(:require [feedparser-clj.core :as fp]))
(defn parse-feed []
(def f (fp/parse-feed " "))
(println f)
)
(parse-feed)