Fork me on GitHub
#clojure
<
2024-01-20
>
xiongtx01:01:13

Why is this valid? What is the recur target?

(let [x 1]
  (println x)
  (recur))

Sam Ferrell01:01:05

I don't think it is valid

xiongtx01:01:00

It’s definitely valid (in that it compiles), all it does is print 1 endlessly.

hiredman01:01:23

It has to do with how the compiler, and specifically eval handles more complex expressions

hiredman01:01:20

for more complex expressions (basically anything but a simple function call) eval wraps them in a no-arg function, compiles it, then invokes the no-arg fn

hiredman01:01:25

It works, but by accident, sort of like the static field thing that @U064X3EF3 mentioned in this channel earlier

hiredman01:01:41

Part of the reason eval does the wrapping in a no-arg fn is because it gives some place for the compiler to emit the bytecode (a method on the clas for the fn), but outside of eval, in other contexts the compiler has other places to write the bytecode, so the wrapping doesn't happen and it won't work

hiredman01:01:27

Outside of the compiler there are a lot of macros that introduce 0-arg fn wrappers where that kind of thing also works, like lazy-seq

xiongtx01:01:27

Thanks, that’s helpful!

Noah Bogart02:01:55

I wonder if this is worth fixing

hiredman02:01:09

I think this case is easily fixable in a few different ways, the easiest would be a flag for fns like :once that stops it from establishing a recur point

xiongtx02:01:26

I don’t think :once stop a recur--or did you mean some other, new metadata?

hiredman02:01:31

Yeah, something new that you could tag fns with like you can tag them with once

hiredman02:01:36

I would almost say you could just add it to once, I think most usages of once fns in the compiler, or in clojure.core macros, using the recur frame introduced by the once fn is a bug, but I bet someone somewhere is depending on it

hiredman03:01:44

You could make an http://ask.clojure.org about it and who knows

borkdude09:01:34

clj-kondo will warn about this

Noah Bogart14:01:09

i wondered if something like this would work, but the core test suite fails in mysterious (to me) ways:

(defn eval
  "Evaluates the form data structure (not text!) and returns the result."
  {:added "1.0"
   :static true}
  [form] (. clojure.lang.Compiler (eval `(let [ret# (do ~form)] ret#))))

Noah Bogart14:01:36

i don't have a good enough grasp of the compiler or evaluation system to know why. the error message I tried to run down complained that a call to is in a deftest couldn't be resolved.

Noah Bogart14:01:46

full stack trace for this specific error, if you care to dive in. not the only error, i should say, just the one i tried to figure out

hiredman16:01:27

Wrapping everything in a let means you can't eval "top level" dos anymore, which means everything becomes a single compilation unit, which will break eval on stuff like (do (require '[clojure.string :as s]) (s/trim "foo")) because the require won't be compiled and executed before the call is compiled, so the compiler won't be able to resolve s/trim to anything

Noah Bogart16:01:54

oh that's interesting, thanks for the link

Carsten Behring13:01:14

I run clojure in a container in a certain scenario, and this results the link to $HOME/.clojure invalid inside the container and I get a cp: not writing through dangling symlink '/home/carsten/.clojure/deps.edn' I would expect that using -Srepro would not even "try" to copy the example-deps.edn, as it would be ignored in any case later I clearly want to tell clojure to completely ignore .clojure But it seem to try to copy an example edn to it, which would probably be ignored later. bash -x clojure -Srepro + set -e + install_dir=/usr/local/lib/clojure + version=1.11.1.1435 + print_classpath=false + describe=false + verbose=false + trace=false + force=false + repro=false + tree=false + pom=false + help=false + prep=false + jvm_opts=() + repl_aliases=() + mode=repl + '[' 1 -gt 0 ']' + case "$1" in + repro=true + shift + '[' 0 -gt 0 ']' + set +e ++ type -p java + JAVA_CMD=/opt/java/openjdk/bin/java + set -e + [[ -z /opt/java/openjdk/bin/java ]] + false + tools_cp=/usr/local/lib/clojure/libexec/clojure-tools-1.11.1.1435.jar + [[ -n '' ]] + [[ -n '' ]] + config_dir=/home/carsten/.clojure + [[ ! -d /home/carsten/.clojure ]] + [[ ! -e /home/carsten/.clojure/deps.edn ]] + cp /usr/local/lib/clojure/example-deps.edn /home/carsten/.clojure/deps.edn cp: not writing through dangling symlink '/home/carsten/.clojure/deps.edn'

Carsten Behring13:01:56

I can indeed solve it by setting CLJ_CONFIG to a valid directory: CLJ_CONFIG=/tmp /usr/local/bin/clojure -Srepro Nevertheless I think when using -Srepro it should not even try to copy the example file anywhere.

Bob B16:01:07

I think maybe that's <https://github.com/clojure/brew-install/blob/5dfbe3e8c4ee36d0e13735af56a450403734e849/src/main/resources/clojure/install/clojure#L288> - I'm speculating that perhaps the approach is "set up the config dir in an idempotent way, even if it's not going to be used". I'd imagine that there are so many options that working through every possible combination for each operation in the bash script gets unwieldy to maintain.

nonrecursive15:01:00

I’m trying to help some colleagues use clj-kondo with intellij and i’m wondering, what’s the recommended approach? I’ve run into trouble so far: • with clojure-extras, I’m seeing a lot of spurious warnings. for example, in test namespaces that refer deftest, is, etc I’m seeing warnings to define those. Even seeing a warning to define ns • with clojure-lsp, I get an error “cannot run program lein” when clojure-lsp attempts to run lein with-profile +test,+dev classpath

ericdallo15:01:22

The clojure-lsp issue is https://github.com/clojure-lsp/clojure-lsp-intellij/issues/26, running from terminal intellij will fix the problem, this is a high prior to me but I couldn't find a solution yet (only happens for Macs)

nonrecursive16:01:07

thank you! i’ll look into this more monday

borkdude16:01:42

> with clojure-extras, I’m seeing a lot of spurious warnings. try linting with clj-kondo on the command line and see what you get there

borkdude16:01:14

> I’m seeing warnings to define those what does that look like? I don't have a clear picture of what might be going wrong there

nonrecursive14:01:09

here's an example of what it looks like. had to modify it, like of course the ns name isn't ... - but the warning to define ns is there

borkdude14:01:48

> "The warning to define ns is there" Sorry, but I don't understand. What warning?

nonrecursive14:01:58

@U04V15CAJ I wouldn't worry about this too much? who knows what else I have configured that's resulting in this

nonrecursive14:01:17

but to clarify this is when using the clojure-extras plugin for intellij ce

borkdude14:01:20

I can't tell if this warning is coming from #C02UN1B0998 or Cursive itself

nonrecursive14:01:17

I don't get those warnings from clj-kondo on the command line

borkdude14:01:46

then it's likely not your configuration. is there a way to check if this is coming from #C02UN1B0998?

borkdude14:01:36

rather than Cursive or some other thing?

borkdude14:01:55

if it's 100% #C02UN1B0998 maybe try that channel

ericdallo15:01:06

if the warning doesn't show when using clojure-lsp-intellij so it's not from kondo too

👍 1
Alex16:01:42

Is it common quote like this: (tap> (list '~'fncall '~f args# '~'=> ~res)) within a syntax-quote? I want to tap into what function was called with what args and what was the result. Can't seem to find a shorter way than '~' ...

hiredman16:01:46

Not common, because it is not common to splice in literal symbols

hiredman16:01:45

So the symbol needs quoting in the output, needs splicing into the output, and needs quoting to avoid being evaluated when the macro definition is compiled, so '~'

hiredman16:01:04

You could just use keywords

Alex16:01:18

ah... that will work as well, thank you! 🙂

jaide17:01:17

Using cljs to render an svg with a few pattern elements in a browser using reagent. It renders as expected in a browser but the goal is to print it to a pdf but only the background layer shows up. Anyone run into an issue like that?

p-himik17:01:02

"Triple kill!" :D There's #C03S1L9DN and #C0620C0C8, and the issue has absolutely nothing to do with anything Clojure-related.

p-himik17:01:47

Probably some CSS issue or a browser bug.

Nundrum17:01:10

Adding some patterns to my project is on the to-do list. If I get to that soon I'll test a PDF and let you know what happens. In the meantime, maybe try to export the SVG and then open and print from Inkscape just to see what happens?

p-himik17:01:32

This page has examples of patterns: https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Patterns Printing works for me on Chrome on Linux just fine.

jaide17:01:57

@U02UHTG2YH5 thanks please let me know! Importing it into Inkscape and illustrator for exporting is on my todo list for today

p-himik17:01:50

Just tried your code on my end. Is this the expected result?

jaide17:01:38

Yes! Goal is to print without margins but at least the grid lines are visible

jaide17:01:32

Margins seem to be controlled via print settings, at least in Firefox

p-himik17:01:45

I got that without making any changes. Worked on my end both in Chrome and Firefox. The only thing that my index.html has that's beyond bare-bones is <meta name="viewport" content="width=device-width, initial-scale=1"> in its <head>. No clue how important that is.

jaide18:01:37

Wild! Well thanks for giving it a shot, I’ll try that too

jaide18:01:26

Weird all I'm getting is this

jaide18:01:41

Aha! It at least works in Brave and probably chrome. That narrows it down to at least a Firefox specific issue. That at least gives me a lead to follow. Thanks so much!

jaide18:01:27

@U2FRKM4TW by chance are you using Firefox nightly?

p-himik20:01:35

Tried on the latest Firefox and Chrome, release versions.

jaide20:01:44

Odd just can't get them to display when printing to firefox. Did find some similar issues in Firefox bugs though

p-himik20:01:09

Just in case - my version of Firefox is 121.0.1-1. I remember having problems with printing in Firefox too. Only not with SVGs but something with flexbox. Had to come up with some workaround.

jaide20:01:56

Interesting I have 121.0.1, will try updating as well

jaide01:01:42

Going to have to switch gears. I just realized the printed version from Chrome-based browsers is rasterized to pixels

jaide03:01:46

Found some success using nbb and generating a svg file then importing into Inkscape and exporting to pdf. Definitely room for improvement for automating that pipeline but at least it suits my needs. Thanks again for the help!

👍 1