Fork me on GitHub

I have a function in my code as below which is prod code.. I am confused that what value get inserted to a and b , when called with `(test-hello "A" "B")

(defn test-hello
  [arg1 arg2]
  (let [structure (get-value input)]
    (fn [a b]
      (assoc {} a b))))

(test-hello "A" "B")


The return value of (test-hello "A" "B") is a function. But why doesn't test-hello itself use it's parameters arg1 and arg2 ?


this just an example that i modified


so it means it creates a function and give new function ?


it creates a function, but what would be the value of a and b


The example doesn't really make a lot of sense. Perhaps you give an example that's less redacted?


As it stands, the "A" and "B" you give to test-hello are simply not used at all.


If your question of "what would be the value of a and b" was related to the function returned - well, they're just parameters so they would get whatever values you pass in to the returned function. ūüôā


got it ...thanks

ūüĎć 1
Nom Nom Mousse16:01:50

How do I connect to an nrepl server from the command line? I've tried stuff like clj -p 7000

Nom Nom Mousse16:01:13

> $ clj -Sdeps '{:deps {nrepl {:mvn/version "0.9.0"}}}' -m nrepl.cmdline --connect --host host --port port Teach a person to fish, eh

randomm char19:01:30

and on windows yeh gotta double qoute ""0.9.0"" :P

Chad Angelelli01:01:52

i'm a personal fan of the following: STEP 1: create "dev" directory

$ cd /path/to/project/root
$ mkdir dev
STEP 2: create shell script
$ touch dev/
$ chmod +x dev/
Place the following in `dev/`:
#!/usr/bin/env bash

script_dir=$(dirname "$0")
cd $script_dir
cd ..

clj -M:repl
STEP 3: create CLJ file to launch custom nREPL place the following in `dev/repl.clj`:
(ns repl
    [ :as nrepl-server]
    [cider.nrepl :refer [cider-nrepl-handler]]
    [rebel-readline.main :as rebel]))

(defn -main []
  (println "nrepl server at localhost:40000")
  (nrepl-server/start-server :port 40000)
  (System/exit 0))
STEP 4: add the following to your `deps.edn` aliases
  {:extra-paths ["dev"]
   {com.bhauman/rebel-readline {:mvn/version "0.1.4"}
    org.clojure/tools.nrepl {:mvn/version "0.2.12"}
    cider/cider-nrepl {:mvn/version "0.22.4"}
    ;; add additional libs here...
   :main-opts ["-m" "repl"]}
STEP 5: call it!
$ cd /path/to/project
$ ./dev/


Is there someway to do doto with an inline defined function? why does it work like this?

user=> (doto {:a 1} println)
{:a 1}
{:a 1}
user=> (doto {:a 1} #(println (assoc % :b 2)))
{:a 1}
user=> (defn foo [x] (println (assoc x :b 2)))
user=> (doto {:a 1} foo)
{:a 1, :b 2}
{:a 1}


card-test=> (macroexpand '(doto {:a 1} #(println (assoc % :b 2))))
 [G__192272 {:a 1}]
 (fn* G__192272 [p1__192269#] (println (assoc p1__192269# :b 2)))


same issue with -> that it threads the form into the first position of (fn [arg] ...) to become (fn threaded-value [arg] ...) so you are naming a function


card-test=> (doto {:a 1} (#(println (assoc % :b 2))))
{:a 1, :b 2}
{:a 1}


if you wrap it in extra parens you should see it work


ahhh! that makes alot of sense thank you