This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-05
Channels
- # beginners (23)
- # boot (84)
- # braid-chat (2)
- # bristol-clojurians (1)
- # cider (53)
- # cljs-dev (34)
- # cljsrn (13)
- # clojure (138)
- # clojure-dusseldorf (5)
- # clojure-italy (1)
- # clojure-russia (164)
- # clojure-uk (41)
- # clojurescript (80)
- # clr (2)
- # core-async (6)
- # core-logic (25)
- # core-matrix (14)
- # cursive (10)
- # data-science (4)
- # datomic (4)
- # emacs (3)
- # funcool (6)
- # hoplon (127)
- # jobs-discuss (4)
- # keechma (36)
- # ldnclj (5)
- # lein-figwheel (5)
- # off-topic (5)
- # om (155)
- # onyx (72)
- # overtone (16)
- # parinfer (39)
- # planck (3)
- # protorepl (1)
- # re-frame (11)
- # reagent (5)
- # untangled (22)
how would you use transducers in a statically typed language?
I don't immediately see a reason that I can't use it well in a statically typed language. I'd impose typeclass constraints on types rather than fully instantiate types.
idk, it seems like it would be really difficult to do it correctly, I think that something like core.typed has the potential to be really good and provide typing for those who want it
@adamkowalski: Do you know typeclass?
yeah I have used them in Haskell and they are fantastic
core.typed
has a very long way to go before it’s comparable to any strong type system with inference.
but in c++ we only have templates
not sure about c because I never really need to use it
C is weakly typed (at best).
I think that the extensibility of a lisp means that it is a great candidate for extension
its one of the things that draws me the most towards clojure
im almost every other language I find I lack something and I am not able to do anything about it.
in clojure if something you want doesn't exist it is possible to use macros to transform your code
C is pretty much the poster child for a weakly statically typed language @hans
(I developed one of the very first ANSI-validated C compiler / runtime systems, BTW)
Anyway, WebAssembly will probably obsolete ClojureScript by 2020 because WebAssembly might become a legitimate compilation target for Clojure.
Also, https://en.wikipedia.org/wiki/C_(programming_language) says C's type system is weak.
Type casting and pointer arithmetic make type system weak. Union types make it weaker. Those features make it hard to enforce type constraints.
I think we can agree to agree @crocket 😸
Haven't had a chance to look at WebAssembly yet. I was agreeing with your comments about C.
It will become a compilation target for javascript and various web browser languages.
How widely supported is it in browsers today?
Major web browser vendors started implementing it since June 2015. Webkit, Chrome, Edge, and Firefox
Initially, C/C++ will compile to WebAssembly, and virtual machine support will come later.
Clojure might replace ClojureScript in the future when WebAssembly is mature and runs on a proper VM platform.
Major server-side javascript runtime environments like V8 will support WebAssembly, too.
IMO this entire comment thread applies https://lobste.rs/c/fjbmp7
It's fine to say that WebAssembly may come to complement JS at some point in the future, but the reality is that Clojure and ClojureScript are both designed to assume very very good garbage collectors and a very rich virtual machine/target compared to raw assembly. The day may well come when something Clojure-like compiles to "native", I just think you're grossly underestimating the amount of work required to do it, and overstating the value given the immense strengths of existing platforms.
Meh, http://lobste.rs is becoming overwhelmed by negative-vote trolls.
Is there a way to measure the performance of map functions without realizing it?
(defn expensive [records]
(let [result (time (doall (map inc records)))
result (time (doall (map dec result)))]
nil))
(defn expensive-2 [records]
(let [result (map inc records)
result (map dec result)]
(doall result)
nil))
Obviously (time expensive (range 1e6))
is faster than (time expensive-2 (range 1e6))
but the downside of the first call is that you won't be able to drill down on which map calls are actually slow things down.
Just curious how does anyone tackle this. Currently I had to realize every map call to have a detailed view of the function calls - which I feel it's not using clojure to its full potential (and render reducers
useless in my case)reducers are just the same in this regard, if you don't actually do the work, you cannot time it
@hiredman yeah, i’m just curious if there’s another way of doing this because if i realize at every step, it defeats the whole purpose of lazy-seq or reducers
and also curious if anyone else is doing the same thing and i’m not the only one doing it this way 😄
if you are just doing microbenchmarks, even then using time can be suspect (you should check out criterium)
time the operation you apply over every record, it makes no sense to time the iteration (or the creation of a LazySeq)
if you are trying to meaningful understand the performance of a large amount of code, consider something like visualvm
if you map a function f
over a collection, a profile like visualvm, will show you the total runtime of f
as your system runs, regardless of where you end up realizing the seq
well my use case is that i have a webserver and some endpoints are more expensive than others. I used clojure-metrics which in turns uses codahale metrics in the backend
and i created a graphite chart to show the response times for each endpoint, but some endpoints are slower so for those endpoints I needed a breakdown
on which functions actually taking up time
so what i did was exactly like the first expensive call, i call metrics/time
on a realized collection all the time
because if i use lazyseq/reducers and if at one point suddenly response time is very slow, there’s no way to find out at which function it’s actually slow right
so in the end my approach is the correct way i guess
@seanirby: One note, I’ve found that versioneer will work for some things when you’re running through leiningen, but then return nil at runtime if you compile to an uberjar and then run that
It winds up getting a system property for myproject.version
which I assume lein sets at runtime
I wound up writing a static file into my jar at build time and falling back to it if versioneer returned nil for me (there might be a better way to do it)
I think there is also a library somewhere which parses project.clj as edn, too, or you could do that by hand of course, but again if you compile to an uberjar you won’t necessarily have it around at runtime
@lwhorton: @turbopape: you can neither exclude .
nor will the runtime warn you that you're overriding it. .
is not a normal Var, it's a special form, you cannot override it.
well, that’s actually more 20K locs. 4K loc was when only the homepage was rendered by clj
@timgilbert: appreciate the detailed reponse. thanks!
I keep having this idea that I want to maintain a fork of clojure on which a Java indenter (among other things) is being run.
Purely automated transformations which get re-applied when new commits appear in the official repo.
having a properly indented clojure would be valuable if contributors could write patch on top of it rather than on top of the mess that's currently clojure's indentation, I don't see much point in a properly indented fork that's read-only
@bronsa Really? Isn’t it generally assumed that code is read at least 10x for every change made? I would suspect this would be much higher for Clojure.
I think it's safe to assume that every Clojure developer knows the Clojure source by heart, no?
Parsing the indentation is not where I have trouble when reading the clojure compiler source
@donaldball: where do you have trouble?
(mind you, I’m not likely to actually do this, but I spend an inordinate amount of time thinking about it)
@eraserhd: Compiler.java is not exactly a prime example of obvious and understandable code
@eraserhd: thing is, if you're reading code for a change, that'll be formatted for clojure/clojure and not the re-formatted clojure, and will likely not apply there
I would hope that people who want to make a change, make that change in the original repo. Making a change like that to clojure presumes one already understands how it works, which presumes they’ve already read the code… and that’s what this would be for.
For reference, I’ve probably spent a dozen hours in the clojure code, and basically understand nothing. I assume I’d have to spend a dozen more before making any kind of patch.
sure, but I doubt people work by reading code for hours and then producing a patch I know I certainly do the reading and writing/testing at the same time when I'm working on a clojure patch, and would find having a read-only repo neat for maybe a few hours. But having to switch back & forth between an indented file and the same file where I'm writing a patch? meh
How does (file-seq)
decide what order to put the files in the return collection? From my minimal experimenting, it seems like the directory itself is always first, and then the rest in reverse order of file creation (this was tested without any subdirectories). Is there a way to change that without calling a sort around (file-seq)
?
https://github.com/6ewis/recruitersPickupLines/blob/master/bestLines.md contribute for the laugh
A fair bit of googling and reading clojuredocs has led me to believe that there's no really straightforward way to search a seq or vector for a "sub-seq" or "sub-vector", i.e., (magic-search-function [1 2 3 4 5] [2 3]) ; => 1
(in contrast to regexps and indexOf
for strings). Is this correct?
user=> (.indexOf (partition 2 1 [1 2 3 4 5]) [2 3])
1
user=> (.indexOf (partition 2 1 [1 2 3 4 5]) [4 5])
3
user=> (.indexOf (partition 2 1 [1 2 3 4 5]) [5 6])
-1
where the first argument of partition is the size of the collection you are looking for
user=> (def x [2 3])
#'user/x
user=> (.indexOf (partition (count x) 1 [1 2 3 4 5]) x)
1
(defn magic-search-function [haystack needle]
(.indexOf (partition (count needle) 1 haystack) needle))
@jr thanks, that's indeed what I was doing—I had been thinking that was terribly inefficient but as I read more about lazy seqs, maybe they're just fine
apparently I have also forgotten how to regex; (re-find #"(?!index)[.]html$" (.getName f))
doesn’t “get anything like html, but not index.html”; instead it gets everything ending in html but doesn’t throw away index.html, apparently
You probably want (re-find #"(?<!index)[.]html$" (.getName f))
. You had a negative lookahead where you needed a negative lookbehind.
I have a stupid question relating to (possibly) cond
but maybe also just invoking functions with vectors… this is not doing at all what I would expect:
(defn read-hiccup [hiccup]
(cond
(empty? (first hiccup)) []
(keyword? (first hiccup)) (conj [:keywword] hiccup)))
It should be a simple function that takes [:html]
hiccup style syntax and just spits it back to me.But I keep getting Don't know how to create ISeq from: clojure.lang.Keyword
. Which makes me think this is a foundational-level issue in understanding and not function design.
Hm. So, at some point yesql started insisting that you specify the {:connection db-spec}
map when you call defqueries. That’s a little annoying; because I don’t know which db I’m going to call it on beforehand. Current versions of yesql raise an exception when you call it with a connection map anyway:
ArityException Wrong number of args (1) passed to: generate/generate-query-fn/query-wrapper-fn--22770 clojure.lang.AFn.throwArity (AFn.java:429)
Even though the fn in question claims to have that arg:
(meta create-table!)
{:name "create-table!",
:arglists ([{} {:keys [connection]}]),
:yesql.generate/source "CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);”}
There’s an existing issue for that exception, but apparently it just thinks that you should know connections at compile time: https://github.com/krisajenkins/yesql/issues/91 Apparently I am not the only person to reach the conclusion that you can’t reasonably manage a connection now: https://github.com/krisajenkins/yesql/issues/99
require-sql appears to be the way you do this, but apparently it’s just broken https://github.com/krisajenkins/yesql/issues/118