Fork me on GitHub
#beginners
<
2016-06-01
>
dmbennett00:06:28

When it comes to iterating through sequences, why is there a first or rest but not an all?

gowder00:06:33

What use would there be for an all that wouldn't be served just by the sequence itself, or a map, or something?

dmbennett01:06:22

I think I’m having difficulty understanding how to apply certain data types, or extract certain data from a JSON rest response.

dmbennett01:06:52

In Ruby I’d have used anarray.each combined with an if to filter some data

gowder01:06:41

Can you show a concrete example? My guess is that it's probably something that can be handled with a simple map

dmbennett01:06:50

move to #C1CGD283U

gowder01:06:01

Poking around in there now

bwstearns04:06:54

@dmbennett: serves me right for naming something tmp.

plexus08:06:48

@dmbennett: the equivalent or ruby's Array#each would be doseq, i.e. loop through a sequence for side effects

plexus08:06:52

Ruby

[1 2 3].each do |i|
  puts i
end

plexus08:06:18

Clojure

(doseq [i [1 2 3]]
  (println i))

plexus08:06:43

but depending on what you're trying to do there might be better ways. You should get familiar with doseq, map, for, doall, dotimes, loop

st10:06:36

When you don’t need a reference to “moving element”, you can also use run!

(run! println [1 2 3])

dp11:06:32

Clojure Boot/HttpKit newbie question: Given this basic sample app running via Boot:

(ns geo.main
  (:require [org.httpkit.server :refer [run-server]]
            [geo.handler :refer [app]])
  (:gen-class))

(defn -main [& args]
  (run-server app {:port 8080}))
I find that the -main, while working, isn’t blocking the thread and immediately exits silently and with code 0. This appears to work with Leiningen (to the best of my knowledge. What am I doing stupidly?

dp11:06:36

Moreover, the code works fine and the webserver correctly returns when run-server is called via the repl.

vinnyataide19:06:12

can someone enlighten me this particular cljs code?

(defn jsonp
  ([uri] (jsonp (chan) uri))
  ([c uri]
   (let [gjsonp (Jsonp. (Uri. uri))]
     (.send gjsonp nil #(put! c %))
     c)))
looking at the jsonp api in google closure I see that send's first arg is the payload but in this case its nil, I somehow understand channels, does that mean that this function just opens the chan without any payload?

seancorfield19:06:37

It is sending nil to the uri and when it gets a response, it put!s that response onto the channel.

senya2219:06:43

so what's the difference between record instantiation in Clojure:

senya2219:06:09

`(defrecord Planet [name moons volume mass]) => user.Planet (def earth (Planet. "Earth" 1 1.08e12 5.9e24)) => #'user/earth (def earth-> (->Planet "Earth" 1 1.08e12 5.9e24)) => #'user/earth-> (= earth earth->) => true`

senya2219:06:13

Planet. vs ->Planet above

senya2219:06:03

when one would want to prefer one over the other?

danlebrero20:06:41

I prefer the second one. To use the first one in a different ns you will need to “import” the class, while the second one you can just “require” the ns

jswart20:06:03

The first is using Java Interop, the second is the constructor defrecord generates for you. There is also map->Planet as well generated by defrecord.