Clojurians
#clojure
<
2017-09-29
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

lvbarbosa01:09:35

Sorry, wrong thread. Moving to #beginners

qqq03:09:45

I need to generate an image by: 1. adding some text 2. adding some salt & pepper noise 3. add some gaussian noise 4. distort the image a bit 5. write it out as a png is quil the right library to use for this, or should I use something else ?

noonian04:09:31

I’m not that experienced with Quil but I think it’d be perfect for that

qqq06:09:59

how do I convert "GrayF32/class" to clojure ? GrayF32 image = UtilImageIO.loadImage("test.png",GrayF32.class);

bronsa09:09:19

just GrayF32

qqq09:09:25

@bronsa: lol, thanks :slightly_smiling_face:

mseddon10:09:32

is there a way to coax cider to allow inspection of return values in the repl like SLIME? currently it seems any value returned is just syntax highlighted but is otherwise a just a string in the buffer.

dominicm10:09:38

there is a cider-inspect

mseddon10:09:49

doh! thanks I'll take a look

joshkh10:09:08

how can i print to the console from .cljc files? neither js/console.log and println work (which is understandable as we're not specifying a build target)

gklijs10:09:19

You can use something like (:require [#?(:clj clojure.spec.alpha :cljs cljs.spec.alpha :default clojure.spec.alpha) :as s]) to support both clj and cljs specific funtionality

gklijs11:09:09

I used this to have all my spec’s in one file

codeasone11:09:39

Good day to all: I've encountered a namespace loading failure when using cloverage, which I'm not sure how to debug Exception in thread "main" java.lang.IllegalArgumentException: Parameter declaration missing, compiling:(/tmp/form-init5334710656729606392.clj:1:73

codeasone11:09:03

The tmp files does seem to exist anymore so I cannot inspect /tmp/form-init5334710656729606392.clj:1:73

codeasone11:09:41

and the Exception trace doesn't address any lines of my own code... I'm a bit stumped tbh

codeasone11:09:12

does > doesn't

codeasone11:09:41

Does anyone know if temporary files like /tmp/form-init5334710656729606392.clj:1:73 can be retained somehow?

codeasone11:09:13

I'm running under lein if that is significant: lein cloverage specifically.

codeasone11:09:27

I cannot find any obvious omissions of parameter declarations within my (defn ...)'s

martinskou11:09:11

(enable-console-print!)

codeasone11:09:31

Well, that wasn't much fun. By nuke all test namespaces and progressively removing clj files from my project, until cloverage worked I isolated the problem to a (defn exist-until) - silly me.

codeasone12:09:02

Still it would be nice if these kinds of issues were easier to isolate - open to ideas

codeasone12:09:56

Seems like I was half-way through implementing a function I thought I'd need, but ended up not using it and since it was not referenced the application concerned compiles and runs fine.

codeasone12:09:57

But clearly cloverage wants to instrument everything, regardless of whether code is used or not...

codeasone12:09:40

Actually, it turns out the function was the only (defn ...) within a new clj file I'd created, that was not being required by any other namespace - doubly silly me. Which is why lein run was not picking it up.

codeasone12:09:49

When I actually require said file, I see a helpful error message that would have enabled me to isolate the problem a lot quicker Exception in thread "main" java.lang.IllegalArgumentException: Parameter declaration missing, compiling:(xxx/xxxx/xxxxxx/domain.clj:13:1) - just in case anyone is interested.

yogidevbear13:09:26

Hi @alexmiller, I'm reading through this article of yours on sequences and was wondering what you meant by "logical" when you said: >Sequences are logical lists http://insideclojure.org/2015/01/02/sequences/

pesterhazy14:09:38

@yogidevbear I'm not @alexmiller but I read this as "conceptually", i.e. something that conforms to the concept of a list, even if it may not be implemented as a classical Lisp list (cons pairs)

lxsameer14:09:26

I wrote a spec for a function, but spec can't create a generator for it. Is there any way to provide the generator for that function to spec ?

genec14:09:40

@yogidevbear Perhaps this will help, https://clojure.org/reference/lazy "A seq is like a logical cursor"

tbaldridge16:09:45

Unlike other lisps, Clojure has an abstract representation of a list. Instead of saying a list is a cons cell, in Clojure a "list" is something that implements ISeq

tbaldridge16:09:10

clojure.lang.ISeq, a interface that defines a "first" and "rest" method.

tbaldridge16:09:39

Seq - something that conforms to ISeq. May be a bunch of cons cells, may be an view over a collection, etc

tbaldridge16:09:51

Seqable - something that isn't itself a seq, but can be converted to a seq

tbaldridge16:09:19

List - a list is technically a PersistentList which is a ISeq that also implements some other features (like O(1) counting).

tbaldridge16:09:16

So all that to say, "logical list' is a way of saying all of that ^^ while also showing that Clojure defines lists a bit differently from other lisps, or even Java.

yogidevbear16:09:15

Thanks @tbaldridge :+1: Going to read that a few times over to let it sink in :simple_smile:

chalcidfly17:09:49

Is there a way to run read-string to get the from from a string without evaluating the defs?

chalcidfly17:09:32

So like something to wrap around (read-string (defn inc [x] (+ x 1))) so that clojure.core/inc doesn’t get overwritten?

bronsa17:09:14

that doesn't make much sense, read-string operates on strings not on data and doesn't do any evaluation

bronsa17:09:19

can you clarify what you mean?

chalcidfly17:09:06

Funny, I thought (read-string "(def inc (fn [x] (+ x 1)))") would overwrite inc but it doesn’t seem to

chalcidfly17:09:35

Something fishy’s going on in my code. Somewhere the def is being evaluated, but I thought it was just being read…

chalcidfly17:09:35

Ok, so my problem wasn’t with read-string. @bronsa, is there a way to do (e/emit-form (ana.jvm/analyze '(def inc (fn [x] (+ x 1))))) without overwriting clojure.core/inc?

bronsa17:09:46

yes, you can provide a different value for ana.jvm/create-var

bronsa17:09:24

that will cause some issues, if you're not careful

the2bears17:09:00

Very intrigued by what @chalcidfly might be working on :slightly_smiling_face:

chalcidfly17:09:40

@the2bears still in the initial research/brainstorming phase, but I hope to have something releasable within a month

chalcidfly17:09:45

@bronsa so it’s not really possible without forking and extending the lib?

bronsa17:09:35

no it's possible, all the knobs are there

bronsa17:09:58

it's just tricky to handle all the edge cases if you do

bronsa17:09:11

there's a few of implicit assumptions that the clojure evaluation model makes

bronsa17:09:31

that assume a var will be interned at analysis time rather than at evaluation time

bronsa18:09:53

depending on what you're doing, you might not care tho

chalcidfly18:09:10

@bronsa I see. If I end up going down the road, can I dm you for help? :stuck_out_tongue:

bronsa18:09:25

expect some async in response tho :)

chalcidfly18:09:32

haha of course :slightly_smiling_face:

bronsa18:09:26

while I'm here, I'll expand a bit on what the edge cases are

bronsa18:09:26

- clojure needs to intern vars at analysis time, to support expressions like (def a (fn [] a)), so that the var a is reachable in the intialization body of the var def - t.a provides a configurable create-var function that you can replace with a no-op, so that the var won't get interned - because t.a resolves vars using its global env map rather than inspecting directly clojure's reified namespaces, so that if you want you can make that expression analyzable w/o actually interning anything however - because side-effects can happen at macroexpansion time, including var interning and var unmapping, t.a. needs to rebuild its namespace map from clojure's reified namespaces after every macroexpansion (yes, there are actually libraries that do this sort of stuff, ugh) - this means that the var assoced into t.a's namespace map will be dissoced after the first macroexpansion if it's not actually interned - to work around this, the function responsible for updating t.a's namespace map is pluggable, thrugh a function under the :update-ns-map! key in t.a.jvm's global-env, so that you can provide your own that ensures the non interned var is kept around

bronsa18:09:29

understanding all this requires some knowledge of how clojure's evaluation model works and some understanding of tools.analyzer's implementation

bronsa18:09:28

all this complexity is unfortunately unavoidable, since clojure's evaluation model wasn't designed with ease of analysis in mind

chalcidfly18:09:39

good heavens, that is complicated…

chalcidfly18:09:55

I need to save that somewhere

waffletower19:09:30

Is there a way to refer to unqualified void in a syntax quote context?

noisesmith19:09:36

isn’t that just nil?

noisesmith19:09:49

I don’t think void means anything in clojure

waffletower19:09:58

I thought it did in gen-class

noisesmith19:09:25

oh - gen-class probably wants the symbol

noisesmith19:09:47

so in a syntax-quote, use

`(... ~'void)

waffletower19:09:54

it might ignore the namespace qualification I should test

waffletower19:09:02

ah there it is

noisesmith19:09:11

that would be handy, but usually the unquote / quote combo does the trick otherwise

waffletower19:09:00

that was exactly what I needed

waffletower20:09:18

don’t have to test

chalcidfly20:09:44

Lotta questions from me the last couple days. Got one more.

chalcidfly20:09:52

Is there a way to check if eval will work on a variable?

chalcidfly20:09:02

Something like evalable?

noisesmith20:09:37

@chalcidfly you could see if resolve returns non-nil

noisesmith20:09:08

user=> (resolve 'inc)
#'clojure.core/inc
user=> (resolve 'foo)
nil

noisesmith20:09:31

I don’t know what you mean by variable though

noisesmith20:09:48

do you mean symbols that may be bound to a var or a local? just vars?

noisesmith20:09:53

are classes included?

chalcidfly20:09:54

Oh, I mean a form

chalcidfly20:09:02

So like true for (+ 2 2) but false for 5

chalcidfly20:09:07

Maybe seqable would do it?

noisesmith20:09:11

but you can eval 5

noisesmith20:09:30

user=> (eval 5)
5

chalcidfly20:09:50

Hm.. I guess eval isn’t really what I need then

noisesmith20:09:05

do you want to know if something is fully simplified?

noisesmith20:09:48

eg. in (case x (1 2) :a :b) (1 2) is fully simplified (one of the few places something that has parens inside it would be such)

chalcidfly20:09:06

Well in this case, I want a trigger on both

chalcidfly20:09:14

Both the outer form and the inner simplified form

noisesmith20:09:47

OK but you’ll have gotchas for case and any other macro that treats parens oddly

noisesmith20:09:33

(depending on how you’re doing this simplifying and whether the language you are supporting is actually clojure or not)

waffletower21:09:17

One last syntax quote context question of the day :grinning:.. I am trying to construct a map from a collection of forms

{[email protected]}
but I receive a compiler exception Map literal must contain an even number of forms

waffletower21:09:05

trying that now… my forms might be angry for another reason. thanks!

waffletower21:09:32

nah, hash-map was the ticket…

lxsameer21:09:47

how can I create to specs which reference each other?

eriktjacobsen22:09:21

@lxsameer There is a #clojure-spec room. There are many ways to have specs referencing specs, such as: (s/def ::checks (s/coll-of ::depend)) (`::depend` is a spec)

lxsameer22:09:50

I see, but i need to reference to ::checks inside the ::depend as well