Questions tagged [clojure]
Clojure is a modern Lisp dialect for the Java Virtual Machine (with versions for the CLR and JavaScript). More than merely an implementation of Lisp in Java, Clojure provides access to Java's classes and ecosystem.
17,264
questions
1
vote
1
answer
23
views
Cache just doesn't seem to work in clojure, what is the way to use it?
I'm working on a simple project that shows some data that I'd like to see everyday. This will go on to my raspberry-pi. I'm using a free api that has a limit on requests so I thought I'd cache the ...
0
votes
1
answer
23
views
Adding unique key to li tag in Clojure and Hiccup using a word and index as key
I have a quick question. I'm working on a Clojure project. I want to add unique key to each li tag, like this:
(defn test [text]
[:li {:key :index} text])
How I can set keys like "hi+index&...
2
votes
2
answers
42
views
Why can I change immutable variables in Clojure?
I come from the Javascript world where const is used to declare immutable variables.
The definition of a immutable variable is explained in the same way in Clojure.
However, this is allowed:
(def ...
1
vote
1
answer
24
views
java.lang.Class cannot be cast to clojure.lang.IFn when date capturing and string formatting
I'm not really seeing where I'm going wrong here, especially since I hit upon a minor variation at one point that allowed this, but couldn't explain why it worked. Please also tell me, in a more ...
0
votes
1
answer
57
views
How to make a Java object of generic type, in Clojure?
Clojure empty changes types of Java collections.
For example a JavaParser MethodCallExpr object mce,
(type (.getArguments mce))
;; => com.github.javaparser.ast.NodeList
(type (emtpy (.getArguments ...
1
vote
1
answer
19
views
how to turn off debug transaction logging in datahike?
on every transaction datahike logs whole transaction
2022-05-24T15:25:00.999Z BB-8 DEBUG [datahike.connector:142] - Using config {:keep-history? true, :index :datahike.index/hitchhiker-tree, :store {...
0
votes
3
answers
51
views
I can return an unevaluated list as a vector using the quoted form with 'vec' in Clojure, how can I then make use of the function reference?
This was the product of trial and error in the 4clojure REPL, and this may be a peculiarity of that in particular,
Intended behaviour:
(vec (repeat 10 0))
=> [0 0 0 0 0 0 0 0 0 0]
Using the quoted ...
0
votes
1
answer
61
views
With IntelliJ/Cursive, why does clojure.test.is consider that empty-string equals any string?
With Intellij and Cursive's "run tests" feature (green Run arrow on a test or a namespace), a simple unit test in Clojure passes when it finds that "X" equals "". I ...
0
votes
0
answers
32
views
Extract both certificates and response payload from URL with Clojure
I'm trying to extract both the certificate from an URL and its payload response in a single request.
My code right now looks like this:
(s/defn get-server-leaf-certificate
[url :- s/Str]
(let [...
1
vote
0
answers
34
views
Error: "Not found" Clojure, compojure.route
I have an update article route in a blog application.
It should submit a POST request with the updated post params then redirect to the newly updated post itself.
Instead it redirects to a "Not ...
1
vote
1
answer
46
views
Clojure sending data with nested vector to function and use the items
First, I'm sorry if my question is something simple or not clear. I'm almost new to Clojure and I need help.
I want to create a function to generate some HTML link for a menu. This is what I have now ...
-3
votes
0
answers
58
views
Clojure(script) Tech Stack for Web Development [closed]
Anyone know of any good tech stacks specifically, or at least friendly to, Clojure(script)?
I'm having a hard time finding something that would be suitable to the task. Other languages have default ...
0
votes
2
answers
59
views
Error "No such namespace: jdbc" when requiring next.jdbc in Clojure
I'm running into require and or next.jdbc errors when I attempt
to create a postgres database:
Unhandled java.io.FileNotFoundException
Could not locate next/jdbc__init.class, next/jdbc.clj or next/...
1
vote
1
answer
57
views
File locking in Clojure
I'm using Java FileLock to lock files in Clojure (on macOS). This is my code to acquire a lock:
(defn lock-file
[file-path]
(try
(let [file (io/file file-path)
channel (.getChannel (...
1
vote
1
answer
30
views
ClojureDart: Execution error at cljd.compiler/load-libs-info (compiler.cljc:126). EOF while reading
While translating a flutter cookbook into ClojureDart, I encoutered this error.
I initialized the project that way:
$ mkdir -p src/samples && touch src/samples/tabs.cljd
$ clj -M -m cljd.build ...
1
vote
1
answer
20
views
ClojureDart: Error while host-compiling (ns samples.tables (:require ["package:flutter/material.dart" :as m] [cljd.flutter.alpha as f]))
Here is the trace:
Something horrible happened! :scream: Error while host-compiling (ns samples.tables "Faithful port of https://docs.flutter.dev/cookbook/design/tabs" (:require ["...
0
votes
4
answers
72
views
Why does the `type` function in Clojure return results associated to Java, to Clojure itself, and to no language?
I am using Clojure, Emacs, and Cider.
In the Cider REPL, the type function returns the following:
user> (type true)
java.lang.Boolean
user> (type '(1 2))
clojure.lang.PersistentList
user> (...
0
votes
2
answers
54
views
What is the benefit of having a Clojure project before starting the REPL? Why Cider keeps asking and nudging the user about it?
I am using Emacs and every time I start a Clojure REPL with cider-jack-in
, the minibuffer echoes the following:
Are you sure you want to run `cider-jack-in' without a Clojure project? (y or n)
I ...
1
vote
1
answer
70
views
Dijkstra's full algorithm using BFS and dictionary bug
Using dictionaries, graphs, and lists, I'm attempting to implement the Dijkstra algorithm with BFS in Clojure. The issue is that I can't get it to work correctly; it won't work when I ask it to return ...
0
votes
2
answers
49
views
Don't know how to create ISeq from: Java.lang.Long
Doing some practice on recursion and map implementation to knock some rust off Clojure. I'm using lists only here so how am I trying to mix seq and non-seqable stuff?
(defn mapset
([operator operand]...
1
vote
2
answers
52
views
clojure: how can I merge these two maps?
I have one map that looks like
{:a {:b {:c {:d [[1 2 3]]}
:e "Hello"}}}
and another map that looks like {:a {:b {:c {:d [[4 5 6]]}}}}. How can I merge these two maps so that the ...
1
vote
3
answers
72
views
What is ACTUALLY happening with parenthesis '()' in Clojure?
I'm looking for the technical answer answer here. How is Clojure interpreting these symbols? My current working understanding is that the opening paren '(' is a kind of call that calls the succeeding ...
3
votes
3
answers
73
views
Replacing characters in a string, with a set of characters inside of a map in Clojure
I have a function that takes in a string s and a map of characters charmap. If any characters in the string s are inside of charmap, replace the character with the value of the map.
Note, the keys in ...
0
votes
1
answer
47
views
I'm trying to understand the syntax of this cartesian-product function in Clojure
Here's some code for a cartesian product, it can be two lists, two vectors, or any number of combinations of the two. I'd really appreciate help with the second, fourth, and final lines, explaining ...
2
votes
1
answer
79
views
In Clojure, passing number with leading 0s to str causes strange behavior. What feature is this?
So, I accidentally figured this out while playing around with some strings.
(str 111) => "111"
(str 0111) => "73"
What is this?
1
vote
2
answers
86
views
Clojure - compiling project with Java classes that are potentially not available
I am wrapping a java library in Clojure. Depending on the java library version, some classes exist or not, so my library can fail to even compile if it can't find the java classes. My idea was to use ...
2
votes
2
answers
100
views
Clojure result returned is always function rather then result
So I'm having trouble in that every time I evaluate a Clojure function, or type in in a REPL and call it, I'm not getting the result but something like #function[clojure.core/map/fn--5880].
What's ...
1
vote
3
answers
97
views
Can I use `recur` in this implementation of function composition in Clojure?
Consider this simple-minded recursive implementation of comp in Clojure:
(defn my-comp
([f]
(fn [& args]
(apply f args)))
([f & funcs]
(fn [& args]
(f (apply (apply my-...
1
vote
1
answer
45
views
How to load this Clojure project in my cider REPL? Why I am receiving the message "The clojure executable isn’t on your ‘exec-path’" (NixOS)?
Recently, I started learning Clojure. I have been using Emacs, and cider (REPL). Also, I have NixOS as OS.
I have been able to successfully program in Clojure using this environment. Usually, I create ...
1
vote
3
answers
106
views
Convert pseudo-code with nested for-loops to Clojure
I want to implement this psuedo code in Clojure:
function(n)
B[0] <-- 1
for m <-- 1 to n do ...
1
vote
0
answers
51
views
Clojure: unit-tests defined with with-test are not actually run
Example adapted from the standard documentation for with-test:
(ns my-test
(:require [clojure.test :refer :all]))
(with-test
(defn my-function [x y]
;; (assert false)
(+ x y))
(is (= 4 (...
0
votes
1
answer
45
views
clojure.core.match on nested map
in clojure.core.match , this example works well in nested map
(match [{:a {:b :c}}]
[{:a {:b nested-arg}}] nested-arg)
but when change the key to a vector it will raise error.
(m/match x
{:a {[:b ...
0
votes
0
answers
40
views
Redefine ENV variable inside a EDN file using aero
I'm trying to redefine a value of an env variable inside an EDN file in order to write some tests.
Basically, I have an EDN file (simplified here) like this:
{:foo #include #or [#env SOME_VAR "...
2
votes
0
answers
62
views
apache-commons-matrix for clojure not playing well with core.matrix?
I'm trying to use https://github.com/adereth/apache-commons-matrix to
access the functionality of Apache Commons Math, via the Maven repo
https://mvnrepository.com/artifact/org.apache.commons/commons-...
0
votes
2
answers
74
views
Wrap HTML tags around pretty-printed Clojure forms
Clojure's pretty printer (clojure.pprint) takes unformatted code like this:
(defn fib ([n] (fib n 1 0)) ([n a b] (if (= n 0) a (fib (dec n) (+ a b) a))))
And makes it nice, like this.
(defn fib
([n]...
0
votes
3
answers
83
views
clojure returning hello world and nothing in the output
I just started learning Clojure and I have my own Clojure script but it's not returning the output that I am hoping for (Hello World). Here is my code:
(ns com.playground.core
(:gen-class))
(defn -...
0
votes
2
answers
74
views
Unable to resolve symbol: Example in this context clojure 1.10
I am a beginner with Clojure and I received this error while trying to write code in Clojure:
; Syntax error compiling at (src/com/playground/core.clj:17:1).
; Unable to resolve symbol: Example in ...
0
votes
3
answers
73
views
Why the for function is not executed [duplicate]
I am a beginner in clojure and have a puzzled problem:
(do (println "ok") (for [x [1 2 3]] (println x)))
output:
ok
1
2
3
I can understand this,but
(do (for [x [1 2 3]] (println x)) (...
5
votes
2
answers
156
views
Is it possible to force Clojure into using primitive types instead of their boxed versions?
I have a following sample of code:
(type (apply / [5.0 0]))
It throws an unexpected error - "Division By Zero" (expected behavior: return Inf)
Probably, it happens due to auto-boxing - can ...
1
vote
2
answers
83
views
Weird words replacement by using regexp in clojure
I would like to replace all demo words in "demo demo demo demo demo1 Demo" by using the following codes, but the result seems a little bit weird.
(string/replace
"demo demo demo demo ...
1
vote
1
answer
86
views
How to import local Java class at Clojure REPL?
There are existing answers to similar questions, but they tend to use Maven, which is not an option for my project. Also, I have not found any which give concrete examples of the syntax you use to ...
1
vote
2
answers
81
views
How to setup clojure.main?
In reference to the thread here : Clojurescript: Error: Could not find or load main class clojure.main
Where (in which directory) do we need to keep the clojure.jar? Should it be in the lein folder or ...
1
vote
1
answer
83
views
How to abstract a list in order to manipulate it in other functions in Clojure?
I'm very new to functional languages and I'm attempting to implement a simple append function in Clojure. My code:
(defn append
[lizt1 lizt2]
(cond
(empty? lizt1) lizt2
:else (def sq (cons ...
1
vote
1
answer
82
views
shadow-cljs watch app error on luminus page
I am using luminus to build a webpage. I want to use clojure script so I created a project with
lein new luminus test +cljs
When starting the webpage I get the following message:
If you're seeing ...
0
votes
1
answer
60
views
How to use re-matches with case or core.match
I am trying to implement pattern-matching in Clojure. My preference is to use core.match to match on a given regex pattern. I tried this:
(defn markdown->html [markdown-line]
(match [markdown-...
0
votes
2
answers
63
views
fn and let inside clojure macro
I'm running into some limitations of Clojure macros. I wonder how to optimize the following code?
(defmacro ssplit-7-inefficient [x]
(let [t 7]
;; Duplicated computation here!...
1
vote
2
answers
76
views
Creating a method for a Plinko game
I am trying to create a Plinko game by having a method with three parameters called num, prevNum (which is our previous random number) and score (which is kept track of on a certain condition).
The ...
1
vote
1
answer
86
views
How do I type-hint a Vector of Strings in Clojure?
My function returns a sequence, for example Vector of Strings.
Here is a trivial example (which in practice would be derived from type inference, but which illustrates the point):
(defn ^...
2
votes
3
answers
97
views
working with non-namespaced symbols in clojure
Here's a working minimal example showing how Clojure can handle non-namespaced symbols:
(defmacro simple-macro [s]
(name `~s))
(str "And the answer is "
(simple-macro v1))
Now I'd ...
1
vote
1
answer
68
views
clojure/clojurescript change just one key in nested map
I have this map:
{:a {:a {:a 1 :b 2}}}
And I want to turn it into this one:
{:a {:a {:x 1 :b 2}}}
I tried this, but -of course- got all :a replaced:
(clojure.walk/postwalk-replace {:a :c} {:a {:a {:...