Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

values are mangled in nested functions #38

Open
ozimos opened this issue May 9, 2024 · 1 comment
Open

values are mangled in nested functions #38

ozimos opened this issue May 9, 2024 · 1 comment

Comments

@ozimos
Copy link

ozimos commented May 9, 2024

  (ns user
    (:require [snitch.core :refer [defn*]]))

  (def sample-data [{:users [1]} {:users [2]} {:users [3]}])

  (defn* repro [input]
    (mapv (fn [{:keys [users]}]
            {:status :ok
             :users (mapv (fn [v] {:id v}) users)}) input))
             
  (repro sample-data). ;; [{:status :ok, :users [#'user/this>]} {:status :ok, :users [#'user/this>]} {:status :ok, :users [#'user/this>]}]
  
  this< ;; {:status :ok, :users [#'user/this>]}
  
  this> ;; (this 3)
  repro< ;; (repro [{:users [1]} {:users [2]} {:users [3]}])
  
  ;; This is a problem when callers of repro fn try to process
  ;; the results. For example we get an error below

  (->> sample-data
       repro
       (mapcat (fn [{
                 :keys [users]}] users))
       (reduce + 0))
       
;;  Execution error (ClassCastException) at user/eval97881 (form-init8825021676185248856.clj:648).
;; class clojure.lang.Var cannot be cast to class java.lang.Number 
@AbhinavOmprakash
Copy link
Owner

Thanks for reporting this, I'll take a look when I have time. I've noticed this bug before. You're welcome to contribute :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants