This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-26
Channels
- # aws (4)
- # beginners (21)
- # boot (12)
- # cider (3)
- # cljs-dev (1)
- # cljsrn (10)
- # clojure (190)
- # clojure-nl (1)
- # clojure-russia (7)
- # clojure-spec (1)
- # clojure-sweden (9)
- # clojure-uk (30)
- # clojurebridge (1)
- # clojurescript (105)
- # cursive (4)
- # emacs (8)
- # jobs (1)
- # jobs-rus (4)
- # klipse (1)
- # luminus (5)
- # om (3)
- # onyx (2)
- # pedestal (5)
- # powderkeg (15)
- # re-frame (13)
- # reagent (1)
- # ring-swagger (5)
- # rum (5)
- # vim (8)
README updated. Argument handling is in a pure function that either returns an :exit-message
or returns an :action
and the :options
. This is more amenable to testing. And if you really want to call -main
in the REPL, you could wrap that call with a with-redefs
to change the exit
function (defined in the cli-example.core
namespace to just println
instead of calling System/exit
(which you could have done before, but this new structure has all the validation in one place instead of mixed with the actual program actions).
Yeah, I was wondering if you could call with-redefs - does that work for Java static methods? You could redefine it to throw an exception which your tests could catch
Doesn’t seem much of a namespace if I have to have the fn name altered to refelct sa
Also having to declare functions in order is consistently tripping me up. What's that all about?
@mattford it's a warning so you can ignore it but obviously it's there to tell you that you've shadowed a core fn. It's useful if somewhere in the namespace you call read
and expect it to resolve to clojure.core/read
to be reminded that you shadowed that fn otherwise you would get unexpected results.
See this discussion by Rich Hickey on what defines a compilation unit and how interning at read time would change Clojure's REPL driven dynamic. https://news.ycombinator.com/item?id=2467359
@mattford to get rid of the warning, the ns
macro takes a :refer-clojure
option, as in: (:refer-clojure :exclude [read])
Ordering declaration makes complete sense in a REPL. If you didn't then a fn you typed at the repl would not necessarily be immediately usable as it could have a hanging unresolved ref.
That's true but the work flow is to iterate continuously on the functions so that the initial ordering is lost. Lost that is in my mind :-)
mattford I usually don't defn a function in the repl. I do lots of lets that I refactor into functions (and copy paste the repl output into a test). I guess I've gotten used to the single pass compiler over time, so it doesn't usually bother me. I do usually restart my repl after defining a lot of things to make sure I haven't copied over dummy things, got my stuff out of order or depended on something in my repl environment to make things work (as I want them to work later)
I make sure I've got the repl history saved tho so I can go back and get the things I need if I've forgotten something tho
I tend to have a source file open and write code there but evaluate it inline (into the REPL), so I naturally just sort of write it bottom-up, i.e., the order Clojure expects. Or maybe as a function gets too big, I'll refactor it into smaller functions just above it.
I did that with Emacs and now I do the same with Atom/ProtoREPL. I don't tend to write much directly in the REPL -- just a few test expressions -- since it's easy to just write code in the source file and evaluate it piece by piece.
seancorfield I sort of force myself to do it in the repl first in a let so that moving it to the source code buffer is the first refactoring (as I have the test captured from my let in the repl)
When I used LightTable for a while, I developed a workflow where I write fragments of code in a source file and evaluate them inline, instead of using a separate REPL. I've carried that over into Emacs and then ProtoREPL... so I probably follow the same pattern as you, just inside a source file as it grows and refactors into actual functions...
I do get that my workflow is a bit old and doesn't take full advantage of the latest things in cider/atom/intellij/other
The inline evaluation with LightTable really inspired me to work differently. That's when I found myself no longer needing or wanting the REPL as a separate thing. I'll often still spin up a REPL from the command line, with Boot, so I can pull in a specific library to just play with.
Mostly I do that when I'm helping someone here on Slack, if it's with a library we're not already using in our code base.