This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-11
Channels
- # architecture (3)
- # beginners (41)
- # boot (7)
- # cider (16)
- # cljs-dev (8)
- # cljsrn (2)
- # clojure (214)
- # clojure-austin (4)
- # clojure-russia (52)
- # clojure-spec (8)
- # clojure-taiwan (1)
- # clojure-uk (10)
- # clojurescript (87)
- # cursive (14)
- # datascript (34)
- # datomic (11)
- # dirac (55)
- # emacs (12)
- # hoplon (44)
- # luminus (6)
- # lumo (24)
- # off-topic (1)
- # om (8)
- # onyx (7)
- # overtone (2)
- # pedestal (1)
- # protorepl (4)
- # re-frame (7)
- # reagent (1)
- # ring (4)
- # rum (2)
- # slack-help (1)
- # spacemacs (2)
- # specter (32)
- # unrepl (131)
- # untangled (14)
- # yada (3)
@devn chunk?
@tbaldridge im mucking with some ruby. i have a lot of records to write to a file and want to chunk the set of items returned from a query, and use the transit writer to write chunks of 5,000.
ah I see, the problem isn't with records, it's with the collection they are in.
From what I know of transit, I have to say no, since the structure of the file and the reader/writer don't support that.
I'm pretty sure you'd have to do it manually via multiple calls to (write ...)
@tbaldridge i guess the other thing i was wondering was if the writer kept track between different calls of write
No, and that's a debate I've had with some of the designers of transit, (I forget if it was Rich or someone else). The rationale is that each thing written should be self-contained, so that if someone wants to drop one of the messages, or it just gets tossed by some transport protocol, the caches aren't screwed up.
Since the caches work on a rolling numerical count of cached values, both the reader and writer have to be in sync.
@tbaldridge hmmm, so it sounds like if i want to chunk, I'll actually need to create a separate file for each chunk instead of reusing the writer
No you can reuse the same writer and file multiple times
You just need multiple calls to write
@tbaldridge i thought you were saying that because of the rolling numerical count of cached values, multiple calls to write on the same file would result in some sort of malformed thing that the reader wouldn't like
No that's fine, and all of this is transparent
The cache will just reset with every call to write.
So it's optimal to do something like this:
(doseq [chunk (partition-all results 500)]
(write writer chunk))
@tbaldridge i was doing something like that (though on the ruby side)
yes, and so on the other end you'll need multiple calls to read.
That's just the nature of the beast, some transit readers may stream (Clojure does I think), but others are pretty much (json->transit (read-json file))
So you have to fully read in a JSON object before you can even start to read in the transit.
(not that the format has changed in the past 2 years or so, but you never know)
@tbaldridge so, maybe i misunderstand what you mean by multiple reads
is https://en.wikipedia.org/wiki/The_Art_of_the_Metaobject_Protocol relevant in clojure, or are the two incompatible ?
@tbaldridge looks like i did find a bug after all
i call read multiple times on the file i create with ruby on the clojure side, and it works
@juanmp In OO you cannot execute arbitrary functions on arbitrary data, because some data is private and can only be modified by member functions. A class is basically a rule that says you cannot execute arbitrary functions on specific data; there is a well defined set of functions you can execute on specific data (the member functions). Inheritance allows you to extend that set so that you can execute parent functions on a child type. In clojure you can execute arbitrary functions on arbitrary data, and no data is private. You can prevent the program from executing arbitrary functions on specific data by preventing yourself from writing those invocations. Clojure doesn't assume it is smarter than you are.
anyone knows how to debug this error?
remote: java.lang.RuntimeException: No dispatch macro for: =, compiling:(core.clj:39:1)
remote: Exception in thread "main" java.lang.RuntimeException: No dispatch macro for: =, compiling:(core.clj:39:1)
it happens trying to deploy to Heroku a chestnut project
and it seems related to leiningen + environ
and maybe AOT compilation
but the errot itself seems rather obscure to me
if I don't use (env :port)
to get the port number it doesn't do it anymore, but Heroku needs that since the port is set dynamically
mm alright using (System/getenv "PORT") instead of (env :port) makes it work, would be nice to understand what is going on there though
argh ok I found it: https://github.com/weavejester/environ/issues/48
it was just this setting in project.clj messing everything up :hooks [environ.leiningen.hooks]
Guys, I need some help about my programming life. I grow up with c++ and OOP, and then I saw clojure. And falled in love with it. The problem is I can’t really embrace functional thinking I guess. I can write code but I really feel bad and dirty on my code. I need a mentor for this, anyone ?
Read lots of (Clojure) code from others. I’ve been coding professionally for 19+, mostly OO but also several adventures in Clojure-land, and it blows my mind every time how sophisticated many of the Clojure libraries are (and how I probably wouldn’t have been able to write them). @scknkkrer
Besides books on Clojure, check out some of the Clojure libraries you use and try to figure out what makes them tick.
I don’t know, maybe others have more pointed advice for you 🙂
And I have a question about pure functions. I know this is fundemental, basic. But I want to clear something in my head. f(x) -> x * 2 is a nice defination. just call it with one numerical argument and it gives a mult. by two. What if I wanted to call another function in f ? Then it’s return value not solely depends on it’s argument. f(x) -> g(x) * 2; ----------> is this a pure function ? I am not sure I can write my functions full depends on it’s arguments. Am I wrong ?
Most people would say that f is pure iff g is also pure, though you’re right to point out that f depends on the state of var-space. In practice, most clojurists tend to the view that vars should be immutable by default.
@chillenious, @donaldball, I am really confused now. 😄
its even possible (although difficult) to build a pure function from impure procedures
for instance, all the operations your computer defines are stateful. They all change the registers or main memory.
and yet clojure and haskel are pure, and are implemented in terms of those procedures
if you only use pure operations in the implementation of a function, the function itself is pure
if you don't that doesn't necessarily imply that the function isn't pure, (although liklihood is a different matter)
the convention in clojure is to mark impure functions or "procedures" with an exclamation point after the name
f(x) -> x * 2 -------> I know this is pure. f(x) -> g(x) * 2; ----------> But, is this a pure function ?
if g(x) takes any x and returns that same x on the first 2 invocations, but on the third and thereafter returns 0, then it is stateful and impure
f(x) would have similar behavior, only it would return 2*x on the first two invocations, then 0
for instance, there could be a function g(x) that returns 0 on the first three invocations and then x on every invocation after that, so that is impure
another function h(x) could be the opposite, returning x on the first three invocations and then zero on every one after that
bcbradley: i do like this example, altho i would drop "pure" and say f is a function.
purity just means that a function will produce a return value corresponding to its arguments; for each set of arguments, there is one return value, and that value will always be returned if those arguments are givne.
it doesn't imply anything about "side effects" that might occur as a result of the function performing its operation
if you want to interpret the side effects a computational implementation of a function might have as part of its return value, you could, and if you do then of course such an implementation couldn't be interpreted as a pure function
but that is just a choice; there is nothing that says you have to have that interpretation
its possible to have side effects that just don't matter; they might not affect your program's operation-- for instance, causing a light to blink on and off could be a side effect
"purity just means that a function will produce a return value corresponding to its arguments; .
see that's the problem with the term. by your definition my implementation of "inc" that launches the missiles would count as "pure". and if "pure" just means "functional semantics", then why bother,
if the result depends on the number of invocations, that function isn’t pure, right? so then f(x) is pure iff g(x) doesn’t hold
if g(x) is pure, f(x) is pure (because it’s only components are a pure function and a constant
dunno, I’m not much of a theorist, but that seems logical to me
but then you can never say a function is pure if there is any other function component to it that isn’t guaranteed to be pure
yeah, ok, gotcha 🙂
yeah, I get what you mean
i'm trying to think of a way to cancel out the impure parts of opengl to provide a library of pure functions that provides the same utility
if you want a function to be absolutly pure, the computer should be pass as a parameter 😛 and it must produce a new computer as a result
mmm not sure that I agree; many hold that a pure fn both always returns the same value for the same args and has no observable side effects
It affects the states of the impure h and g; that’s an observable side effect
It’s not a super interesting debate tbqh, clojure isn’t overly concerned with purity, much more of a semantic quibble
fwiw, "impure function" is an oxymoron. since all real -world computations have observable side-effects (at the very least, consumption of energy), the are no genuine functions in any programming language. but operations with no semantic side effects are close enough, so we call them "pure functions". note that an operation that fits the classic defn of function - always gives same result for same input - could nonetheless have semantic effects. for example a fn that always returns 3 could update a global counter each time it is called. to the client that calls it, it looks like a pure function, especially if the client doesn't care about the global counter. But it's not even a function, strictly speaking. this can be very useful, esp. for metaprogramming, support for which is one of Clojure's greatest strengths. lots of Clojure stuff is "impure" in this way, e.g. most antything that starts with "def" will have semantic side effects altering the environment (namespace). what really matters is reliable predictability that approximates genuine functionality, rather than "purity".
the whole idea of purity is just a tool, like the concept of immutability is a tool, or the idea of objects is a tool
insisting "nothing is pure" and leveraging that point of view to assert that the idea of purity isn't useful isn't very productive
that is because obviously something is pure, or it wouldn't be possible to imagine purity
in other words, the land of imagination is as valid a place as the land of you and me
@bcbradley personally i'm not very interested in ideological purity. i just like accurate descriptions of the way things actually work. "purity" is a buzzword that people are free to use as they wish. but it is not a technical term in cs; it's simply not very meaningful. accurate terminology is critically important, esp. for newcomers. "what is a pure function?" and "is this function pure?" are common kinds of question. imho the way to answer them is to focus on computability rather than mathematics.
i would add the the people behind clojure have very laudably emphasized, in so many words, that Clojure is about thinking. thinking about functional v. imperative v. oo programming is hard, imo.
is "range" a function? no; functions always terminate. but it always returns the same result, and it has no side effects. is it pure? does "pure" even meaning anything here?
bcbradley: i wouldn't be so sure about that. afaik, mathematically, functions always return finitw values. but i am not a mathematician, and math can be surprising; it would not surprise to to learn that this is not always the case. but then i think we would be talking about 2 different concepts of "function".
https://en.wikipedia.org/wiki/Function_(mathematics) there is nothing that says a function's domain or range have to have numbers as elements
a function is just a collection of mappings from one or more things to a corresponding thing
sure, but they always return a value. a fn coukd return the set Nat, but it could not return an infinity of nats.
the underlying issue here is induction v. coinduction. the functions we know and love, like +, are inductively defined. "functions" like range cannot be inductively defined. there's a fundamental symmetry.
f(3) = [1,2] is certainly valid and the "result" is an uncountable set of real numbers
"an infinity" is most certainly a thing. Here: F(x) => "an infinity". There is a function that takes anything and returns an infinity. If that seems a bit facetious that is because functions really are this general. Its humans and computers that are too limited, not functions.
busted? help me with this. obviously in a computer there is no such thing as an uncoutable set. our procedures can only approximate. but more to the point: your f returns a definite set, which happens to be infinite. it does not return a list of values that keeps going. also you cannot do (first (f 3)).
i was just wondering about your aversion to finite, so i posted a counter example. but it appears i misunderstood which range function you were discussing
i also can't tell if we're talking about pure mathematics or particular instances of functions in code
@U11BV7MTK maybe "determinate result" would be better.
fwiw this topic is in my experience very complex. also fascinating, also directly relevant to oo v. functional. afaik it's all down to this v. co-this. functions: induction. routines that returrn infinite lists, random numbers, etc.: co-induction. oop is co-stuff. the symmetry is incredibly beautiful.
@U11BV7MTK no aversion to infinite here, luv the stuff! it's just not functional.
is there some definition that you are using then? i don't understand why a function returning an infinite list makes it not functional
@bcbradley regarding "F(x) => 'an infinity'". it's obvious that F cannot return an actual infinity, right? if it could, it would not in fact be infinite. the best F can do is return some kind of peocedure the lets us crawl thru the infinity.
@U11BV7MTK ok, let's go back to foundations. what problem did turing set out to solve? in a word, "effective procedure (for computing a function)". procedures that do not terminate are not "effective". they do not calculate the answer to the question, since they never answer. Clojure's "range" never answers since it keeps going, forever. sure you can "take" partial answers, but that's different. sorry, i'm still working on the language to explain this clearly.
also "range" does not return an infinite list! how could it? computers do not have infinite memories! what it returns is a computation.
bcbradley: yes, i meant (range), or any other "function" that returns a pseudo-infinity.
he believes the idea of purity doesn't apply to (range) because it never terminates
I believe it doesn't matter if it terminates or not because termination is a computational idea; (range) returns all integers, in order. that is a well defined return value.
bcbradley: no, range does not return all integers. how could it? the very idea is absurd. the idea that it does is a useful fiction, but still a fiction. if you don't think termination is important i have some bugs i 'd like you to look at. ;)
If f(5) -> 25 and you can substitute any f(5) by the constant 25 in your code, then f is referentially transparent and thus "pure"
Further, the composition of a bunch of pure functions yield another pure function, but the composition of a bunch of pure functions and at least one impure function yields an impure function.
@slipset if i knew what "pure" means, i might agree. but @bcbradley gave an excellent example of a pure fn composed of impure fns.
@mobileink I fail to see how the composition of impure functions can yield a pure function.
@bcbradley gave a good example. https://clojurians.slack.com/archives/clojure/p1489244285027879
What I'm getting from this is: You can compose a function that is referentially transparent from functions that aren't. You can't compose a function that has no semantically observable side effects from functions that do have them.
or howsabout this: i have a fn, my-inc. it take a nbr and increments it. but it also has a metadatum, which keeps track of all the times it has been called. functional? pure?
because it can block a go thread for an arbitrary amount of time
and there are a fixed number of go threads
ok, then what is the best way to do this: (go-loop [] (locking out (println (<! channel))) ?
why do you want to do that?
you don’t need to lock *out*
to write to it
so build complete strings before you println
(println (str …))
(print (str … “\n”))
or alternately send to a channel (or an agent) and have the channel or agent read and print messages one by one
in other words, reduce the number of writers to one
right, that’s an option, didn’t do it because then i’d need to change all println calls to put!s or something. (print (str)) seems to work, thanks!
that is, the counter is not a global, it's atyached to the fn. to get at it you have to really want to. ;)
@mobileink The fact that it's metadata doesn't change anything from my perspective. It's a value outside of it's arguments, that you are affecting in an observable way by calling the function.
true. but there's a big diff between metaprogramming and app progrsmming. that's one of the things i love about clojure. app programmers don't need to worry about the meta stuff.
If you were limiting the domain of your semantics to exclude metadata, it would be a pure function.
a lib can use metadata on namespace, vars, etc. to enable amazing things, and the users need never know about it.
e.g. i have a lib in the works that uses tons of metadata and other metaprogramming stuff, but it's all completely hidden. it all looks like "pure" functional stuff, but it isn't really - just like clojure.
True, Clojure lets us do amazing things. But users can still observe those things if they want to, with regards to the discussion about purity and what constitutes an observable side effect. So it could be considered disingenuous to say a function like that is pure. I think the Clojure core team are pretty clear about the fact that large parts of the language aren't pure. There's a distinction between pure and stateful transducers, for example. And core.async.
@shdzzl heh. nobody can ever say the core Clojure folks are ideologues, thank goodness! fwiw, "purity" is just not in my vocab, wrt prugramming. i tbink it does more harm than good. this routine is functional (meaning, it approximates functionality), this one isn't,.
@mobileink You literally can't do anything with your code except make the processor hot without a touch of impurity. One of the really tricky parts of language/lib design in the functional space is how to introduce side effects into your base assumption of functional purity. Clojure does it really well IMO.
Purity is a useful term when considering functions that are run to get their value, but that might be run mutliple times or asynchronously. In your example of a function that updates a counter in metadata, if you were to use that to try to update a ref in a dosync
, the counter might be updated mutliple times even though you only intended to run the function once. So the semantics have to be clear.
@qqq http://www.braveclojure.com/writing-macros/ The section on syntax quoting. That's where I learnt about it. The official docs for syntax quoting: https://clojure.org/reference/reader#syntax-quote
Okay. Is there a right enough way to integrate compojure and cider such that C-c M-j
launches the test server and inserts the REPL into the appropriate namespace?