This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-06
Channels
- # adventofcode (24)
- # aleph (1)
- # bangalore-clj (2)
- # beginners (196)
- # boot (148)
- # cider (18)
- # clara (83)
- # cljsrn (24)
- # clojure (210)
- # clojure-brasil (3)
- # clojure-china (1)
- # clojure-italy (11)
- # clojure-korea (8)
- # clojure-russia (82)
- # clojure-spec (115)
- # clojure-uk (130)
- # clojurescript (109)
- # core-async (7)
- # cryogen (1)
- # cursive (22)
- # datascript (11)
- # datomic (6)
- # devcards (2)
- # emacs (1)
- # garden (1)
- # hoplon (2)
- # incanter (1)
- # klipse (4)
- # luminus (4)
- # off-topic (89)
- # om (53)
- # onyx (78)
- # parinfer (9)
- # proton (3)
- # protorepl (20)
- # re-frame (107)
- # reagent (52)
- # rum (30)
- # spacemacs (1)
- # testing (3)
- # untangled (31)
- # vim (43)
- # yada (9)
a destructing problem in selmer. When I do paintings.tiles I see this output :
[{:x 0, :y 0, :url ""}]
how do I get the url out of it. I tried {{ % get-in paintings [0] % }}
{{ % get-in paintings 0 % }}
{{ first {{ data.paintings }} }} ` but no luck
It's hard to help without more context. Need to see what data structures are called what in your template and I've no idea what paintings.tiles
is. However, given the shape of the data (a vector containing a map with url in it) you need to get the first (0 indexed) item in the vector to get the map and then the value associated with the :url
keyword.
So something like: (get-in paintings [0 :url])
assuming paintings
has that shaped data and I don't know if it does from the information you've given.
@agile_geek , yes, I know that part. But my question is how to convert that so selmer can do it
No idea - look at selmer docs
I suspect you need to destructure the data in Clojure and then set a variable using Selmer's fn's then reference that variable in the template
I found this in the docs :
"Accessors are separated by dots like {{ foo.bar.0 }}
which gets translated into (get-in context-map [:foo :bar 0]). So you
can nest vectors and maps in your context-map.
That's extracting data from the Selmer context-map
. Is your data in the context map
So that won't work
I would extract the url from the map in clojure and pass it to the selmer template as a variable using render
do the extraction using Clojure
Anyway I've work to do so good luck
I've only used Selmer once three years ago so I wont be much help but it does have things like for
tags so if you have multiple urls that all need to render in the same way in sequence you could pass the for
tag a vector of URLs
If each image needs to go in different places they probably need unique names anyway
But if you want to render the details and images of several paintings on a page the for
tag could wrap a html and tags for a collection but then you would need to figure out how to destructure the individual details from each map
I think if you for
loop over a vector of maps where each map is your painting details you can name each map in the vector something e.g. painting
and then use dot notation to get the contents {{painting.url}}
Really do need to get back to work now 😉
I am requiring ring but when Clojure compiles I receive an error
[ring.util.http-response :refer [response]]
java.lang.IllegalAccessError: response does not exist
ring.util.http-response doesn’t define its own response
, it uses the one from ring.util.response
thanks! that’s good to know! But when I re-run it with:
[ring.util.response :refer [response]
I get:
No such namespace: response
What’s your whole ns/require block look like?
(ns guestbook.routes.home
(:require [guestbook.layout :as layout]
[guestbook.db.core :as db]
[bouncer.core :as b]
[bouncer.validators :as v]
[compojure.core :refer [defroutes GET POST]]
[ring.util.response :refer [response]]))
I thought it was, that’s probably my error
[ring/ring-core "1.5.0"]
<-- minimal dep
[ring "1.5.0"]
<-- core, util, jetty, devel
:dependencies [[bouncer "1.0.0"]
[cljs-ajax "0.5.2"]
[com.h2database/h2 "1.4.192"]
[compojure "1.5.1"]
[conman "0.6.2"]
[cprop "0.1.9"]
[luminus-immutant "0.2.2"]
[luminus-migrations "0.2.8"]
[luminus-nrepl "0.1.4"]
[markdown-clj "0.9.91"]
[metosin/ring-http-response "0.8.0"]
[mount "0.1.10"]
[org.clojure/clojure "1.8.0"]
[org.clojure/tools.cli "0.3.5"]
[org.clojure/tools.logging "0.3.1"]
[org.clojure/clojurescript "1.7.228" :scope "provided"]
[org.webjars.bower/tether "1.3.7"]
[org.webjars/bootstrap "4.0.0-alpha.5"]
[org.webjars/font-awesome "4.7.0"]
[org.webjars/jquery "3.1.1"]
[org.webjars/webjars-locator-jboss-vfs "0.1.0"]
[reagent "0.5.1"]
[ring/ring-core "1.5.0"]
[ring-middleware-format "0.7.0"]
[ring-webjars "0.1.1"]
[ring/ring-defaults "0.2.1"]
[selmer “1.10.0”]]
cool! Thank you!
But I might be wrong, because looking at the source on github, core should include the utils
Hm yeah I got the same error
I am not able to launch a repl in this project because my code won’t compile due to this requirements issue
No such namespace: response
This means you're doing response/response
something, or something like that.
I want the function that is under ring.util.response that is called response
I figured it out
I was doing
response/ok
which was thought to be a namespace just as you’ve mentionedThank you for your help!
Hey guys, is this blog about select-keys (http://blog.jayfields.com/2011/01/clojure-select-keys-select-values-and.html) out of date? Does it now return a map with keys in the order of supplied keys-vector every time? I don’t know if I can depend on that.
I don’t believe you can. As an impl detail, I believe small maps are implemented as array maps and do preserve insertion order, but that is not a contract on which you should rely.
If you need a logically ordered map, sorted-map
is there for you.
How about if I try to rewrite it with something like for k in ks … get map k … into {}
no, you’re dumping the values into a map at the end
Can you live with dumping the ordered values into a vector?
You’ll have to maintain key uniqueness yourself, of course
sorted-map
sorts the map by a comparator fn on the keys
There is no ordered-map
in clojure core of which I’m aware
> An array-map maintains the insertion order of the keys. Look up is linear, which is not a problem for small maps (say less than 10 keys). If your map is large, you should use hash-map instead. > When you assoc onto an existing array-map, the result is a new array-map with the new key as the first key. The rest of the keys are in the same order as the original. Functions such as seq and keys will respect the key order. > Note that assoc will decide to return a hash-map if the result is too big to be efficient.
Yeah, that’s also a fine idea, but the assoc
land mine is just waiting to defy your expectations 🙂
(keys (assoc (array-map :foo 10 :bar 20) :baz 30))
gives me (:foo :bar :baz)
in my repl
I think the threshold is 16 values
(type (assoc (apply array-map (range 1000)) :foo "bar"))
clojure.lang.PersistentHashMap
No, you’ll just lose the “seq is in insertion order” property
I feel like since I’m trying to build up a ordered list of k-v pairs just as an intermediate step to a final calculation, maybe a reduce is better?
Hard to say, ennit. There are certainly cases where you need to preserve an arbitrary ordering, but those cases don’t tend to be also those where you require unique values by some other key.
http://adventofcode.com/2016/day/4 this little game here
if you really need an ordered map, see https://github.com/amalloy/ordered
hi there 🙂 was wondering if I could get any guidance on setting :source-paths
in project.clj
for a cljs project
(defproject hello_world "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url ""
:license {:name "Eclipse Public License"
:url ""}
:dependencies [[org.clojure/clojure "1.8.0"]]
:source-paths ["src"
"src/hello_world"
"."])
eh?attempting to run lein run -m clojure.main repl.clj
and getting some nasty error messages... the tutorial guidance suggests it might have something to do with :source-paths
but it doesn't specify how it should be structured
abs, thank you!
goomba : putting "." in source-paths is a bad idea, because it results in your entire repo being in your jar
(if you ever make jars)
ahhh okay
was just trying various things to attempt to get it to run 😛
haha, fair enough
also in general if "foo" is in src-paths, then "foo/bar" probably shouldn't be there too (I assume that too was shotgun debugging of course)
yes indeed 😄
it's cool got it mostly running... will probably just wipe it and start a clean slate having the benefit of hindsight
and by "it" I mean my harddrive and change careers 😂
This is an import because this is on Clojurescript's quickstart guide. If we're confusing people this early into their journey, it's going to turn some people off
if they got past the parenthesis it's probably fine 😛
oh, that project was copied from an example?
towards the end of it the tutorial mentions Leiningen and gives a lein command to run
you said "we're" confusing people 😄 I heard clojurians were awesome
yeah I'm a Python guy but I've fallen for Clojure ❤️. I'm trying to backdoor it into my work with ClojureScript, hopefully using it on the backend via node.js, and then magically one day it will just be real Clojure 😄
also anything I can do to spend less time writing JavaScript T.T
@goomba then I suggest heading over to the #mentoring channel and see if anyone has bandwidth to get you started down a more productive track
very well
thank ya thank ya!
regarding the leiningen section on that page, the suggestion to run lein classpath
if you have questions is so stupid it's funny
"oh, I see, a list of 1000 files all on one line, now I understand"
hahahahahaha
anyway got to clojure conj??
ehhh I'll take it to #off-topic
@goomba Welcome! How much Clojure have you done so far? Everyone learns differently, but I personally like using a template for starting out a ClojureScript project (where I can explore for a bit without worrying about the project building at all). I'm not sure which one is best for beginners, but https://github.com/bhauman/figwheel-template is a pretty cool barebones template with automatic code reloading and https://github.com/reagent-project/reagent-template is popular if you want to use the Reagent react wrapper.
fantastic 😄 I'm very "old-school" ... If I had it my way I'd work from JVM byte-code out (I suppose can say assembly for a different day) but there's only so much time in the universe! It's obviously a ton of value to see some projects put together with best practices
@goomba if you really want to see byte code / assembler, no.disassemble with jvm clojure is pretty awesome
reallllly 😄
you hand it a function, it shows you the assembly for the byte code generated
that is awesome! I'm a big fan of language design in general so I love that stuff
it even knows how to return disassmbly data as a data structure so that you can write code that works with it
whoaaa 😄
so it goes past byte code and to assembly?? wow
well "disassemble" as in get pseudo-code for the byte-code
ahhh okay
there's no direct access to the assembly for machine code
that's even better
yeah I was wondering how that worked!
@curlyfry thanks for the warm welcome 🙂
goomba: clojure contains a copy of asm.java which is a project that directly emits jvm bytecode without using javac - it's pretty neat
man... this language is so magical
It's also absolutely perfect for AI
and not that machine learning nonsense everyone calls AI I'm talking real AI 😄 😄 😛 😛
@dpsutton Will do! So much to learn
got it
bit confused about the purpose of reify
is it om specific?
okay. I'm not totally comprehending the doc string or examples... it seems like the purpose has something to do with working with objects?
I'm good with contrived examples 😄
indeed
so in the Om example you posted in the other channel it is returning a "reified" instance of IRender with a modified implementation of render
also, in my example above I'm calling toString on a reified instance of an object with a modified implementation of toString. my version returns "Oh Hai!" so that is what gets returned
ahhhh I see
so the [_] is pointing to the "this" of the object and you denote it as an underscore because it is unimportant
okay, I understand now. there is a similar function in Python... just needed to connect the dots, thank you
so the second argument of reify is instructions for how you want to perform the "reification"?
interesting... just trying to draw comparisons, I assume reify is primarily for Java objects? In Python objects have the ability to define how they wanted to be reified... called repr
in python
do Java objects do the same? like if I call an object that has some kind of defined method for reifying itself does it need the protocol argument?
it's not just a java interop thing. you can also use it to create a one-off instance of a protocol
what's the difference? could be any kind of valid form, not just string?
so if you had
(defprotocol Cat (speak [this]) (scratch [this person]))
you do (def nice-cat (reify Cat (speak [_] "mew") (scratch [_ _] "I don't scratch, I good kitty")))
ahhhh interesting
defprotocol
is new to me (guess I'm in the right room)
except my guess is it's smarter and doesn't let you mutate state and screw your coworkers 😛
it's what they call an interface in Java? like a class with just methods and no data?
baller
gotcha 😄 thanks guys!
you may have started the parsing for number and thrown it off when you switched to 10rand
I was just messing around trying to understand destructuring I didn’t think about the variables names.