This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-02
Channels
- # admin-announcements (1)
- # aws-lambda (9)
- # beginners (161)
- # boot (1)
- # cider (3)
- # cljsrn (36)
- # clojure (245)
- # clojure-austin (2)
- # clojure-denmark (3)
- # clojure-dev (11)
- # clojure-greece (6)
- # clojure-italy (25)
- # clojure-russia (5)
- # clojure-serbia (1)
- # clojure-spec (76)
- # clojure-uk (78)
- # clojurescript (168)
- # clojurex (4)
- # community-development (7)
- # core-async (11)
- # core-logic (5)
- # css (6)
- # cursive (8)
- # data-science (6)
- # datomic (5)
- # devops (4)
- # duct (17)
- # emacs (1)
- # figwheel (8)
- # fulcro (51)
- # hoplon (4)
- # instaparse (3)
- # kekkonen (6)
- # klipse (3)
- # lein-figwheel (9)
- # luminus (2)
- # lumo (3)
- # midje (4)
- # off-topic (11)
- # om (4)
- # onyx (62)
- # other-languages (60)
- # re-frame (21)
- # reagent (63)
- # rum (1)
- # shadow-cljs (22)
- # spacemacs (22)
- # specter (23)
- # test-check (2)
- # vim (2)
- # yada (6)
In a (cond) statement, I can evaluate a bunch of tests, and the first one to evaluate true will return the value of its corresponding expression
My question is: Does :else somehow evaluate to true? How does this work? Is the keyword :else just used by convention?
It’s just convention. Any truthy value will work.
I'm not sure in what way a keyword is truthy though. If I try (true? :test), it returns false
true?
is a specific test for the true
boolean value. Anything that passes boolean
is truthy, namely any value that is neither nil
nor false
.
boolean accepts some values as false
that if (and therefore cond) does not btw
+user=> (if (Boolean. "FALSE") :yes :no)
:yes
+user=> (if (boolean (Boolean. "FALSE")) :yes :no)
:no
+user=> (cond nil 0 false 1 (boolean (Boolean. "FALSE")) 2 (Boolean. "FALSE") 3 true 4)
3
but nobody should be making new instances of Boolean anyway, so it's a serious corner case
Can i do everything in typedclojure that the mainstream clojure can do?
@arno Typed Clojure is "just" an annotation system and analyzer for Clojure -- so what you're writing is still Clojure.
ah, ok
hi… i need to check if the email exists on database, is there anyway of doing that using clojure.spec?
how to make this work?
(spec/def ::geoloc (spec/keys :req-un [::latitude ::longitude]))
(spec/def ::address (spec/keys :req-un [::type ::country ::postal ::state
::region ::street ::number ::geoloc]
:opt-un [::adjunct ::reference]))
(spec/def ::billing_address (spec/keys :req-un [::type ::country ::postal ::state
::region ::street ::number ::geoloc]
:opt-un [::adjunct :reference]))
(spec/def ::document (spec/keys :req-un [::number ::type]))
(spec/def ::phone (spec/keys :req-un [::country-code ::area-code ::number]
:opt-un [::extension]))
(spec/def ::company (spec/keys :req-un [::type ::document ::corporate_name ::contry
::billing_address ::address ::email ::phone]
:opt-un [::fantasy_name ::brand_name ::state_tax_id ::city_tax_id]))
throws
CompilerException java.lang.AssertionError: Assert failed: all keys must be namespace-qualified keywords
(every? (fn* [p1__1857#] (c/and (keyword? p1__1857#) (namespace p1__1857#))) (concat req-keys req-un-specs opt opt-un)), compiling:(atrium/company/validator.clj:14:29)
~
what is :opt-un and why isn't it namespaced?
opt-un is optional, strip namespace
what about :reference (other places it's ::reference)
yeah, that's the problem, nice eyes
the line number would have made it easier if we saw it, heh
I assume that spec/def call was on line 14 of the original
a good editor can take that validator.clj:14:29 and jump straight to the error (if the line/column was generated properly at least)
If you use emacs, why are you not using Cider? I thought that did all the repl integration stuff
@carr0t it does, it also adds some complexity and brittleness and not everyone rates the tradeoffs the same way
I don't use fireplace, I just use vim, for the same reason I run debian stable - things break enough just from me being dumb, I don't need to add unstable tools on top of that to drive myself crazy 😄
@noisesmith lol, I’m dumb as well, thats why I prefer pure emacs
I like the extra confidence that if things go wrong I know it's not tooling weirdness (though I hear cider and related tools are much more reliable than they once were)
@noisesmith is there anyway to use spec validation with db query (mongo)? check if something exists
@noisesmith without fireplace, what is your workflow like with vim? Quite curious, as I'm thinking of switching to vim myself.
I use load-file and require with a reload argument to hot load code
(load-file "/home/justin/clojure/foo/src/foo/bar.clj")
(works even with libs) (require 'foo.bar :reload)
(only works with things loadedfrom the current project)
also (load-file "/tmp/experiment.clj")
or similar
I also have a library that stores the data I am looking at in the repl into a file, so that it can be transparently loaded in a new repl, or in a unit test https://github.com/noisesmith/poirot
I use clojure.repl/doc clojure.repl/apropos and clojure.repl/source to figure out how to use other people's code (or go to github and browse as a last resort)
though I find if I have to look up docs I probably want javadoc anyway a decent percentage of the time
technically I have fireplace installed, but I'm not using the cider plugin it requires for advanced stuff and I never use its features
I like that, keeping it minimal. I assume you just use vanilla vim, or neovim? And what vim tools, just vim-sexp? Any others?
vim-sensible, vim-sexp, vim-clojure-static, gundo are the ones I use for clojure editing
I may hit you up later for advice as I experiment. I prefer vim editing, but evil mode only goes so far.
yup my path was vim (for a few months) emacs (for decades) wrist pain, then evil mode, then vim again
not chording plus a split keyboard completely eliminated RSI problems btw
not that I ever need to use
I either remap to a leader plus individual keys, or ignore the feature - eg. I remapped all my window / buffer management to single keys
I could do the same thing in emacs, but vim is closer to the target of not chording from the get-go
I mean - I still use the shift key, and ever so rarely the control key of course
but it's not constant like it was even with evil mode for me
My problem with evil mode is you are still in emacs and need emacs bindings for some tools. And evil was per buffer and diff buffers would be in diff evil modes
\o/ clojure.pprint/cl-format
has made me happy 🙂 - is it ANSI compliant or are there any documented gotchas?
I can only speculate, but my assumption has been that def should be using immutable data anyway, and if you really want data hiding you should use let and not def
maybe someone has a better answer
an idiomatic thing is passing the value to the things that need to use it explicitly, rather than using access control around a (namespaced) global value
I'm definitely definitely enjoying clojure. Taking my time to reduce code results in the smallest, clearest lisp I've used
it's very opinionated, but its opinions are usually good choices in my experience
and the opinions, once I've grokked them, are usually good. I don't know what it'll be like to e.g. use opengl or something very heavily stateful yet, but I'm trying to ignore that problem for now and stick with what's natural
opengl is pretty far from clojure's sweet spot too, idiomatic clojure would create way too much garbage I bet, and make the API annoying to use without adding benefit - unless we are talking about something much higher level that uses Opengl, rather than wrapping it for other clojure users
but that's just speculation...
that's my current assumption. haskell is similar. opengl code winds up looking like any other imperative programming language
except probably being clumsier (I bet the clojure version would be even clumsier than the haskell version actually)
hehe, that remains to be seen. that said, clojure could make a very acceptable high level interface over java providing a more retained mode scenegraph
but! clojure has this great ability to integrate with java in both directions - so you can easily have java classes that interact with opengl and an AI that controls it in clojure all in one project with seamless interaction in both directions
my day job (like so many others) is pulling chunks of data out of persistent storage, munging it and stuffing it somewhere else, and for that, it seems pretty good (once I've grasped the core)
yeah, clojure is best in class for ETL as far as I know
i’ve been using clojure with opengl and been having a lot of fun with it
although i’ve been accessing opengl through jna
i’d be happy to share my code, but it’s a kind of a mess
when I first learned clojure I thought I had become an ETL genius, but no, not at all, I just learned a language that is very good at that domain haha
@smith.adriane my code is also a mess, but happy to swap ideas, i love playing with that stuff
i’m very interested in finding good resources for the best way to design for that
@noisesmith haha, i've found a lot of other solutions to be cognitive overload
@mseddon do you have any links for how things were used from CL?
bonus points for DSLs for GLSL (all homebrew)- and multimethods which are really fast in sbcl
but actually someone here earlier today who turned up is a professional games engine developer in C++, was discussing John Carmack porting wolfenstein to haskell
I will try and find you some CL resources- it's been quite a few years since I was embedded in there
awesome!
my main use case is more for creating UI rather than for a game engine
which clojurescript is being used for all the time
there's that clojure-clr port to run in a windows game engine, but if you look at what they did to get it to run with any acceptable performance inside the render code it's kind of insane - they made their own custom byte code emitting dsl that looks just like clojure but only does things they can promise are fast enough
sounds fun
i’ve actually been really surprised at how responsive the UI’s I’ve been making are even with my extremely naively implemented code
but optimized blitter stuff, I have other things up (polymorph) that contain layout managers (pack/grid) ala gtk/qt
the problem i found was text input on mobile, and handling international text performantly on mobile (though that has recently just got fast enough to not matter)
the UI’s i’m creating are running on my laptop via opengl
which probably helps that desktops have access to lots more cpu
yeah, desktop does help- i actually have some probably unpublished truetype font parsers for that, too
ok, i’ve been using freetype
I can use socket connections, talk to the file system, easy multi threading
it’s great
pmap
, promise
, thread
, future
tbf the repo i linked may not be so useful. it's about blitting quads as fast as is practical on a browser on a mobile
but it's WebGL 1, so OpenGL/ES2- there are better ways on a desktop, and frankly, i don't think you really pay for it doing it another way
cool, i’ll check it out!
may have http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf shader in there tho
if it does, i know you need to add the texture derivative (dFdx, dFdy) extension to it to be better.
@noisesmith what is the status of clojureCLR?
i've done some professional unity work in the past (version 3) in c# and it was a bloody nightmare
According to the commit list on the ClojureCLR repo, it's currently tracking Clojure (JVM) as of March 14th this year.
Which is 1.9 Alpha 15
that said, the last time i started out with clojure, it was in 2009 and the CLR implementation was DOA
@rcustodio clojure isn't slow to start natively on desktop
aot uberjar will fix it, provided your game engine runs fast enough once it's up and running, i would say
@seancorfield in this case aot is good?
AOT could reduce your startup time so it could improve your application's time to launch; I would avoid it while developing and then try a fully AOT-compiled uberjar for "production", and compare startup times.
Is it possible to destructure a #object[HTMLDivElement]
in CLJS? Right now I have this
(let [width (.-offsetWidth Element)
height (.-offsetHeight Element)] ;; ...
and I was thinking it would be nice to be able to do something like this:
(let [width :offsetWidth height :offsetHeight] Element] ;;...)