Fork me on GitHub
#beginners
<
2016-08-10
>
guy13:08:59

so does anyone know how to print out a transient vectors contents? if you know what i mean

guy13:08:03

No worries if not

kauko13:08:42

I'd probably try asking in #C03S1KBA2 - that doesn't really sound like a beginner question 😛

guy13:08:45

ah sorry

guy13:08:03

cheers @kauko 👍

guy13:08:34

in your snippet, if you add in a (println “i am here”) at line 12-13 and run it again what do you get

guy13:08:45

between the let and loop i mean

guy13:08:05

my gut feeling is saying that you might not be evaluating the pretty-print

guy13:08:15

I think loop recur is lazy

guy13:08:03

i could be wrong, but if you replace your do with doall does that fix it?

roberto13:08:18

also, the do isn’t needed

iae13:08:13

So, I did try the println, but to no avail

iae13:08:18

Nor does the doall seem to work

iae13:08:29

@roberto I did originally have a version that did not use do

iae13:08:35

Instead I printed the statements one after the other

guy13:08:56

yeah just trying your code on mine too, looks likeits just hanging

iae13:08:11

Oh, I got some output

iae13:08:15

It's severely delayed

iae13:08:28

If I mash some keys it will eventually print out twenty grids in a row

iae13:08:56

Well at least it works, sort of

roberto13:08:49

also, (read-line)

roberto13:08:10

in the loop binding, no need to call the function again (at that point it isn’t a function anymore)

roberto13:08:47

well, it is, but you are calling it twice, I’m sure that would cause some wonkiness

roberto13:08:53

nevermind, I take it back

iae13:08:06

You know, I don't think it's delayed

guy13:08:14

it prints out every 32or so for me

iae13:08:26

Yeah, if I stop typing it will stop printing

iae13:08:30

The hell did I do

guy13:08:38

it just feels like its waiting on input

guy13:08:01

which makes sense because of your read-line right?

iae13:08:15

Yes, because the game should only update when the user makes an action

kauko14:08:13

@guy just to be clear, I didn't mean you shouldn't ask that question here. I meant #C03S1KBA2 has 6 times more people than this channel, and your question sounded advanced enough to warrant asking there (not that there's some level of clojure skill you have to have to be allowed to talk there 😄 )

guy14:08:14

yeah no worries @kauko

guy14:08:22

it got answered so im happy!

scriptor15:08:39

to be clear, loop/recur is not lazy

guy15:08:54

Apologies

scriptor15:08:07

and doall is intended for functions that return lazy collections, not simply to force any expression

guy15:08:18

can you give an example?

guy15:08:27

(doall (map fn coll)) like that?

chadhs17:08:15

playing with clj-time and feel really dumb. i can’t for the life of my figure out how to “use” a formater

chadhs17:08:17

it seems to me you should be able to use it like you see it in show-formatters

chadhs17:08:20

(f/unparse :date-time-no-ms (t/time-now))

oahner17:08:57

@chadhs: you need to load the formatter first

oahner17:08:08

(f/formatters :basic-date-time)

oahner17:08:17

then you can use it in parse/unparse

chadhs17:08:03

@oahner: did i miss that in the docs? it seems to jump right from “here’s how you see a list of parsers” to “here’s how you use a custom one"

oahner17:08:15

@chadhs: I don't know if it's stated as such, but parse/unparse definitely accepts a formater object as its first argument, not the formater's keyword

oahner17:08:00

it goes from (def custom-formatter (f/formatter "yyyyMMdd")) to (f/parse custom-formatter "20100311")

chadhs17:08:11

here, noticed this: (def built-in-formatter (f/formatters :basic-date-time))

oahner17:08:53

right, so here you'd pass built-in-formatter to f/unparse

oahner17:08:21

f/formatters returns a formatter object

chadhs17:08:09

maybe it’s just me but this seems so complicated just to return a time value, compared to the UNIX date command that is.

oahner17:08:15

the API around formatters could be made more ergonomic

oahner17:08:39

as it stands, it's just a wrapper around joda

chadhs17:08:00

ah… thus the objecty-ness (word?)

chadhs17:08:17

thnx for helping me with this @oahner

oahner17:08:33

that would be my guess

chadhs18:08:32

@oahner: this ended up working well for me

(defn get-current-iso-8601-date
  "Returns current ISO 8601 compliant date."
  []
  (let [current-date-time (time/now)]
    (time-format/unparse
     (time-format/formatters :date-time-no-ms)
     current-date-time)))

(get-current-iso-8601-date)

chadhs18:08:02

now i just need to play with a little date math

chadhs18:08:08

(time/minus (time/now) (time/hours 24)) cool, getting it a bit now.

tungsten18:08:15

How do I refer to files in my resources folder so that they work with an uberjar (leiningen)

tungsten18:08:01

oahner: That does not seem to work

oahner18:08:37

do the files you're targeting actually make it into the uberjar?

tungsten18:08:51

yes, I did a jar -tf | grep myfiles

tungsten18:08:54

and they were there

tungsten18:08:11

hmm maybe im just messing up

oahner18:08:45

sounds like there's something else at play here

tungsten19:08:43

yes, the joy of lisp thanks oahner

dg19:08:53

Make sure not to give a path. Just (io/resource "abc") for "abc" directly in the resources directory.

oahner22:08:10

in cljs, if def produces ordinary JS variables, what does ^:dynamic do when applied to a def?

senya2223:08:52

Trying to understand why when I put the function into the scope of another function, its behavior suddenly changes:

(first (map #(dep/transitive-dependents graph %1) [:a :b]))
=> #{:c :f}
(defn task2 [ruleset facts]
  (let [graph (reduce apply-rule (dep/graph) ruleset)
        dependents (map #(dep/transitive-dependents graph %1) facts)])
  (first dependents) )
=> #'task2.core/task2
(task2 ruleset [:a :b])
IllegalArgumentException Don't know how to create ISeq from: task2.core$dependents  clojure.lang.RT.seqFrom (RT.java:528)

dg23:08:43

How is graph constructed in the first?

senya2223:08:46

ah, the graph

dg23:08:53

by the way (map (partial dep/transitive-dependents graph) facts)

senya2223:08:19

it''s an equivalent to what I did?

senya2223:08:02

never quite understood partial hence that way

dg23:08:29

We just take a function that needs 2 arguments, supply 1 with partial, and we get back a new function that only requires that last argument

senya2223:08:10

(def rule1 [[:a :b] :-> :c])
(def rule2 [[:c :d :e] :-> :f])
(def rule3 [[:k :d :e] :-> :m])
(def rule4 [[:p :t] :-> :k])

(def ruleset [rule1 rule2 rule3 rule4] )

(require '[com.stuartsierra.dependency :as dep])

(defn apply-rule
  [graph rule]
  (let [[premises _ consequence] rule]
    (reduce #(dep/depend %1 consequence %2) graph premises)))

senya2223:08:09

perhaps I need to stick this apply-rule inside the task2 somehow too

senya2223:08:41

to come up with just one function eventually: task2 [ruleset facts]

senya2223:08:19

but in any case, what I don't get is why the difference in how the (first ) behaves on the result

senya2223:08:33

does it make sense?

dg23:08:31

Yeah, since your first snippet didn't show the definition of graph, but it's created in the task2 scope, I was wondering if it may not be identical.

senya2223:08:03

anything glaring?