Fork me on GitHub
#specter
<
2016-07-19
>
arvind17:07:00

I cloned the specter repo from github

arvind17:07:08

and ran "lein repl"

arvind17:07:39

I downloaded a lot stuff

arvind17:07:39

Can anyone explain what is happening? I am new to Clojure and Java.

arvind17:07:51

Does specter have so many dependecies?

nathanmarz18:07:23

@arvind: those are all build/test dependencies

nathanmarz18:07:48

except for riddley, which is actually used by specter's implementation

nathanmarz18:07:08

and riddley has no dependencies of its own

nathanmarz18:07:24

so basically specter is very lean with respect to dependencies

arvind18:07:10

another question

arvind18:07:32

When I run "lein repl" inside the specter directory and type (require 'com.repl.specter)

arvind18:07:55

It says the file was not found on classpath

arvind18:07:14

but running "lein classpath" shows that the src directory is in the classpath.

arvind18:07:51

I want to require 'com.repl.specter to play with the transform and select macros

Chris O’Donnell18:07:30

@arvind: try (require '[com.rpl.specter]). Also, the select and transform macros are in com.rpl.specter.macros.

Chris O’Donnell18:07:51

actually, it should work not in a list

Chris O’Donnell18:07:26

oh, you added an extra e

Chris O’Donnell18:07:36

com.rpl.specter, not com.repl.specter

arvind18:07:45

@codonnell: Please refer below:

arvind18:07:48

user=> (require 'com.rpl.specter) FileNotFoundException Could not locate com/rpl/specter__init.class or com/rpl/specter.clj on classpath. clojure.lang.RT.load (RT.java:449)

arvind18:07:12

Also when I run (all-ns) in the repl I don't see com.rpl.specter in the list of namespaces

Chris O’Donnell18:07:29

@arvind: if you've cloned specter off github, you need to run lein cljx to compile the classes.

arvind18:07:58

@codonnell: I just ran lein cljx

arvind18:07:12

and then lein repl

arvind18:07:41

and (require 'com.rpl.specter.macros) returned nil

arvind18:07:11

and I tried (transform) that gave the following error: CompilerException java.lang.RuntimeException: Unable to resolve symbol: transform in this context, compiling:(/tmp/form-init2526821032412369112.clj:1:1)

Chris O’Donnell18:07:04

If you just do (require 'com.rpl.specter.macros), then transform is named com.rpl.specter.macros.transform

Chris O’Donnell18:07:22

If you want to just type transform, you need to do (require '[com.rpl.specter.macros :refer [transform]])

arvind18:07:12

Yeah that worked. Thanks.

Chris O’Donnell18:07:32

If you're new to clojure, that's a great book to work through.

arvind19:07:26

@codonnell: I bought that book recently. Have to read through it.

hueyp19:07:48

this might be a question of me not understanding spectre … but say I’ve got a nested map that I want to transform multiple times … is it possible to save the lookup? e.g. write a generic path, but for this exact instance of the map, its a very narrow this key, the next key, run the transform, etc?

Chris O’Donnell19:07:41

@hueyp: could you give an example of what you mean?

hueyp19:07:59

sure … {:foo {:a 1 :b 2 :c 3} :bar {:x 1 :y 2 :z 3} … something like … ALL LAST ALL LAST even? (I might have that syntax wrong …) … it would transform [:foo :b] and [:bar :y] … like if I want to double those, or subtract 1, etc … that paths are the same, so I’d like to kind of save that knowledge

hueyp19:07:10

again … might be not something that actually matters re how spectre works 🙂

Chris O’Donnell19:07:31

Sure. If you know the whole path in advance (no parameters), you could save it with (def my-map-path (comp-paths MAP-VALS MAP-VALS even?))

Chris O’Donnell19:07:53

(`MAP-VALS` is the same as [ALL LAST], but more efficient

hueyp19:07:08

that would still require a full traversal of the map though to determine what matches?

hueyp19:07:23

basically I’d like to do that traversal one, and save more specific paths?

Chris O’Donnell19:07:13

it would do a traversal each time, that's right

hueyp19:07:14

this is more of a curiosity … the cost of traversing the maps I have is small … just curious if I could say turn (comp-paths MAP-VALS MAP-VALS even?) + an exact instance of a map into a more specific path

hueyp19:07:46

and then re-use that with multiple transforms

hueyp19:07:55

all on the same starting map 😜

Chris O’Donnell19:07:18

@hueyp: you could use traverse from 0.12.0, which returns an instance of IReduceable (or something like that; basically it's only useful when being called with reduce or into)

Chris O’Donnell19:07:52

that will only do the traversal once, and you could call reduce on it multiple times over the same initial structure

hueyp19:07:37

@codonnell: interesting, I’ll take a look, thanks~

hueyp19:07:31

oh wow, wiki!

nathanmarz19:07:12

@hueyp: I think you might be looking for a locate feature https://github.com/nathanmarz/specter/issues/49

hueyp19:07:27

wow, yup!