This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-10
Channels
- # beginners (151)
- # cider (41)
- # cljdoc (7)
- # cljs-dev (6)
- # clojure (92)
- # clojure-dev (5)
- # clojure-italy (26)
- # clojure-losangeles (1)
- # clojure-nl (10)
- # clojure-russia (3)
- # clojure-spec (23)
- # clojure-uk (82)
- # clojurescript (56)
- # clojutre (1)
- # core-async (3)
- # cursive (15)
- # datomic (26)
- # editors (3)
- # emacs (3)
- # events (2)
- # figwheel-main (192)
- # fulcro (66)
- # leiningen (12)
- # mount (1)
- # off-topic (131)
- # portkey (6)
- # re-frame (38)
- # reagent (10)
- # reitit (7)
- # ring-swagger (55)
- # shadow-cljs (21)
- # spacemacs (11)
- # tools-deps (48)
yep. since moving to deps.edn / clojure cli tools, all of my projects have a .dir-locals.el that tells CIDER to add a -A:dev
to the command
@lilactown I have (setq cider-clojure-cli-global-options "-A:dev")
in my .dir-locals.el
is that what is needed?
this is what my .dir-locals.el looks like:
((clojure-mode
(cider-clojure-cli-global-options . "-A:dev")))
Yeah, found it after some time 🙂
the emacs manual can sometimes be terse 😛
you’ll want to make sure you run M-x reload-dir-locals-for-current-buffer
as well after changing them
does not work
@mishraantash34 No namespace declaration?
Are Clojure Agents also called Agents (not talking about AI thing) in academia, or CS world. Found this article http://wiki.c2.com/?ActorVsAgent and am trying to understand what is written there, and under their definition of agent → communicate to an agent by modifying something that it is observing; you do not need to know that the agent exists What does this even mean, do not need to know that the agent exists? Are we talking about the same thing?
@mishraantash34 works fine here
"In computer science, a software agent is a computer program that acts for a user or other program in a relationship of agency, which derives from the Latin agere (to do): an agreement to act on one's behalf."
"Agents provide independent, asynchronous change of individual locations." So, they provide access on the behalf of others."
no its a software architecture definition I believe
So Clojure Agents is just a way to illustrate this concept, not the absolute truth how agents should look like, right?
well it's an implementation, yeah
the only 'absolute truth' definition is what I posted above
It's like a isolated robot that you send to do a task and then it comes back. I guess that's the 'archetype' of it
i mean, if you think of actors, it's more or less always the same, right? You can not go wrong with it
when it comes to agents, that's the only thing I know (Clojure agents) Reading about https://msdn.microsoft.com/en-us/library/dd492627.aspx Microsoft Agents Lib. To understand how they do it and how it's different
I think not having to know the agent exists is because you can implement watchers on values and they trigger
Rich Hickey begs his audience not to call them actors in this talk, so maybe not. 🙂 https://www.youtube.com/watch?v=nDAfZK8m5_8&t=1h12m03
I think they're used for the same purpose, is that what you mean?
On the clojure website they even say what's the different and the problems with actors
An agent is some data you can throw functions at and you don’t want to have the result synchronously. An atom is some data you can throw functions at and you want to have the result synchronously. Atoms are far more prevalent in Clojure code than agents.
@borkdude http://wiki.c2.com/?ActorVsAgent read this link for more info
An 'Agent', as from ConcurrentConstraintProgramming or ReactiveDemandProgramming, is different: * active continuously - making observations on an environment, constraint store, or perhaps other agents * presence of agent may also affect the system, i.e. applying a rule or demand; nature of effect distinguishes Agent systems * communicate to an agent by modifying something that it is observing; you do not need to know that the agent exists * upon observing certain conditions, in some systems agents might spawn new agents or update local state * the information that agents need to perform their jobs is continuously maintained by their runtime environment * agents tend to process all relevant information at once, and thus need consider only combinations * it takes some discipline to prevent 'feedback' systems, similar to placing a microphone near a speaker
So the question was whether or not this applies to Clojure agents, are they representing the same thing/concept or not
This is not an agent vs actor talk. It's about this agent definition vs Clojure agent definition if you wish.
E.g. here MS calls this agent library, but agent is used as an actor https://msdn.microsoft.com/en-us/library/dd492627.aspx So what it an agent in the absolute meaning of it. Not applied to any language or framework
there are like 3 definitions depending on the context
simulation, a model of something, and asynchronous entities that you 'send out to do stuff'
I don't think anyone knows for sure
Actors live in a house and they send and receive all info via the mailbox at their front door. Agents can go to PO boxes and check the memory stores of the shared world.
so basically agents have a mission (in their head), actors have a script (from the director) 🙂
The fact that updates to the container participate in the "unified update model" of the entire clojure world gives it a lot of leverage
But, technically, you could leave that container nilled out all the time and just send functions to the agent like it's a thread to run things off the main thread.
And agents are backed by a thread pool, so you can fan work out to them just like a java thread pool, without touching their "local" containers at all.
Threads with their own coordinated memory, where coordinated means updates consistently with the rest of the clojure state model
Is agents implementation the only one for this "concurrency model"? Meaning are there other programming languages, that are using agents?
I think it's a more amorphous term outside of clojure. I'm not aware of many other languages giving a first class implementation like clojure
and most other context I'm familiar with the term is from the AI world, MAS and what not
But, one could argue, most threading models that act a little like java, is a little agent-ish
This is why this article confused me a little: http://wiki.c2.com/?ActorVsAgent
The terms in that piece refer to theoretical abstractions from the early days of Comp Sci. Hewitt's Actors paper is from the 1970s. The term "Agent" has been variously defined by lots of folks since at least the 1960s. Unfortunately that history, while fascinating, is a red herring when it comes to puzzling out what modern code is doing, or how current authors have made decisions about division of responsibility and so forth in their frameworks.
So I kinda backed myself into a corner here. The first format is used while the user fills out the form where as the second format is used to validate the data and submit. Unfortunately this is making it difficult to load the form back after submission and clearly I should only be using one format but I’m not sure which one to pick. What questions should I be asking?
That’s true, it wouldn’t be difficult to change between the two. Perhaps the trick is converting the validation format back to the storage format after validation succeeds so it’s always stored\fetched the same way?
I'm a little confused by different terms here. But i would figure out what you want your data to look like in your form and then translate it into what the storage needs at the last moment after its been validated
you said "backed into a corner". not sure how far into the corner you are or if it would be easy to refactor. but i bet it would pay off
What is confusing about the terms? I know I’m not always great at communicating. Second, the form and storage both operate with that first format. After discussing this situation it appears I’m less into a corner and more just stubbed my toe 😛
I think the issue is that it’s mostly the first format, the storage format -> validation format -> validate -> submit where it should be storage format -> validation format -> validate -> back to storage format -> submit
maybe this is a better question for #cider, but how do y’all deal with a go-loop
(or similar) running of the rails when running a repl in cider?
in all seriousness, you can't kill go machinery from the outside, you pretty much need to restart your vm
(which is a good reason to make sure you write go-loops so they accept a termination message of course)
If you are just playing around, you could always add an alts
inside the go-loop that tries to read from a “poison”/“kill”/“termination” channel. Or even an atom you’ve defined (if only playing in the REPL)
yeah i wondered if there was maybe some mitigating thing i could do outside of kill
since this almost always happens when i’m being sloppy playing around lol
yeah, sadly the go machinery is not really open enough for that
@UCDG904RW keep a reference around to the channel where your loop is reading from. when the channel is closed (you know by reading a nil), then terminate the go-loop. this way you can quit the go-loop from outside.
@U0E2EQFME Do you have an example of that termination atom or channel?
Example from https://www.reddit.com/r/Clojure/comments/2ka3na/how_do_you_organize_your_coreasync_code/:
(defn make-printer-component [input-ch]
(println "[printer-component] starting")
(let [poison-ch (chan)]
(go-loop []
(let [[v ch] (alts! [poison-ch input-ch])]
(if (= ch poison-ch)
(println "[printer-component] stopping")
(do
(println (<! input-ch))
(recur)))))
(fn stop! []
(put! poison-ch :stop))))
Though that code embeds the poison channel and returns a function that can be called to put a value onto the channel. You could pass the poison channel as another argument to the function and then place a value onto the poison-ch yourself.the core thing is to always check a channel read/write for a nil, and not recur if you get a nil. If you close a chan that a go-loop uses and it doesn't check for nil it will often go into a hot loop consuming nils (unless this makes it blow up in someother way of course)
;; for dev sakes
(def quit? (atom false))
(a/go-loop []
(println "hello")
(a/<! (a/timeout 10000))
(if @quit?
(println "quit!")
(recur)))
(comment
(reset! quit? true)
)
I’m trying to sort-by
alphabetically, but with an exceptional case. so I’m using sort-by
with my own comparator
:
(defn special-comparator
[e1 e2]
(if (and (= "speciala" e1) (= "specialz" e2)) -1
(compare e1 e2)))
(sort-by identity special-comparator ["s" "speciala" "specialz" "z"])
current result: ("s" "speciala" "specialz" "z")
desired result: specialz should be before speciala: ("s" "specialz" "speciala" "z")
oh hm. having stepped through it, i see there’s no comparison of speciala
with specialz
. hm.
yeah, a sort assume's it's commutative - that comparator breaks that rule
does it? I think you can assume the order... because you can sort-by > and <, which are not commutative
use comparator
to make a legit comparator https://clojuredocs.org/clojure.core/comparator
sorry, @john, this for me doesn’t work:
(defn special-comparator
[e1 e2]
(if (and (= "speciala" e1) (= "specialz" e2)) false
(compare e1 e2)))
at repl: (sort-by identity special-comparator ["s" "speciala" "specialz" "z"])
result: ("s" "speciala" "specialz" "z")
thanks @alexmiller
and yes-- instead of the term “commutative” the clojure guide mentioned “totally-ordered set”--i think that’s the set of properties we were talking about.
i think what’s going on is, the assumption that the input is totally-ordered, means that you can do fewer comparison operations. so speciala
is never getting compared with specialz
. i could be wrong…
yeah, I don't think commutative was the right term, totally-ordered is the one
and yeah, it's not doing an O(n^2) sort that compares every item to every other item, we can assume that
What is your desired total order? Do you want "speciala" to be the minimum possible value among all possible, and "specialz" to be maximum among all possible, and all other pairs to be compared normally via compare?
@andy.fingerhut: speciala and specialz sorted normally among all elements except specialz comes before speciala
i think you could solve it if you added the reflexive case. make sure your function returns compare Special-Z Special-A = -1 and compare Special-A Sepcial-Z = 1
@mfm but where should specialm be relative to those two, if all three appear in the input to be sorted?
totally fair point, but in my desired case, there is only ever speciala and specialz. : |.
In the default clojure.core/compare function given strings, there are an unlimited number of strings after "speciala" but before "specialz"
Do you mean that the only values you will be sorting are the strings "speciala" and "specialz". There are no other string values you want to sort relative to those?
I understand each of the words of that rule, but that rule is not enough to specify a total order.
should "specialz" come before or after "speiak" ?
Sorry I meant "speciak" there.
(compare "speciak" "special") is -1, so "speciak" before "special". Same for the pair "speciak" and "speciala"
Then there is where "specialzoo" goes relative to the rest. Probably where it was originally by what compare returns?
If yes, then it sounds like you want a custom comparator that could be described as: "When comparing any string except "speciala" to "specialz", compare it to "speciala" instead. When comparing "special" to "specialz", treat "specialz" as earlier."
the current implementation problem is i can’t guarantee that special will be compared to specialz
You don't need to do that, if your custom compare function always gives the correct answer given an arbitrary pair of strings.
The trick is defining what that correct answer is for an arbitrary pair of strings.
the rule for "specialz" needs to fire when comparing with "specialy" also, because the sort could easily compare "speciala" to "specialy", then "specialy" to "specialz" and with a total order, it doesn't need to compare z and a
and the algorithm takes that for granted for efficiency
Let me hack up a proposed comparator fn in a couple of mins...
a proposal. strip the special-a and z out of the seq, sort it, and then adjoin them at the end as you like
thank you andy, noisesmith, enforser, alexmiller, john, dpsutton for all your help so far! i rigged up what i wanted as an ugly filter with a bunch of predicates. so no obligation @andy.fingerhut to make a comparator fn.
There may be something shorter, but I don't know how to make it much clearer yet:
`(defn my-custom-comparator [a b] (cond (= a b) 0 (= a "specialz") (if (= b "speciala") -1 ;; "specialz" is in same place as "speciala" ;; relative to any other string. (compare "speciala" b)) (= b "specialz") (if (= a "speciala") 1 (compare a "speciala")) :else ;; else neither of them are "specialz". Compare normally. (compare a b))) `
If I leave that (= a b)
case out, then I think the middle cases need checks to see if you are comparing "specialz" to itself.
A general rule: using a comparator function for sorting, it can be given an arbitrary pair of values from your input collection, not only the ones that are next to each other in the sorted output sequence. You need to think "If I was given an arbitrary pair of values, and had to answer which one should be earlier and which one later, how would I do that?" You can't use the sorted sequence in the answer to that. 🙂
Well, I guess there are special cases where you are only sorting a finite set of values, and then you can use the complete list of items in the order you want to specify the compare result. But it doesn't work when there are an unlimited number of possible values to compare.
On the subject of names, is it better to lean towards what a thing is, or how your going to use it?
children vs children-to-feed
I would say it's better to use a name saying what something is -- since how you use it may change over time.