Fork me on GitHub
#beginners
<
2015-12-29
>
seancorfield00:12:09

@kopasetik: Sorry, got distracted by work. Yes, if you need to make API calls to other servers, you’ll want to depend on clj-http: https://clojurians.slack.com/archives/beginners/p1451336138005235

alexmiller02:12:09

@christopherbui: also (range 1), which will be faster in some circumstances

christopherbui02:12:21

How did I forget about that

mamapitufo09:12:28

@kopasetik: the REPL probably uses readline. You can find the navigation commands here, under "Editing Commands", http://linux.die.net/man/3/readline

mamapitufo09:12:45

no prob (they are really handy to know, pretty much everything uses it to provide command line editing)

jcomplex16:12:25

this might be a stupid question but I have some code and i can run lein test and everything runs fine. But when I run lein repl load "tutorial/mongo in-ns 'tutorial/mongo init I get Unable to resolve symbol: init in this context. What am I missing? I feel like this is really simple and I am missing something minor.

jcomplex16:12:11

By the way here is the init defn (defn init [] (println "Starting Databases"))

noisesmith16:12:21

jcomplex: tutorial/mongo isn't the name of the ns I bet

noisesmith16:12:35

namespaces usually don't have / in them

jcomplex16:12:03

i knew it was trivial

noisesmith16:12:07

(in-ns 'anything/at-all) will just create a garbage useless ns

jcomplex16:12:16

my eyes glazed over that

noisesmith16:12:17

it's OK, this is the beginners channel after all simple_smile

jcomplex16:12:27

i just inherently put a period there in my head instead

kopasetik20:12:12

OK, why doesn’t this work: (map #((if (> %1 %2) %1 %2)) [13, 64, 15, 17, 88] [23, 14, 53, 17, 80])

solicode20:12:18

@kopasetik: You have an extra set of parens. This should do it: (map #(if (> %1 %2) %1 %2) [13, 64, 15, 17, 88] [23, 14, 53, 17, 80])

solicode20:12:07

Also, if you're writing it that way for learning purposes, that's totally fine, but you can use the built-in max function as well: (map max [13, 64, 15, 17, 88] [23, 14, 53, 17, 80])

plaxdan23:12:29

(map js/console.log ["one" "two" "three”])
Can anyone help me understand why the above doesn’t print anything to the console in a ClojureScript application?

plaxdan23:12:47

My first assumption was that the js functions can’t be passed as args to other functions like map so I tried the following with an inline function to no avail:

(map #(.log js/console %) ["mango" "apple" "banana”])

solicode23:12:14

@plaxdan: Because it’s a lazy sequence. You’re not actually running anything. If you use doall you should see a difference: (doall (map println ["one" "two" "three"]))

solicode23:12:35

But really, map probably shouldn’t be used with side-effects like that

solicode23:12:59

You could try using doseq instead.

plaxdan23:12:17

@solicode: thanks for the hints!

solicode23:12:25

Sorry, I wrote println, but I meant console.log

plaxdan23:12:13

(defn print-city [city]
  (let [line (str "City: " city)]
    (.log js/console line)))

(defn print-cities [cities]
  (doseq [city cities]
    (print-city city)))

(print-cities ["Boston" "Denver" "Tokyp”])
This is working nicely now, thanks. I see from some stackoverflow questions that doseq seems to be the idiomatic way to perform side-effects over a collection.