Fork me on GitHub
#beginners
<
2022-01-26
>
popeye14:01:52

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")

Fredrik14:01:25

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 ?

popeye14:01:31

this just an example that i modified

popeye14:01:14

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

popeye14:01:00

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

pyry15:01:40

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

pyry15:01:18

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

pyry15:01:32

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. 🙂

popeye15:01:56

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/repl.sh
$ chmod +x dev/repl.sh
Place the following in `dev/repl.sh`:
#!/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
  (:require
    [clojure.tools.nrepl.server :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)
  (rebel/-main)
  (System/exit 0))
STEP 4: add the following to your `deps.edn` aliases
:repl
  {:extra-paths ["dev"]
   :extra-deps
   {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/repl.sh

eltonlaw20:01:46

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/foo
user=> (doto {:a 1} foo)
{:a 1, :b 2}
{:a 1}

dpsutton20:01:00

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

dpsutton20:01:43

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

dpsutton20:01:15

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

dpsutton20:01:23

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

eltonlaw20:01:48

ahhh! that makes alot of sense thank you