Fork me on GitHub
#clojure
<
2015-11-19
>
andrewboltachev02:11:38

Hi. Are there any workarounds for the fact that strings don't have metadata?

eraserhd02:11:00

@andrewboltachev: There’s no general workaround. It’s pretty much find another way to do what you are trying to do. What are you trying to do?

mikera02:11:48

@andrewboltachev: various objects don't have metadata (Strings, numbers, booleans, arbitrary Java objects etc.). So you should never assume you can attach metadata to an arbitrary value. If you really need metadata, you can wrap any of the above types in a defrecord. But most likely you should think of a different way to solve the problem.

andrewboltachev02:11:54

@eraserhd: well, I'm reading a file and wanna keep line numbers for it's lines, in case I would need to report errors

eraserhd03:11:33

@andrewboltachev The clojure reader just skips these, I think. For error reporting, symbols are the big win.

andrewboltachev03:11:15

ok, thanks for answering!

andrewboltachev03:11:36

I'm thinking to make it like {:line-no 10 :value "foo"}

roelof07:11:58

this is maybe a beginners question but how can does the print not work here : http://lpaste.net/145556

theophilusx08:11:01

@eraserhd Maybe the as-> threading macro could provide that extra bit you need to manipulate the return/result in calls to the next function?

jethroksy10:11:59

@roelof you'll want to use pr-str to print the contents of a vector.

jethroksy10:11:29

@roelof sorry scratch that I didn't realize println worked on vectors too haha. You have an extra parens around final-body-parts that breaks your code

ian11:11:59

@jethroksy: I believe all pr* functions (`prn`, pr-str, println, print) all call pr, for future reference.

jethroksy11:11:22

@ian thanks for the headsup!

roelof14:11:25

Is there also a channel where nightcode questions can be asked ?

jaen14:11:23

Quick question - people use Schema for validation and coercion of data from, say, JSON to Clojure datastructures, turning data strings into joda time's data objects and so on. Did anyone try reverse?

jaen14:11:08

By that I mean having a well formed, schema-matching data structure in Clojure and serialise it according to the schema, turning date objects into a desired string representation and so on?

jaen14:11:11

I tried that once but couldn't get it work since coercion happens before validation and that blew up for me. Maybe there is a way to do it?

bfaber14:11:30

@jaen I think @favila was tackling almost that exact case ... Let me poke him

timgluz15:11:38

@jaen, i’m doing something similar with schema-tools - https://github.com/metosin/schema-tools , but i vent had any need for custom coercers yet - https://github.com/metosin/schema-tools

juhoteperi15:11:20

@jaen: Do you have any reasons to use anything but RFC-3339 datetime format on JSON?

jaen15:11:43

@juhoteperi: doing university project that has to interact with an API which is deliberately weird. One such weirdness is that datetimes are represented in miliseconds since unix epoch in UTC+2.

jaen15:11:10

So I can't just expect (str (time/now)) to work.

juhoteperi15:11:25

Okay. Well, one option is to use Cheshire option to set the date format.

jaen15:11:18

Hmm, right, I could do that when registering joda's objects with it. Though that implicitly assumes the date formats will be uniform. What if they won't be? Besides, I already have to coerce string enums like "BROKEN" into keywords like :broken so I figured I might as well do both of those with coercions.

jaen15:11:15

@timgluz: looks interesting, let me take a look if I can understand how to use that from examples.

timgluz15:11:08

(st/select-schema your-data DataSchema) part

jaen15:11:36

@timgluz: Hmm, I don't think it does exactly what I want. What I wanted is something like this

(let [schema {:date DateTime}
      value {:date (time/now)}
      coercion-matcher {DateTime (fn [date-time]
                                   (let [unix-timestamp (time-coerce/to-long date-time)]
                                     (* unix-timestamp DATE-TIME-CONVERSION-FACTOR)))}]
  (some-magic-function value schema coercion-matcher))
to produce
{:date 1447887600000}

jaen15:11:56

And select-schema errors out.

jaen15:11:09

I just want to use schema to guide conversion, but validate before conversion.

jaen15:11:56

Essentially the reverse of how schema/coercer works.

jaen16:11:42

Funny thing

jaen16:11:00

I actually did exactly what I tried once, but didn't work and it just worked.

jaen16:11:36

And I was pretty sure I tried that before and it didn't work, heh.

lvh19:11:35

tcrawley: Hey! Mind if I direct-message you re: Clojars sponsorship?

tcrawley19:11:58

lvh: sure thing

tcrawley19:11:09

meaning, I don't mind :)

meow22:11:19

I need to be able to create XML files, specifically X3D format. Should be fairly easy. Any suggestions on a good library for this kind of thing? I was thinking something that generated XML as nicely as hiccup-style syntax is used to create HTML.

meow22:11:24

I don't need to be able to read an X3D file in, and I've got code for creating the content of the file, I just need something simple and easy for handling the XML specific bits and pieces.

eagleflo22:11:00

clojure.data.xml?

meow22:11:10

@eagleflo: yeah, looking at that now

meow23:11:07

Euler on LSD