This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

## 2022-09-22

## Channels

- # 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:

```
(defmacro alet [a body]
(let [exp (macroexpand `(foo ~a)]
`(let ~exp ~body)))
```

But then I get an error saying that `macroexpand`

requires specifically `'`

, and not `.macroexpand doesn't require any kind of quoting

```
user=> (macroexpand (list (symbol "+") 1 2))
(+ 1 2)
user=>
```

unless you are using clojurescript, where macroexpand is a macro that pretends it is a functionIt 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?

```
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)
```

i’m not sure i’m following the lazy bit. Just compute on demand is one version of lazy> Why do you want to do it lazily? To work with realy big numbers :-)

Thnx!

if you don’t want to repeatedly str the number my `get-char`

closes over the string representationo

Standart function nth are not lazy.

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.

Guys I'm newbie, so don't be scary :-)

> 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
Aren't `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).

Thnx!

isn't the `str`

version linear time because of `(str number)`

?

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

(defn digit [nth number] (SomeCode)) (digit 3 717934) -> 9