This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # announcements (2)
- # asami (123)
- # aws (17)
- # babashka (77)
- # babashka-sci-dev (23)
- # beginners (48)
- # biff (6)
- # calva (35)
- # cider (16)
- # clj-on-windows (1)
- # clj-yaml (19)
- # clojure (36)
- # clojure-europe (78)
- # clojure-nl (5)
- # clojure-norway (8)
- # clojure-poland (3)
- # clojure-uk (16)
- # clojurescript (17)
- # cursive (6)
- # datahike (3)
- # datalevin (26)
- # duct (7)
- # emacs (41)
- # events (2)
- # fulcro (7)
- # graphql (5)
- # honeysql (13)
- # juxt (3)
- # kaocha (7)
- # lsp (5)
- # malli (12)
- # off-topic (14)
- # pathom (3)
- # portal (1)
- # rdf (9)
- # reitit (3)
- # remote-jobs (2)
- # shadow-cljs (37)
- # spacemacs (5)
- # tools-build (1)
- # tools-deps (20)
- # xtdb (2)
Is there any way to macro expand the bind vars of a
let form? Something like:
(ns test.core) (defmacro foo [a] `[~a :b]) (defmacro alet [a body] `(let (foo ~a) ~body))
I did try:
But then I get an error saying that
(defmacro alet [a body] (let [exp (macroexpand `(foo ~a)] `(let ~exp ~body)))
', and not `.
macroexpand doesn't require any kind of quoting
unless you are using clojurescript, where macroexpand is a macro that pretends it is a function
user=> (macroexpand (list (symbol "+") 1 2)) (+ 1 2) user=>
It also looks like
macroexpand is not supposed to actually be used in your code...just when experimenting at the repl.
Hello friends! 🙂 Is there idiomatic way to write lazy function which will convert n-th digit of Number to Char? (i.e. lazy evaluation of selected digit in decemical number) Thnx!
You can write your code normally and wrap it in a delay Why do you want to do it lazily?
i’m not sure i’m following the lazy bit. Just compute on demand is one version of lazy
qp=> (defn get-char [number] (let [s (str number)] (fn [n] (nth s n)))) #'nocommit.qp/get-char qp=> (let [f (get-char 9876)] (map f [0 1 2 3])) (\9 \8 \7 \6)
if you don’t want to repeatedly str the number my
get-char closes over the string representationo
the only thing i can think of is like haskell where the expression is not computed until the result is “needed”. And Clojure offers nothing like that
I'm trying to solve problems from https://projecteuler.net/ And here a lot of problems related to lazy evaluations of few last digits of some realy big number.
> the only thing i can think of is like haskell where the expression is not computed until the result is “needed”. And Clojure offers nothing like that
delay and lazy sequences like that?
nth digit from the end
(require '[clojure.math :as math]) (defn nth-digit [^long num ^long n] (mod (quot num (long (math/pow 10 n))) 10)) (nth-digit 123456 1)
For example: N equal to sum of 1 trillion of prime numbers. Find last digit of N (like ...4189 -> 9).
right, it looks like one of the goals is to get one of the least significant digits quickly
the fun question is - is there a way to get the nth digit without calculating everything?
for example, if you need the nth digit of the sum of all primes, you can always mod the result 10^(n+1)
even further, is there an analytical expression for the nth digit of the sum of k primes?
i wonder what the internal representation of bignums, bigints are. It might have a string representation in there so the
str call is just a constant field access and then
.charAt is constant as well
and it led to interesting places. everyone here is better off having thought about it, wrestled with it