This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # adventofcode (4)
- # aleph (1)
- # architecture (9)
- # beginners (67)
- # boot (7)
- # boot-dev (12)
- # cider (3)
- # clojure (166)
- # clojure-austin (3)
- # clojure-estonia (1)
- # clojure-greece (2)
- # clojure-russia (5)
- # clojure-spec (1)
- # clojure-uk (4)
- # clojurescript (19)
- # cursive (1)
- # data-science (5)
- # datascript (4)
- # datomic (3)
- # docs (10)
- # emacs (24)
- # events (4)
- # fulcro (16)
- # graphql (8)
- # hoplon (2)
- # jobs-discuss (1)
- # leiningen (5)
- # off-topic (2)
- # planck (30)
- # re-frame (20)
- # reagent (36)
- # ring (3)
- # shadow-cljs (5)
- # spacemacs (1)
- # specter (2)
You can call meta on a function and it return the args. But i think because … its a var, that i wouldn’t be able todo it at runtime. Is that correct? i’m a bit shaky on functions being stored as vars and what the implications of that are.
err, so someone would have to pass me the var? i couldn’t go from function symbol to var?
(defn foo [args] body) is short for
(def foo (fn [args] body)) --
#'foo is the var,
foo is the symbol that "evaluates" to the function.
What's the problem you're trying to solve @drewverlee? Or is this just curiosity / an experiment?
I want to write a library where you hand it a function and it makes that function available at the command line and provides a helpful prompt.
The goal was just to have a quick way to make a cli for your program. So if your program took a number and increimted it. The dev could just do something like:
(defn add-5 "add 5 to x" [x] (+ 5 x)) (cli/add add-5)
./run-program --help fns add-5 [x] "adds 5 to x" ./run-program add-5 1 => 6
you could require that they pass in the var, or make it a macro and get the metadata that way
i’m about to fall asleep, i shouldn’t have sparked up a conversation about it lol.
I am a beginner and I just learned about
clojure.spec. I would like to know if someone already made a macro that take a spec and gives a parsing code that would act the same as the conform function for that specific spec.
My idea was to use the parsing code into some macro. s/conform only provides the parsed data.
I was (naively) thinking that it would be useful to the programmer to have a reduced, specialized version of this parser so we can make it part of the implementation of the function that is been specified.
For example, that could be useful in error prone cases where function's input is a list of parameters where some of them are optional, and no trivial to detect (i.e. not at the end of the list.
Hi clojurians, I'm parsing a HTML with hickory. It's great so far, however I have to parse now basically a text by some patterns. The fragment I have difficulties have the next shape:
Basically, I have to partition all children by a condition (get sublists of elements which starts with a
<div id="container"> <!-- some non relevant elements --> <!-- here begins the block which I should process --> <strong>1.</strong> <strong>...</strong> <br> <p>some text</p> <!-- a random number of paragraphs --> <br> <br> <strong>2.</strong> <strong>...</strong> <br> <p>some text</p> <!-- a random number of paragraphs --> <br> <br> <!-- end of the second block --> <!-- and so on --> </div>
strongtag with number in it and ends with double
<br>separated by nonbreakable space). So, my question is - how can I get those blocks correctly?
After I've changed my
project.clj to use clojure 1.9.0, how can I have spacemacs + cider start a REPL using that version of clojure? I really need better error messages.
I'm practising by doing some codewars challenges in Clojure, and just finished a partial solution to one problem. This one involves some simple parsing, which I'm doing in a very ad-hoc fashion here. Would anyone care to have a look at what I'm doing and suggest better/more idiomatic ways of writing this code? https://gist.github.com/zsck/64e509d9836377edc2a2c4eaac025d31
I wrote up a solution of my own at https://gist.github.com/codonnell/27da48e74cc4dbc7d71b40fe6eb61e92. To me, parsing a big string like that screams for a combination of
Not sure if it's helpful, but I edited the gist to include my repl session while I was writing my solution. Might help to see my thought process.
Thanks. I'll check it out. I am actually quite pleased with how my solution turned out. https://github.com/zsck/Kata/blob/master/src/Kata/ranking-nba-players.clj
minor suggestion, instead of
(flatten (map analyze-game games)), you can do
(mapcat analyze-game games)
In Schema, I'm using
s/defn to add constraints to my functions and I have one that returns an anonymous function, is it possible to describe this anonymous function in the output schema?
Here's an example:
I'd like to create a schema for
(s/defn foo :- foo-output-schema  (fn  "test"))
(fn  "test")here. And would probably use it in
you can't really do a schema check on a fucntion - you can check the output of calling a function, but functions don't carry any info that we can run checks on
oh, i see, thanks for the confirmation. would you know if this is something achievable somehow with clojure.spec?
@zack.mullaly I would try to incorporate threading macros
->> to make things more readable and eliminate unnecessary let bindings.
tokenize-game-details can be rewritten as such:
(defn- tokenize-game-details [game-sheet] (let [tokens (str/split game-sheet #" ")] (->> (map try-parse-int tokens) (map vector tokens) (map lex))))
Awesome. I didn't realize
->> could work like this. I thought I'd have to manually create a bunch of partial functions to use it.
@zack.mullaly there's also
as-> that lets you define a symbol for the value of the first argument, and then you can the symbol as a place holder in the arguments to the subsequent calls. it's worth checking it out, might be useful when you need more flexibility
@zigned no - spec has the same problem. But there is s/defn for schema that I haven't really looked at, it may or may not be "checkable" in terms of its return value by another schema
Is there a function that takes a value and a collection of functions and calls each function on the supplied value?
(applicative value [f1 f2 f3]) => [(f1 value) (f2 vlaue) (f3 value)]?
juxt takes functions and returns a function, also the function used can be called on any number of args (as long as all of the functions it takes accept those args of course)
Guys, can help with a clojure.java.jdbc error? I'm trying do a insert, but its not working... (Is that the correct place for ask that?)
@caio.cesar.g.souza one thing right off the bat - there's some tutorials out there suggesting a postgres jdbc driver from clojars that is way out of date and not compatible with up to data clojure.java.jdbc
so if you are using a postgres driver from clojars, first step is to use the real postgres driver (it will come from org.postgresql on maven)
Hey everyone I’m new to the clojure game still in college to give you some background, what is the best way to format clojure to deal with those parentheses!
@tbrumbaugh1976 there are some good editor plugins that help keep things balanced and such - what editor or IDE do you use?
sadly it looks like all CCW provides is rainbow parens, which is useful but not as advanced as some other options http://doc.ccw-ide.org/documentation.html#_clojure_editor_features
in emacs with cider, or vim with fireplace, or Intellij with Cursive you can use paredit (which automatically inserts close parens with open parens and has keystrokes for manipulating forms directly) and parinfer which changes parens based on indentation
but honestly a big part of it is getting used to it - it's something that one learns (much like the error messages) for better or worse and in the long run isn't a huge problem
@tbrumbaugh1976 How attached to Eclipse are you? Perhaps consider Cursive (based on IntelliJ) - or Atom/ProtoREPL (or Emacs or vim of course).
I’ll put a plug in for atom with the following packages: https://gist.github.com/jasongilman/d1f70507bed021b48625 It’s not quite as sophisticated but its so much less cognitive load for a newcomer.