Fork me on GitHub
#cider
<
2023-06-29
>
Colin (fosskers)00:06:22

TIL: you can cider-undef on a defonce in order to be able to rerun/redefine it in the current REPL session without needing to restart the whole REPL

gratitude 4
👏 2
Sturm12:06:04

I've seen someone bind a keyboard shortcut in Cursive to call a clojure function eg. (reload) to reload a web server process during local development. Is that something I could do in cider?

dakra13:06:34

Sure. A simple solution would be something like (define-key cider-mode-map (kbd "<f12>") (lambda () (interactive) (cider-interactive-eval "(reload)")))

vemv14:06:44

There's also cider-ns-refresh

jpmonettas14:06:57

@UDE7BJK1N here https://www.youtube.com/watch?v=2nH59edD5Uo&amp;t=2289s I'm demoing a "dev menu" I create for my projects. This is a way of binding a key to show a menu per project with different key actions for that project, like reload, start webserver, clear a chache, calling profilers, etc. You can see the code here https://github.com/jpmonettas/elisp-utils/blob/master/clojure.el

enn20:06:19

Do folks feel like this is a bug?

user> (list 'var 'foo)
#'foo
Compare to bare Clojure REPL:
user=> (list 'var 'foo)
(var foo)

dpsutton20:06:43

100% a bug.

Alex Miller (Clojure team)21:06:52

#'foo desugars to (var foo) so these are equivalent semantically, the question is what the printer does for a var I think. Clojure's printer re-sugars back to var quote, and I assume something in cider is making a different choice there. it's different, but not sure it's a bug?

dpsutton21:06:43

(list 'var 'foo) should never get identified with any foo vars right? It seems an unequivocal bug if CIDER is identifying the symbol foo in the form (list 'var 'foo) with a var of that name, right?

phronmophobic21:06:24

What does (deref foo) print?

vemv21:06:10

I would guess that cider's #' formatting tries to accomplish something that Clojure lacks by default. Without an example of that feature it's harder to assess if the bug can be fixed

enn21:06:16

@U7RJTCH6J it throws because it’s not actually a var.

phronmophobic21:06:32

oops. I meant (list 'deref 'foo)

enn21:06:47

I’m not sure if it’s a bug either, but I think the behavior of the standard Clojure printer is better because it makes clear that I’m looking at a list and not a var. I ran into this today because my code was throwing trying to call one of these things, and I was looking at it in the REPL and thinking it was a var, because CIDER prints them indistinguishably.

👍 2
Alex Miller (Clojure team)21:06:03

(list 'var 'foo)
at the repl is evaluating that list. var is a special form that returns a var. the repl is then printing that var. the default printer re-sugars vars to print them as var quotes, #'foo. But the printer is open and you could print vars as (var foo) and it means the same thing.

enn21:06:38

@U7RJTCH6J that also throws because it’s not actually a var, it’s just printing like one. it’s a list so it throws class clojure.lang.PersistentList cannot be cast to class java.util.concurrent.Future

enn21:06:09

there is no actual var foo here in this example. Just the list ('var 'foo) . which might evaluate to a var, but it’s not being evaluated, it’s just a list of symbols.

user> (list 'var 'foo)
#'foo
user> (type *1)
clojure.lang.PersistentList

Alex Miller (Clojure team)21:06:34

oh right, I am confusing myself here

Alex Miller (Clojure team)21:06:48

then yes, I agree it's a bug :)

phronmophobic21:06:56

user> (list 'deref 'foo)
(deref foo)
For both cider and the clojure cli repl.

enn21:06:51

oh, sorry @U7RJTCH6J, I misread, I thought you were asking about (deref (list 'var 'foo)). Yes, lists with other symbols render normally, only lists of length 2 with 'var as the first value render in this confusing way AFAICT.

phronmophobic21:06:28

The reason I ask:

> (= '@foo (list `deref 'foo))
true
clojure cli:
user=> (list `deref 'foo)
(clojure.core/deref foo)
cider:
user> (list `deref 'foo)
@foo

phronmophobic21:06:18

and with var:

user> (= '#'foo (list 'var 'foo))
true

phronmophobic21:06:23

user> (= ''foo (list 'quote 'foo)) 
true
clojure cli:
user=> (list 'quote 'foo)
(quote foo)
cider:
user> (list 'quote 'foo)
'foo

phronmophobic21:06:56

I assume you probably get a similar result for some other sugars like ~ and ~@ .

dpsutton21:06:20

(-->
  id                                 "35"
  op                                 "eval"
  time-stamp                         "2023-06-29 16:34:07.272187000"
  code                               "(list 'var 'foo)"
  ns                                 "user"
)
(<--
  id         "35"
  value      "#'foo"
)
it’s some bug in the printer.
user> (list 'var 'foo)
#'foo
user> (type *1)
clojure.lang.PersistentList

enn21:06:44

interesting that for deref it behaves differently depending on whether the symbol is namespaced or not, but not in these other examples

phronmophobic21:06:41

Just checked. deref behaves similarly to ~, but cider doesn't re-sugar ~@.

phronmophobic21:06:17

I think the reason deref must be namespaced is just based on the how the reader desugars @foo and ~foo. Those desugar to the fully qualified functions, deref and unquote while var and quote are special forms that can't be fully qualified.

phronmophobic21:06:38

Fun fact, afaik (var foo) always refers to the special form even if you try to make a local binding:

user> (let [var (constantly 42)]
        (var 10))
Syntax error (ClassCastException) compiling var class java.lang.Long cannot be cast to class clojure.lang.Symbol (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.Symbol is in unnamed module of loader 'app')

hifumi12322:06:03

one of the consequences of being a lisp-1 instead of a lisp-2