Fork me on GitHub
#beginners
<
2016-11-05
>
markx00:11:46

My guess is that I can do

(dynamic-buffer
    (composite-frame 
      :a (int32-type)
      :bf bit-field-frame)))

markx00:11:33

But then, how do I create a wrapped buffer from it?

markx03:11:32

Can anyone help?

olegakbarov12:11:32

Very newbie question: why acc is always {} on every iteration of map?

(let [acc {}]
  (map
   (fn [item]
     (has-kids? acc item msgs))
   msgs))

olegakbarov12:11:10

i expected it to be like a first arg in reduce

markx13:11:39

Maybe it’s a lexical thing?

roosta13:11:09

@olegakbarov Because you never actually change the acc value. Its defined, and then referred to in has-kids?. Data in clojure is immutable so whenever you try to change acc you create a new value in that scope based on acc. Reduce and other functions like it is based on recursion so that you take a value, do whatever to it and the run the same function with a 'new' variable that came from the previous recursion building it up for each pass. I'm unsure exactly what you're trying to do since I don't know what has-kids? do but maybe you could wrap your map in into {} so that whatever result you get back from map is put in a map? Something like this:

(into {}
      (map
       (fn [item] item)
       [[:foo "bar"] [:baz "qux"]]))
I hope that explanation was accurate 🙂 my best go at it anyways.

olegakbarov13:11:58

@roosta thanks!

olegakbarov13:11:48

i felt like let binding creates ‘shared’ scope for all functions

roosta13:11:05

it does, but still every attempt to change it creates a new value. If you wanted a value that you could change you'd have to use an atom. It's tricky to wrap your head around immutable data if you're used to other languages.

gamecubate13:11:45

Trying to massage this:

[[“id” “name”][1 “one"][2 “two"][3 “three"]]
into that:
[{:id 1 :name “one”}{:id 2 :name “two”}{:id 3 :name “three"}]

gamecubate13:11:38

It looks like a case for mapv. Will try.

dominicm13:11:52

Hmm, mapv is rarely necessary.

gamecubate14:11:06

(let [keys (map keyword (first data))]
will get me the keys. Then somehow need to “pivot” that with (rest data).

dominicm14:11:16

(fn [[header & rows]]
  (let [header-keys (map keyword header)]
    (map #(zipmap header-keys %) rows)))

dominicm14:11:21

I think that's what you want.

gamecubate14:11:42

reading up on it

gamecubate14:11:11

brilliant. I hadn’t spotted that one. Thanks a lot. Exactly what I needed.

dominicm14:11:36

No problem. It's a nifty function for csvs & row-based data

gamecubate14:11:38

A lot of useful fns to remember in clojure. That’s the beauty of it. It’s probably already in place, whatever the need.

gamecubate14:11:46

Exactly what I was doing.

gamecubate14:11:05

Using CSV parse with cljs-ajax to fetch remote csv data

gamecubate14:11:25

Trying to reagent-friendlify the mapbox leaflet map lib

gamecubate14:11:34

using 43000 rows of data

dominicm14:11:56

lazy sequences are your friend here.

gamecubate14:11:16

the nasty part being the “reagenting” of stateful leaflet maps. head hurts.

gamecubate14:11:53

Thanks @dominicm this clears a hurdle

markx14:11:49

Hmm… Anyone happen to know buffy?

markx14:11:21

I’m very lost when trying to use buffy

markx14:11:22

yeah, that’s the thing. clojurewerkz/buffy

markx14:11:17

So I’m trying to parse a file with data like this: int32 int32|string. I don’t know how to combine a Primitive type with a frame-type

thedavidmeister14:11:07

@markx i’m using clojure happily with essentially zero java knowledge 🙂

thedavidmeister14:11:40

@markx haven’t done much heavy lifting with files though, mostly been working in the browser

markx14:11:48

@thedavidmeister That’s very good to know. Guess I happened to start on the tough task.

markx14:11:29

@gamecubate Could you help me a bit here?

gamecubate15:11:15

I’ve never used it and am looking it up now. Hang on.

gamecubate15:11:07

frame-type? Only ever heard of that in R programming.

markx15:11:12

That’s just the thing it uses for dynamic length type. Not a standard thing I guess.

herbm15:11:10

Did you get help? I don't know what you mean by a "frame type" either

herbm15:11:14

And what does "combine" mean in this context? (add? concatenate? put in a list? assoc? or something else?) @markx

markx15:11:26

Hmm. frame-type is a function used in the example code in README

markx15:11:25

So here you can use this “dynamic frame” thing, to parse a string with dynamic length.

markx15:11:47

so my question is, wow do I construct a buffer that includes both buffy’s primitive types and dynamic frames?

markx16:11:36

@herbm Does that make any sense?

herbm16:11:17

Not really, looks to be part of some library, I could make guesses but so far they've been wrong (thought it might have something to do with decoding/encoding network frames). Maybe a more expert Clojure programmer will understand without context or guess the library markx

herbm16:11:21

It doesn't even look like built-in Clojure to me -- could be wrong easily -- so what are function/spc-form/macros dynamic-buffer frame-type frame-encoder frame-decoder?

herbm16:11:56

Working backwards my guess is frame-type might be a macro which is making functions out of the encoder/decoder

herbm16:11:16

Anything in first position of a form has to act like a funtion ( e.g., a macro or special form or somehow be interpreted as data by some other part of the program, i.e some macro or spc. form.

herbm16:11:16

It could easily be from some part of the language I haven't study yet of course

herbm16:11:31

What is the source of this @markx?

herbm16:11:48

Google searches are putting me on it being built-in

markx16:11:46

I definitely don’t think it’s a built-in in. It’s from this library.

markx16:11:25

See the only doc for this lib I could find is the project’s README file, and it doesn’t seem to cover my use case, so I got lost.

markx16:11:01

Any term I said can be found in the README file. I just quoted them.

herbm16:11:04

Ok, so maybe I came in too late to help (reading back) -- "this library"? What are you really trying to accomplish? What is the current issue? (unless you already received help)

markx16:11:35

Nonono, I’m still lost.

markx16:11:19

So the question is, I’m trying to parse a local binary file. Someone pointed me to https://github.com/clojurewerkz/buffy. The binary file is this: https://aria2.github.io/manual/en/html/technical-notes.html

herbm16:11:25

"wow do I construct a buffer that includes both buffy’s primitive types and dynamic frames?" What would that mean and what would it do? Are you trying to assemble/compose a datatype supporting multiple interfaces?

herbm16:11:10

(I am personally not very knowledgeable about Clojure interfaces and object like structures -- just haven't spent much time with those yet.)

markx16:11:57

Nothing like that. This is more of a question about the library, and less about Clojure.

herbm16:11:36

This is probably more than a 'beginners' question so you might also post in one of the other threads but first clarify what exactly you are asking and assemble the details

markx16:11:32

Oh I’m not sure the difference between the “beginners" channel and “Clojure” one.

herbm16:11:45

You'll need to be pretty specific, about your GOAL at least. There are many ways to "combine" -- from a simple as a list (probably not what you want) to perhaps hash table with a key and value for each piece {:buffy-buffer buffer :dyn-frame dframe} to some type of record or even reified object with interfaces

herbm16:11:28

Well only people who are beginners or who like to help beginners are likely to read this channel (or who read everything :) @markx

markx16:11:58

haha well I am a beginner, so I ask it here...

markx16:11:45

What you said doesn’t really clear my confusion.

herbm16:11:49

I am a near beginner who knows a few things so like to read and try to help here 😉 @markx

markx16:11:22

Let’s say this, My question is, how to parse that file I posted, using the library buffy.

herbm16:11:32

I didn't really say anything specific or useful, just threw out some possibilities for what you might be asking which is still pretty vague

herbm16:11:20

Are the docs not useful for that? Who wrote the buffy library? Is it someone who's an identifiable member here?

herbm16:11:22

(Sounds like the guy, Daniel Higginbotham, who wrote one of the better newbie Clojure books, "Clojure for the Brave and True". He loves TV & vampire allusions etc.

markx16:11:14

Sorry I don’t know anyone in this community yet...

markx21:11:39

Hey guys, how do you convert a byte to a binary string?

markx21:11:58

like -1 should be “11111111"

markx21:11:57

Thanks. Is there a Clojure way to do it?

val_waeselynck21:11:11

@markx you can simply translate one of the examples from Java to Clojure, using loop and the bitwise operators in clojure.core. But honestly, for this kind of low-level stuff, I prefer sticking to Java.

markx21:11:13

hmm… Good to know. The thing is, I don’t know much about Java...😅

val_waeselynck21:11:25

@markx you only need to know how to copy and paste java for this purpose 🙂

val_waeselynck21:11:41

Here's a more Clojury implementation, but don't expect it to be fast!

markx21:11:01

Yeah… I’m curious, shouldn’t there be a built-in function for this?

val_waeselynck21:11:13

@markx I don't think it's that common a use case in practice

val_waeselynck21:11:51

you usually don't care what the individual bits are when passing bytes around

val_waeselynck21:11:44

it's telling that there's nothing built-in for Java either

markx21:11:06

Yeah that’s true. Using Java we can do this (Integer/toBinaryString (Byte/toUnsignedInt -1))

markx21:11:29

But I really don’t like it.

markx21:11:57

@val_waeselynck Will you happen to know clojurewerkz/buffy ?