Fork me on GitHub
#clojure
<
2015-09-28
>
lfn301:09:21

Can anyone think of a cleaner way of doing:

(swap! a-map #(assoc %1 :a (inc (get :a %1 0))))
My issue is that the atom gets reset to {} occasionally, so it's blowing up on nulls.

danielcompton01:09:08

@lfn3: what are you trying to achieve here?

lfn301:09:15

Just keep a running total on some stuff.

lfn301:09:54

It's just counting up stuff passing through a channel, and the counter gets reset when it sees a certain message.

lfn301:09:13

So there's a corresponding :b :c etc.

danielcompton01:09:22

@lfn3: this is a little clearer

(swap! a-map
       (fn [m]
         (->> (get m :a 0)
              (inc)
              (assoc m :a))))

danielcompton01:09:43

You could also look at using find instead, though I’m not sure if it would be any cleaner

danielcompton01:09:25

(update {:a 3} :a (fnil inc 1)), this is better

danielcompton01:09:15

aka (swap! a-map update :a (fnil inc 1))

lfn302:09:02

Ah. fnil. forgot about that.

tel02:09:05

Is there a way to lexically override defs

tel02:09:14

and maybe get the results as a map, perhaps

tel03:09:56

guess not

lfn303:09:02

@tel it's just kinda quiet at this hour, I think.

tel03:09:27

oh! haha, sorry, no, that had more to do with my own research then any lack of response simple_smile

lfn303:09:31

Ok. Yeah the only thing I can think of off the top of my head is (with-redefs) but I'm sure you already know about that.

tel03:09:37

yeah, similar idea, but the control is in the wrong place I think

tel03:09:50

I’m trying to capture the effects of a macro which involves some defs

tel03:09:01

when I don’t really want to introduce new variables or anything

tel03:09:12

just get ahold of the defined bits

lfn303:09:28

Right so the macro is defining some stuff for you, and you want to capture the things it's defined?

tel03:09:43

just like, make a junk namespace and toss it afterward

lfn303:09:47

You could look at the state of (ns-publics) before and after executing the macro?

lfn303:09:27

Or some of the other (ns- things, there's quite a few of them, depending on what exactly the macro defines.

lfn303:09:10

You could write something that wrapped the macro in question and emitted the new defs in a map.

lfn303:09:14

At least I think you could.

tel03:09:33

I’m actually getting some headway just straight re-mangling symbols out of the macro

tel03:09:49

they’re just a big list of (def sym fn) so it’s not hard to parse again

tel03:09:52

just weird..

cfleming03:09:32

Does anyone know of a classloader that I could use to load classes from jar files that isn’t a URLClassLoader?

lfn303:09:29

@tel yeah I wouldn't want to do that repeatedly though.

tel03:09:25

it’s super hacky

tel03:09:43

but feels ever so slightly superior to the alternative of step by step namespace hacking

lfn303:09:28

Aw man namespace hacking is my favourite. It reminds me of dirty reflection hacks from when I wrote C#

danielcompton05:09:22

@cfleming: there was someone on the mailing list a few months back who was trying to do some stuff with custom ClassLoaders

cfleming06:09:27

@danielcompton: Thanks, in the end I found what I needed in the IntelliJ codebase

danielcompton06:09:57

Legend tells there’s a lisp interpreter hidden deep in the IntelliJ codebase

cfleming07:09:33

@danielcompton: According to Greenspun, there must be.

borkdude08:09:31

are Rich's slides from 'Clojure, made simple' at Java One available somewhere?

profil11:09:04

I need to parse a tab-separated columns file, which approach should I have? I thought about using with-open and map #(clojure.string/split % #"\t") over the line-seq. Anyone got a better solution?

jrychter12:09:48

@profil: for really simple files (where you control the source of the data), what you wrote looks great. For external data, I use either data.csv, or clojure-csv, the latter is more tolerant of real-world files.

profil12:09:32

Yeah the file is really simple, 3 columns consisting of floats, so I am using clojure.edn/read-string to parse the numbers

jrychter12:09:23

If the data comes from somewhere you don't control, I learned that there is no such thing as "really simple". The world continues to surprise me.

alexmiller13:09:50

@borkdude: in general, Rich does not release his slides as he prefers them to be viewed in context of the talk

csmith14:09:09

@jeremyraines: I have one that isn’t quite complete

csmith14:09:47

More than willing to share. I’ve got 1-4 dimensions working but haven’t quite gotten around to getting the definable seed thing working

csmith14:09:35

existing ones I found were ~ok but didn’t quite have everything I needed

jeremyraines14:09:17

I might have gotten it working . . . but it looks too regular and I can't tell if it's because I have too few pseudorandom vectors, or because I did something wrong

jeremyraines14:09:08

I just used short lookup table for gradient vectors, without using the seeds, because I didn't really understand the bit twiddling that all the implementations I saw were doing to generate the gradients on the fly

jeremyraines14:09:16

but yeah, would love to see it

jeremyraines14:09:14

here is mine so far, excuse the repitition and dog-slowness of the canvas parts, I was learning that as I went

jeremyraines14:09:12

very cool, thanks! This will help me understand it better. I don't know what the octaves are at all yet

csmith14:09:54

just realized the image generator thing isn’t using it there, but can drop that in as appropriate to see it. The octaves basically tweek some parameters and do the noise iteratively to sort of improve on the initial thing

csmith14:09:20

First round gives you peaks/valleys, next round gives you bumps, next one gives you boulders so to speak (if it is elevation)

csmith14:09:24

octaves is like number of iterations IIRC, persistence (which I misspelled 😕 ) is like how much each next one affects it (each one is “weaker”)

jeremyraines14:09:42

another basic thing I don't quite understand is: why 256 seeds? and then also why does the permutation table need to be 512, i.e. what's the nature of and purpose of "allow[ing] for indexing to wrap-around"

csmith14:09:37

yeah. So basically, that table is a hard-coded lookup table. There is a function that generates those and its super hard to find online what it is. Always see the table everywhere which makes me sad, especially because we could use memoization

csmith14:09:40

(and its a table in Perlin’s paper). Anyway, the idea is that if you don’t start at the beginning and offset it some amount, you’ll get a different result (I don’t provide a way to do this in my code yet)

csmith14:09:11

and the 512 thing is prevent needing to use modulus to wrap the index around to beginning when it goes past 255

jeremyraines14:09:27

oh, I see, thanks

csmith14:09:05

but this only gives you a seed value for the 0-255 range. I’ve been trying to figure out how people do E.g. minecraft, with a long seed value

jeremyraines14:09:51

and that table is just for looking up the pseudorandom gradients, right?

csmith14:09:07

yeah, that is my understanding

csmith14:09:40

(I did this ~1 month ago, and I read a lot until I understood 50% of the math but didn’t get much deeper)

ytl14:09:09

hi, looking for help on this threaded-form.. why wouldn't this work? https://www.refheap.com/110038

spei14:09:58

@ytl I think you need an extra set of parens around the fn

ytl14:09:12

@spel sry, doesn't seem to fix it

csmith14:09:16

yeah, you’d need to actually call it, or either replace it with just (* 3)

ytl14:09:24

This really is to be an if-stmt inside a -> call and want to bind the var to the if.else calls (not the predicate) so need to 'move' where the var gets bound

ytl14:09:18

@spel heh I must've missed out a parens the first time, working, thank you!