This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-20
Channels
- # beginners (106)
- # boot (25)
- # cider (2)
- # cljs-dev (100)
- # cljsjs (1)
- # cljsrn (8)
- # clojure (90)
- # clojure-brasil (1)
- # clojure-dev (7)
- # clojure-greece (2)
- # clojure-italy (4)
- # clojure-madison (1)
- # clojure-russia (15)
- # clojure-serbia (15)
- # clojure-spec (13)
- # clojure-uk (32)
- # clojurescript (88)
- # cursive (19)
- # datascript (13)
- # datomic (32)
- # defnpodcast (1)
- # dirac (43)
- # euroclojure (1)
- # graphql (5)
- # hoplon (11)
- # immutant (1)
- # jobs (6)
- # lein-figwheel (2)
- # liberator (2)
- # luminus (14)
- # lumo (22)
- # off-topic (12)
- # om (9)
- # onyx (49)
- # parinfer (45)
- # precept (4)
- # protorepl (2)
- # reagent (14)
- # ring-swagger (3)
- # sql (1)
- # test-check (58)
- # timbre (3)
- # untangled (86)
Can someone help me figure out a probably-stupid oops? I'm trying to avoid blowing the call stack on a non-recursive function (calculating triangular numbers) by leveraging memoize + laziness. This code works, and prints 28 as expected:
(defn tri [num]
(if (= num 1)
1
(+ num (tri (- num 1)))))
(def triangulate (memoize tri))
(println (triangulate 7))
However, if I try and map the triangulate function to a lazy infinite seq with:
(def triangles (map triangulate (range)))
(println (take 7 triangles))
it blows the call stack (testing this code out using cljs in planck, if it makes a difference). In fact, even if I only do (def triangles (map triangulate (range 7)))
and (take 2 triangles)
it still blows the stack.the self call doesn't go back and call the memoized version
(def triangulate (memoize (fn tri [num] (if ... (+ num (triangulate (dec num))))))
back references to a def you are inside are allowed
I knew it would be a dumb mistake... đ thanks @noisesmith !
hmm. even the properly memoized version still blows the call stack though.
(def triangulate
(memoize
(fn tri [num]
(if (= num 1)
1
(+ num (triangulate (dec num)))))))
(def triangles (map triangulate (range 7)))
(println (take 2 triangles))
-> maximum call stack exceeded...is it well defined what #?(:cljs 1) evaluates to in clojure ? is it 'nil', nothing-at-al--since-stripped-awway-by-reader, or undefined
> If no tags match and :default is not provided, the reader conditional will read nothing (not nil, but as if nothing was read from the stream at all).
@gowder FWIW, memoizing a function does not prevent a stack overflow .. if the function is called recursively many times when no memoized values are available yet, it will still blow up.
Every time I use partition
I think it is going to behave like partition-all
âŠ. until awhile later tiny parts of data are missing everywhere and I remember my nemesis
kwladyka: https://clojure.org/api/cheatsheet > transducers > use
for clojure.core, yes + core.async has other usages + advanced stuff here https://github.com/cgrand/xforms
Do you see here place for transducer? https://pastebin.com/ABd9rYAr
how can i call a java function that expects a primitive float? (f 0.5)
won't work because 0.5
is read as a java.lang.Double
nonetheless, (f (float 0.5))
doesn't work. f
is a constructor and i'm getting No matching ctor found for class
found a solution. The full signature of f
was (f float float float float)
. calling this in Java with f(1, 1, 1, 0.5)
works fine because the ones get coerced
in clojure i have to write (f (float 1) (float 1) (float 1) (float 0.5))
to get the same effect
so i'm trying to implement an abstract class using proxy
and i want to set a protected field during an init
method. using set!
seems to fail because of the visibility restriction
Is it expected that executing java -jar mystandalone.jar from the command line returns focus back to the user when the main function is finished? When I execute the jar file my main function runs, gives the output, and then it just hangs
i think i fixed it by adding (System/exit 0) at the end of my main function
@michaellindon Instead try shutdown-agents
, which might address the root cause
There's a 60 seconds delay on the agent threadpool or something like that; shutdown-agents bypasses that.
thanks guys
hi I have a âflatteningâ question
I have a list like this (def listoflists [[1 2 3 4] [5 6 7 8]])
. Iâd like to build a new list thatâs something like [ 1 [1 2 3 4] [5 6 7 8]]
by doing [1 something(listoflists)]
. (flatten) is âgreedyâ Doing it on the entire collection gives me [ 1 1 2 3 âŠ]
just on listoflists results in [1 (1 2 3 ..)]
. Iâd found some notes that indicated that either (apply concat listoflists)
or (mapcat identity listoflists)
would do what I want, but they both seem to essentially do a flatten
(def listoflists [[1 2 3 4] [5 6 7 8]])
=> #'user/listoflists
(pprint [1 listoflists])
[1 [[1 2 3 4] [5 6 7 8]]]
=> nil
(pprint [1 (apply concat listoflists)])
[1 (1 2 3 4 5 6 7 8)]
=> nil
(pprint [1 (mapcat identity listoflists)])
[1 (1 2 3 4 5 6 7 8)]
Any suggestions@eoliphant if [1 [1 2 3 4] [5 6 7 8]]
is not a typo, the answer is (cons 1 listoflists)
Is there a way to get clojure.test/are
to report the values for which it failed on failure
it doesnât seem like you actually want flattening at all
if it needs to remain a vector for datomic, you can use (into [1] listoflists)
is there an idiomatic implementation of binary trees to be found anywhere? I cannot seem to find much content on binary trees in clojure -> it makes me believe that the standard was of delclarying a node object with key left and right is not idiomatic in clojure
a clojure sorted-set is a binary tree iirc
itâs red/black
ClojureScript has CLJS ports of the Clojure datastructures, including the PersistentTreeMap, which is the red/black tree used for sorted-map and sorted-set https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L7649-L8364
There you have node objects RedNode and BlackNode, defined with deftype and having left and right fields
data.avl also uses deftype to define AVLNode: https://github.com/clojure/data.avl/blob/master/src/main/clojure/clojure/data/avl.clj#L159
this looks good, let me check some of these out, thanks
So I have a project running in both boot and lein. Under lein it runs fine, but under boot I get a ClassNotFoundException: org.jboss.vfs.VirtualFileFilter
. Both projects have the exact same dependencies. Why would boot faile to load JBoss properly?
boot does classloader jiggery pokery after the jvm has started, lein starts the jvm with the classpath set
does this eastwood message mean anything? I didnât get a warning
dbg wrong-pre-post: condition=(:exec game-record) line=103 test-ast :op=:keyword-invoke
in case someone picks this up later, i find myself writing a lot of cypher queries and executing them via tquery, but i'm constantly mapping through results to pluck the :data values and ignore all the other stuff i don't care about (incoming relationships, meta properties, etc.). i'm now resorting to spectre to stay sane. is there a better way?
in a *.cljc file, I should be able to just do: (:require [clojure.core.match :refer [match]]) and it all works right? or do I have to #?(:cljs ... :clj) separate lines ?
@qqq I think this should work.
(ns foo.bar
(:require
[clojure.core.match :refer [match] #?@(:cljs [:include-macros true])]))
You may get away with not including the include-macros thingy, and just :requiring normally, but it depends on how the namespace you're requiring is written.
http://blog.fikesfarm.com/posts/2016-03-01-clojurescript-macro-sugar.html#implicit_sugar