This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-21
Channels
- # announcements (2)
- # aws (1)
- # beginners (172)
- # boot (3)
- # calva (19)
- # cider (18)
- # clj-kondo (5)
- # cljsrn (18)
- # clojure (47)
- # clojure-europe (9)
- # clojure-finland (7)
- # clojure-italy (3)
- # clojure-nl (15)
- # clojure-spec (20)
- # clojure-sweden (2)
- # clojure-uk (72)
- # clojurescript (45)
- # cursive (42)
- # datomic (6)
- # duct (4)
- # emacs (4)
- # expound (48)
- # figwheel-main (7)
- # fulcro (64)
- # graphql (8)
- # hoplon (9)
- # hyperfiddle (1)
- # jackdaw (8)
- # jobs (4)
- # jobs-discuss (61)
- # klipse (5)
- # leiningen (6)
- # off-topic (72)
- # pathom (2)
- # planck (11)
- # re-frame (1)
- # reagent (3)
- # reitit (16)
- # remote-jobs (17)
- # ring-swagger (3)
- # shadow-cljs (49)
- # spacemacs (12)
- # sql (3)
- # tools-deps (124)
- # vim (64)
- # xtdb (4)
Error printing return value (ClassCastException) at clojure.core.logic.Choice/bind (logic.clj:1094).
clojure.lang.LazySeq cannot be cast to clojure.lang.IFn
map returns a lazy seq, core.logic programs are made up goals (== returns a goal, as does permuteo, etc) you cannot mix and match them like that
your map call is returning a lazy-seq of goals (because the maping function returns the goal returned from the unification)
so you need something that takes a seq of goals and returns a single goal, in this case conjunction of goals (the other option is a disjunction) which I don't entirely recall the name of
thanks @U0NCTKEV8 - makes sense.
clojure
(l/run* [out-list]
(let [lvars (repeatedly 3 l/lvar)
pairs (map vector (list nil nil 3) lvars)
important-pairs (filter (fn [[x _]] (not (nil? x))) pairs)]
(l/fresh [lvars]
(l/== out-list lvars)
(l/permuteo (list 1 2 3) out-list)
(map (fn [[x y]] (l/== x y)) important-pairs))))
anyone know why that last map
is throwing the above error?
which call to map?
in the last line
sorry, l
is clojure.core.logic
is important-pairs
lazy or something, as produced by let
?
filter is always lazy
as is map
I don't know enough about core.logic to get much further than that though, I thought it was macro based and I wouldn't expect those macros to work with lazy-seq args, but I could be totally off track here
i’m using sente, and on a successful server-update, i want to notify only the client that sent the update. but on a failed server-update, i want to notify all clients (all tabs) associated with a user.
I believe the docs, which say
>Each user-id may have zero or more connected clients at any given time
but if connected-uids
is just a set of uids, how does my app know which user-id (“alice” with several tabs, “bob” with 1), goes to which connected-uid (“uuid” “uuid” …. “uuid”)
https://github.com/ptaoussanis/sente#what-is-the-user-id-provided-to-the-serveruser-push-fn
maybe i have to track it myself? i can do that, but i naively thought “each user-id may have zero or more connected clients” meant sente had a place to but user-ids and connected clients.
when I used sente I did my own server side bookkeeping to map user ids to connected socket ids
indeed lymchat uses redis to bookkeep https://github.com/tiensonqin/lymchat/blob/f7cfac0fe9ee1ef2dfc27944a1a13717ccda7c08/api/src/api/db/channel.clj#L72-L93
I don't think sente makes any assumptions about users and ids - for all it cares every socket connected could be anonymous / unauthenticated, or every socket could be the same user
yeah - unless you know you only have one server instance running ever, you do need something that spans multiple instances (eg. your db)
thanks again. rereading those paragraphs with the thought “sente doesn’t make any assumptions about users and ids” makes it more sense.
hey folks, is there any authentication client for clojure rest api project? I am starting to build a project and i need some help. Actually my first one.
@quieterkali Are you looking for something like https://github.com/cemerick/friend ?
exactly @U04V70XH6, thank very much 😄
(or perhaps https://github.com/funcool/buddy )
I have an record implementing an specific protocol. I’d like to wrap the protocol calls to have certain behaviour before/after the protocol-function is called. How’d i go about it? I messed around with proxy; but that doesn’t seem right
Hi! I'm trying the simplest thing, launching a development environment with Figwheel-main and Clojure CLI. I'm following [the Figwheel tutorial](https://figwheel.org/docs/installation.html) to the letter, but when I launch clojure -m figwheel.main
, a browser window opens, but no repl in the terminal (although there should be one started). I don't get any error messages either... Any advice? Thanks!
which browser? I only ask cause terminal doesn't popup for me on firefox but it does on chrome
I'm using Chrome on Linux. I open a shell at the root of my project, in which I created the proper deps.edn file, then type in the starting command. The browser window opens, and it says I should be "returning to the REPL and typing", but there's no actiive repl running in the shell. Last message I have is Opening URL
. 😕
Super noob question, I see a test that has a structure that looks like (deftest ^{:some-key "Some-value"} similar-to-key ...)
What is the map all about?
it's like in the name and everything :)
Is there any way to determine whether code is being executed by a go block? I'd like to conditionally apply <!
or <!!
based on whether I'm inside a go block.
Hey Folks, can someone help me to understand difference between compojure-api and pedestal?
@rschmukler given how the go block compiler works, that's not going to work
I figured as much, but I was hoping perhaps behind the scenes it set a thread variable or something (on the executor threads)
the portable thing is to create a go block in your function and return its channel
go blocks are cheap
Yeah, the problem is that it feels like a bit of a leaky abstraction
ie. Concurrency is an implementation detail - making the caller aware of its semantics feels dirty
changing behavior when inside vs. outside a go block is a much bigger leak
It'd be encapsulated by a function though. ie. callee's responsibility, instead of caller
core.async's model can't abstract that
But I do get why it's not done. Stringing channels through all my APIs just isn't worth it though. I'll see if I can find a different way.
using go works in both contexts - you never end up blocking a thread
channels are the price of the core.async model though
Yep yep
Where are my JVM fibers 😞
I understand that it can be done that way. But it forces everything into a different paradigm - namely, using channels instead of function application
The problem is strictly semantic - not a big one, only seeing if there was a more elegant solution afforded somewhere.
Okay, I'll try and explain
if you have a channel and need a blocking or callback function, use take!
right?
I have a function which preforms a large computation and relies on an army of workers to execute it
Traditionally it is called from outside of a goblock (eg. the repl, a dedicated threadpool, whatever)
ie. the impl of do-work
takes from a channel with all the results <!!
Absolutely
I want to clarify, I know how they work, I'm just trying to showcase how they can leak
Now, I've got a new system, also implemented with go blocks, each one calling do-work
with slightly different arguments
The problem is now that these go blocks are calling a function (`do-work`) which actually blocks (instead of parking). So now I have to either create a function that returns the channel directly (not a big deal, but it forces the caller of the system to be aware of its concurrent implementation detail) or expose a variant that parks instead of blocks (again, leaking the internal implementation of what do-work
does out to the caller, that also happens to be implemented with go blocks.
My point is, but for the fact that these systems share a goblock runtime, these variants would never exist. It's not a big deal at all, but it does force an all-or-nothing type of constraint on the system. Either channels are used at system boundaries, or they aren't - it's difficult for two independent systems which happen to be implemented w/ go routines (a strict implementation detail) to coordinate with functions.
I do buy that not much better can be done until fibers come to the JVM though
Yeah, this is definitely better than call backs
Yep. Systems are hard 😛
True, but it's also a consequence of this specific implementation of do-work-servers
. ie. Runtimes with actual support (again, not Clojure's fault, Project Loom for the JVM is coming) enable you to put the machines back behind the function boundary (either via a preemptive scheduler ala erlang) or full run-time level support (golang) where all functions end up "parking".
i still wouldn't put the focus on the execution machinery -- the essential thing here is conveyance
Yes, they are a fantastic coordination mechanism
But, without the runtime handling parking, they leak. Ie. golang doesn't have <!
and <!!
because the runtime handles it for you
I won't even say leak, as it comes off too harshly - they just can't be mixed well with functions
which is my point, a lot of people start with a function calling and returning kind of design, and want to sprinkle in little bits of core.async and it is annoying because it isn't transparent
which is kind of a dissonance, but if you approach core.async systems as more machines to start with, you get a model of calling (create-do-work-server) once at start up, and doing client/server style request response stuff
Absolutely - and erlang / Exlixir have that paradigm pretty strongly. But, because there is a preemptive scheduler, you can put the semantics of request / response back under functions.
Functions have a lot of advantages, at the highest level. They are highly composable, can be partially applied, can represent lazy execution (thunks), have great tooling for exploring their results, have great tooling for jumping to where they do, etc. Channels could have tooling at that level
Anyway, I appreciate everyone engaging. I'll return the channel and deal 😛
What's the issue with this? trying to follow the conversation here
Nevermind, looks like it is all in this talk linked below
orchestration via channels can avoid that. There's a good talk from Rich Hickey that deals with this
Absolutely. I did Haskell for about a year professionally and it's the king of creating compositional coupling
@ghadi Are you referring to "The Language of the System"?
I haven't seen that one. I'll give it a go
Wonderful, thank you!
What http-server do you guys recommend? I have a really hard time deciding which one to go with. Clojure JVM.
Can someone point me in a direction on what I should think of when deciding between e.g Jetty, Http-kit, Aleph, Immutant..?
Also having a look at clojure-nginx
Performance, features, stability, project longevity are all important factors to consider. Personally, when all else is equal, I’ll reach for jetty as it’s popular and performant.
Start with the embedded Jetty, and if it doesn't satisfy your needs, try something else.
At work, we use Jetty in production for most everything.
(we used http-kit for a while but the integration with New Relic is lacking)
Thanks for the answer, since I have some experience with Jetty i'll use it for my production app. Previously I had a toy-project using Sente (for websockets) and immutant. 🙂
@U04V70XH6 are you using websockets together with jetty, and if so- which library? Or did you build one yourselves?
@UBN9SNVB4 One of my coworkers wrote this. https://github.com/RutledgePaulV/websocket-layer pretty lightweight, but we’ve used it in a few projects!
@UBN9SNVB4 We're not using WebSockets with Jetty. We're using Netty and http://Socket.IO in one app that is not Jetty-based tho'.
I really like https://github.com/nginx-clojure/nginx-clojure for 'including' Clojure to Nginx, but it has little recent activity.
While reading Programming Clojure, 3rd ed. I realized in page 70 that you can use clj command line tool as a substitute to my standard file tools find & grep. E.g. in code examples directory start clj and then:
`
(import java.io.File)
(def my-file (File. "."))
(def my-files (file-seq my-file))
(def my-file-names (map #(.getName %) my-files))
(require '[clojure.string :as clj-str])
(filter #(clj-str/includes? % "clojure") my-file-names)
; => ("clojure.js" "clojure-deps.xml")
Yihaa! 🙂
Of course that's a lot more writing than:
find . | grep clojure
... but using clj you have all the power of Clojure to manipulate the files further.
I wonder if clojurians are really using clj like that (as a command line tool to manipulate files).
I think you would be interested in the Clojure/north talk related to this
I think someone has made some sort of bash script analogue for Clojure
I haven’t used it, but there is also https://github.com/dundalek/closh
I agree though, it's awesome!
Interesting, thanks for sharing! 🙂
specifically they were talking about lumo which is a CLI environment that executes ClojureScript
In what context do you see that?
I've seen code like that in Alex's book when the rest of the code is unimportant for the example, for instance
in this case, I don't think that's it
some people call that the Fogus comma to mark where the values are threaded in examples
http://blog.fogus.me/2009/09/04/understanding-the-clojure-macro/
I'm trying to get started with clojurescript, so far unsuccessfully. Is there a good "how to" guide that someone could point me to? FWIW i'm on linux ubuntu 16.04 .
Having trouble getting CLJS installed?
To tell the truth I'm not sure. Is that what I'm supposed to install to compile a clojurescript file?
I have clj but not cljs
Have you seen https://clojurescript.org/guides/quick-start ?
yes, and I was able to get a repl going. But what I was hoping to do is just to compile a file to javascript/html and load the results in the browser.
Can that be done?
Yup. The guide that mike showed will be able to do that. Here is another guide as well: https://betweentwoparens.com/deoploy-clojurescript-to-github-pages
And if your interested in more examples of small web site projects to use as examples: https://github.com/tkjone/clojurescript-30
Thank you. Those pages look pretty helpful. I'll take a look .
You asked if I was having trouble getting CLJS installed. What is CLJS . I looked over the examples you showed me and they all seem to be using clj ( not cljs ) on the command line.
What is CLJS ? ( this time as a question ) 🙂
It's a programming language and a Clojure program that reads this language and spits out JavaScript 🙂 That's why you use clj
and give it the path to the program ClojureScript and to your ClojureScript source files.
@UJSU0AR9U The idea is this:
ClojureScript
is a library that is run by Clojure
. This is why you have to specify it as a dependency in the deps.edn
file.
So when you run clj -m cljs.main ...
you are telling clojure
to run the ClojureScript
library. Then, whatever you feed cljs.main
(e.g. a .cljs
file) will be passed into the ClojureScript
library and the compiled result, javascript, will be returned to you.
got it ( i think ). That's very helpful and informative.
So, installing CLJS is just adding it to your deps.edn
file and then running clj -m cljs.main ...
. It will download it for you the first time you run it.
I'll take some time to go through https://betweentwoparens.com/deoploy-clojurescript-to-github-pages . That looks like what I was looking for.
With luck that will be enough to get me going. If not, I may be back with more questions later. Thanks again!
Or perhaps someone could just tell me how to get started.