This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-04
Channels
- # architecture (13)
- # bangalore-clj (1)
- # beginners (174)
- # boot (25)
- # cider (65)
- # cljs-dev (10)
- # cljsjs (4)
- # cljsrn (3)
- # clojure (169)
- # clojure-berlin (27)
- # clojure-brasil (32)
- # clojure-greece (3)
- # clojure-russia (31)
- # clojure-sg (4)
- # clojure-spec (6)
- # clojure-uk (74)
- # clojurescript (186)
- # code-reviews (5)
- # css (12)
- # cursive (17)
- # datascript (1)
- # datomic (45)
- # dirac (33)
- # funcool (42)
- # hoplon (25)
- # jobs (6)
- # jobs-discuss (114)
- # lambdaisland (6)
- # leiningen (1)
- # luminus (24)
- # off-topic (86)
- # om (13)
- # om-next (14)
- # onyx (75)
- # perun (2)
- # protorepl (19)
- # re-frame (2)
- # reagent (17)
- # ring-swagger (2)
- # rum (1)
- # slack-help (2)
- # specter (31)
- # test-check (5)
- # timbre (1)
- # untangled (34)
- # vim (8)
I feel like this is solved already but I can’t find anything about it: I want to match a certain sequence of keys coming off of a channel, and drop keys that did not conform to that sequence
What do you mean by “sequence of keys”?
(a channel just produces values)
Do you mean a set of predicates or a strictly monotonic sequence of predicates? (for accepting the values)
(and what if a value you receive from the channel matches multiple predicates in order?)
If i had a channel that produced random alphabet characters, is there a way I could describe a sequence, say ‘ACDC’ , to match upon?
In case you hadn’t guessed, I’m trying to show how application-specific your need seems to be...
How you write this depends on the exact rules you have in mind for accepting and dropping values, and how you determine you’ve reached the end state. Essentially you have a FSA (Finite State Automaton) and the rules are going to be entirely application-specific.
(sorry that probably wasn’t the answer you were looking for — I think it’s an interesting problem by the way!)
No problem. I just thought it might have been solved and I could learn from someones solution
what is the argument for running leinigen in verbose mode ?
Do anyone have emacs setup recommendation for Clojure?
@abhishekamralkar depend on your operation system..
I am on Fedora 25
@abhishekamralkar I like Spacemacs' clojure layer. http://spacemacs.org/layers/LAYERS.html http://spacemacs.org/layers/+lang/clojure/README.html
One of these days, I need to make a blog post about Spacemacs. It's a very radical reconfiguration of emacs that brings the good parts of emacs and vi together but also adds some nice ideas of its own.
Somebody, have experience with Redis (carmine) and compile to java with uberjar? (maybe that is Carmine bug, but I would like to know 100%..)
Is there something wrong with my repl in cursive :
(defn set-intersection
"Write a function which returns the intersection of two sets.
The intersection is the sub-set of items that each set has in common.\n"
[s1 s2]
(reduce (fn[item, acc] (if (contains? s2 item) (conj item acc))) {} s1 ))
CompilerException java.lang.RuntimeException: Unable to resolve symbol: defn in this context, compiling:(C:\Users\rwobb\AppData\Local\Temp\form-init5325766479843326056.clj:1:1)
@roelof have you loaded the namespace ?
@val_waeselynck yep, see here :
Starting nREPL server...
"C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3\jre\jre\bin\java" -Dfile.encoding=Cp1252 -XX:-OmitStackTraceInFastThrow -Dclojure.compile.path=C:\Users\rwobb\Desktop\clojure\forclojure\target\classes -Dforclojure.version=0.1.0-SNAPSHOT -Dclojure.debug=false -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3\bin" -classpath "C:\Users\rwobb\Desktop\clojure\forclojure\test;C:\Users\rwobb\Desktop\clojure\forclojure\src;C:\Users\rwobb\Desktop\clojure\forclojure\dev-resources;C:\Users\rwobb\Desktop\clojure\forclojure\resources;C:\Users\rwobb\Desktop\clojure\forclojure\target\classes;C:\Users\rwobb\.m2\repository\org\clojure\clojure\1.8.0\clojure-1.8.0.jar;C:\Users\rwobb\.m2\repository\org\clojure\tools.nrepl\0.2.12\tools.nrepl-0.2.12.jar;C:\Users\rwobb\.m2\repository\clojure-complete\clojure-complete\0.2.4\clojure-complete-0.2.4.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain clojure.main -i C:\Users\rwobb\AppData\Local\Temp\form-init1675104803961926111.clj
Connecting to local nREPL server...
Clojure 1.8.0
nREPL server started on port 63683 on host 127.0.0.1 -
(in-ns 'forclojure.easy3)
=> #object[clojure.lang.Namespace 0x15414a1 "forclojure.easy3"]
(defn set-intersection
"Write a function which returns the intersection of two sets.
The intersection is the sub-set of items that each set has in common.\n"
[s1 s2]
(reduce (fn[item, acc] (if (contains? s2 item) (conj item acc))) {} s1 ))
CompilerException java.lang.RuntimeException: Unable to resolve symbol: defn in this context, compiling:(C:/Users/rwobb/Desktop/clojure/forclojure/src/forclojure/easy3.clj:59:1)
@roelof try adding (require 'forclojure.easy3)
before the in-ns
it becoming more wierd:
CompilerException java.lang.RuntimeException: Unable to resolve symbol: require in this context, compiling:(C:\Users\rwobb\AppData\Local\Temp\form-init1675104803961926111.clj:1:1)
do this from user
from the user
namespace in the REPL
(require 'forclojure.easy3)
=> nil
(in-ns 'forclojure.easy3)
=> #object[clojure.lang.Namespace 0x17806f1 "forclojure.easy3"]
(defn set-intersection
"Write a function which returns the intersection of two sets.
The intersection is the sub-set of items that each set has in common.\n"
[s1 s2]
(reduce (fn[item, acc] (if (contains? s2 item) (conj item acc))) {} s1 ))
=> #'forclojure.easy3/set-intersection
why does this returns nil :
(defn set-intersection
"Write a function which returns the intersection of two sets.
The intersection is the sub-set of items that each set has in common.\n"
[s1 s2]
(reduce (fn[item , acc] (if (contains? s2 item) (conj acc item))) [] s1 ))
`where if I try it in pieces it seems to do what I thought It would do
(contains? #{4 2 5} 2)
=> true
(conj () 2)
=> (2)
someone a tip how to make this work with 3 sets :
(defn set-intersection
"Write a function which returns the intersection of two sets.
The intersection is the sub-set of items that each set has in common.\n"
[s1 s2]
(set (reduce (fn[acc item] (if (contains? s2 item) (conj acc item))) () s1 )))
I could make another clause which checks for contains s3 but then it fails when there are no more then 2 sets
@roelof set intersection is an associative operation, so you can just use reduce
@roelof btw, this operation is already implemented in clojure.set 🙂
this is part of the core library
alright
oke, the solution could be a lot smaller when using filter and set I see from other solutions
@val_waeselynck thanks again
yeah, stuff like (into #{} (filter s1) s2)
but that'd require you to understand transducers etc.
It depends what your learning objective is. I mean, in real life, you would just use clojure.set
anyway 🙂
Hi! Anyone got any experience with the following beginner-course? https://www.udemy.com/clojure-fundamentals-for-beginners/ I'm looking for a good (video-based) beginners course in Clojure... 🙂
Not sure about the Udemy course, but I've heard really good things about https://tbaldridge.pivotshare.com/. You might also want to look at https://www.youtube.com/watch?v=9A9qsaZZefw&list=PLAC43CFB134E85266
Unrelated to video tutorials/courses, but I got Living Clojure for Christmas and am extremely happy that I did. The book covers a lot of fundamental concepts in the first half of the book that I feel I'd be a lot poorer not reading and understanding before jumping head first into actual coding
I am coming from a procedural / OOP background, so people from other FP backgrounds may feel differently, but many concepts covered are largely Clojure specific
I think, you can access to this course via http://SarafiBooksOnline.com with free 14 days trial. (I bought with 99% discount in 2016.. just check that is a same course or not)
@yogidevbear that is cool link (tbaldridge), I didn’t see before this.
@peter.d there is all Clojure course.. I don’t know what is your background and what do you would like to reach. Many options there.. video courses and books too (and really free to check everything with free registration). By the way if you are really beginner, then it could help for you: the http://purelyfunctional.tv/
I’m beginner too, so that is my experience. The best path.. follow the easiest way.. what lot of people use.. because in this case they can help for you. I didn’t do that.. and maybe that isn’t a best way 😉
@sb not quite sure what you’re asking there…?
(def users {"admin" {:username "admin"
:password (creds/hash-bcrypt "pass")
:roles #{::admin}}
"dave" {:username "dave"
:password (creds/hash-bcrypt "pass")
:roles #{::user}}})
(use three backticks to introduce a block of code)
Remember that ::user
is a qualified keyword for a specific namespace, so you’d create that use the two argument form of the keyword
function: (keyword “my.namespace” “foo”)
=> :my.namespace/foo
I would expect you to be storing a sequence of such things in MongoDB for the roles? Is it a sequence or just a single string?
(since it’s potentially more than one ‘role’)
I store this kind of infos (this is just a test now):
{:_id #object[org.bson.types.ObjectId 0xa4c1b07 "586d3e268aaed4460e2a9134"], :username "admin", :password "$2a$10$qP4TO3pAN8pxOk2ZCEkEwuzAhNmLxnNgHrzyicfD3eSHVnhfg9m1q", :roles [”admin”]}
(let [conn (mg/connect)
db (mg/get-db conn "monger-test")]
(mc/insert db "users" {:username "admin" :password (creds/hash-bcrypt "pass") :roles #{::admin}}))
Cool, so ‘roles’ is a sequence of strings and you need a set of keywords
So starting from a sequence of strings, you’ll want to map
a function over them to convert each one to a (qualified) keyword, like I showed above, and then convert the sequence to a set
.
what is the difference between different apps template with lein new
?
e.g. app
vs default one
or plugin
lein new app something
creates an application skeleton, lein new something
creates a library skeleton, lein new plugin something
creates a skeleton for a Leiningen plugin
yes, this is what I know from help
the question is what are the differences between them
what is a plugin compared to library
because I can assume what an app is
It’s exactly what the help says...
I’m not sure what you’re asking?
what exactly is plugin
?
what is it used for?
how is it different from a library?
A plugin is specific to Leiningen.
I see
thanks for clarification
for things you would specify in the :plugins
vector in your project.clj
file.
ok, I wasn't sure, now I know
An application has a -main
function so you can run it from the command line.
thank you again
Sorry, I wasn’t sure which words you needed explained...
ok, now I know everything
lein new
lets you create a skeleton based on any template. A few are built-in (`app`, default
, plugin
, template
) but most are published as libraries on Clojars: https://clojars.org/search?q=lein-template
Short answer is “you can’t” — clojurescript runs in a Javascript-ish environment, and clojure runs on the JVM, so they live in different worlds
Depending on what you want to do, though, you may find .cljc files to be useful
:thumbsup:
just fyi, I am trying to use clj-rethinkdb library i am trying to share data between cljs part of the code with clj. ie, there is some data added by the user, i want to save it in the rethink db. created async channel, but i cannot access the channel from my clojure code
Yeah, if you have data in a cljs environment, and a database in a clj environment, you’re going to have to wrap the data up in EDN or JSON or something and send it over to the clj environment
So if it’s a web browser using a cljs client, and a web server running a clj app, you’ll need to make an AJAX call or something similar.
You’d have the same thing even if it were a cljs-based browser app talking to a cljs-based NodeJS server. It’s nice both programs are written in the same language, but they’re still two separate environments, so they don’t share the data.
@manutter51 gotcha thanks!
@seancorfield hello I created the script, but not so nice..
(def users
(into {} (for [x testm]
{(x :username)
(assoc x :roles
#{(keyword "fu.handler" (x :roles))})} ))
)
I would like to use more Clojure friendly script. How possible to solve in different way?Ok, if you have time, just please help me to understand better, how to use clojure. I know that script not a best.
your reducing function would take 1 user out of testm and assoc a new key into the map
you can follow along here https://www.livecoding.tv/notanon/
(reduce (fn [results input] (let [username (:username input) password (:password input) role (keyword "fu.handler" (:roles input))] (assoc results (:username input) {:username username :password password :roles #{role}}) )) {} testm)
it took me a while to wrap my head around reduce, loop/recur when i first switched over from java
but after writing a couple functions for a real use case (instead of contrived examples like calculate fib sequence)
it's becomes clear very quickly... you're just building something up, like the results argument to the reducing function in this example
probably has a math background for the name reduce... i slept thru calculus so i probably missed that bit
Yes, a little bit hard for me the first baby steps. Very helpful the results, inputs word in the code. Now, I understand better how I need to use reduce. I could use hopefully next time.
yeah i've found that using very descriptive variable names and breaking things into separate functions makes things so much easier to read
just because you can write very very very concise code, doesnt mean you have to write it as concise as possible