Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

cljr-expand-let on a let inside of a let value is confused #488

Copy link
Copy link
Open
@dgtized

Description

@dgtized
Issue body actions

When using cljr-expand-let on the let inside of the let value it gets quite confused.

(let [a 1
      b (let [c 2]
          (+ a c))]
  b)

Expected behavior

Any of the following seem reasonable;

(let [a 1
      c 2
      b (+ a c)]
  b)

OR

(let [c 2]
  (let [a 1 
        b (+ a c)]
    b)

OR

Throw an error that it can't manipulate this form.

Actual behavior

;; cljr-expand-let at ^(let [c 2]) =>
(let (let [c 2]
       [a 1
        b (+ a c)])
  b)

Which is not valid clojure. I suspect this may be a tricky problem to resolve correctly as the inner let may encodes dependencies on other vars in the outer let, however, I think if the value is inserted as a key in the parent let immediately before this key it should work? I'm also not sure what should happen if the inner let has more then one key and one depends on the other. IE

(let [a 1
      b (let [c 2
                d (+ a c)]
            d)]
  b)

I guess maybe the operation should just fold all the keys in the inner let to the outer in order? Like so maybe?

(let [a 1
       c 2
       d (+ a c)
       b d]
   b)

Thanks for creating this tool, it's very useful! Also appreciate this particular case is kind of a tricky edge case, but thought it would be useful to report!

Steps to reproduce the problem

Use cljr-expand-let on the inner let.

Environment & Version information

clj-refactor.el version information

clj-refactor 2.5.1 (package: 20210413.733), refactor-nrepl 2.5.1

CIDER version information

;; CIDER 1.1.0 (package: 20210422.802) (Plovdiv), nREPL 0.8.3
;; Clojure 1.10.2, Java 1.8.0_292

Leiningen or Boot version

clojure CLI Version: 1.10.2.774

Emacs version

GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2021-04-30

Operating system

Ubuntu 2020.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.