This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-16
Channels
- # admin-announcements (14)
- # announcements (1)
- # aws (1)
- # beginners (105)
- # boot (609)
- # braid-chat (4)
- # braveandtrue (3)
- # cider (24)
- # cljs-dev (13)
- # cljsrn (2)
- # clojure (142)
- # clojure-berlin (7)
- # clojure-ireland (7)
- # clojure-japan (10)
- # clojure-nl (4)
- # clojure-poland (76)
- # clojure-russia (198)
- # clojure-sg (4)
- # clojure-taiwan (1)
- # clojurebridge (1)
- # clojured (4)
- # clojurescript (73)
- # conf-proposals (11)
- # cursive (10)
- # datomic (32)
- # devcards (1)
- # dirac (22)
- # editors (5)
- # emacs (3)
- # events (4)
- # funcool (19)
- # hoplon (18)
- # job (1)
- # jobs (3)
- # jobs-rus (16)
- # keechma (25)
- # ldnclj (33)
- # lein-figwheel (10)
- # leiningen (4)
- # luminus (1)
- # off-topic (19)
- # om (255)
- # onyx (51)
- # overtone (1)
- # parinfer (206)
- # perun (5)
- # proton (2)
- # re-frame (3)
- # reagent (2)
- # remote-jobs (13)
- # ring-swagger (7)
- # slack-help (4)
- # yada (7)
I’m working on this one right now, http://www.4clojure.com/problem/22
Crazy how hard it is to figure out how to solve in Clojure
The "special restrictions" is amusing, because that would otherwise be the one-word answer.
exactly!
Basically means you need to write the count function. I would use loop/recur.
reduce also works.
What's wrong with loop/recur?
It always feels awkward. I prefer into
or for
instead. Or a custom transducer for some things.
Can’t even follow what you guys are talking about lol
Josh, just put all those words on separate pieces of paper, shuffle them, and choose one. Look up the page and it will help to solve the problem.
"into" makes a collection. Need to turn collection into scalar here.
"reduce" will be much easier.
Josh, do you have access to REPL to try out partial solutions? That exercise page looks a little unforgiving if you can't test out your solutions.
Josh, I'll help you through a reduce-based solution. Need to hear that you're ready though. 😉
@joshua.d.horwitz: Are you still there?
@ericlavigne: His profile status would appear to indicate otherwise.
Hello.
Need help)
I have a lein-project. Here is its structure
.
├── CHANGELOG.md
├── doc
│ └── intro.md
├── LICENSE
├── project.clj
├── README.md
├── resources
├── src
│ └── clojure_sicp
│ ├── braveclojure
│ │ └── brave.clj
│ └── core.clj
├── target
│ ├── base+system+user+dev
│ │ ├── classes
│ │ │ └── META-INF
│ │ │ └── maven
│ │ │ └── clojure-sicp
│ │ │ └── clojure-sicp
│ │ │ └── pom.properties
│ │ ├── repl-port
│ │ └── stale
│ │ └── leiningen.core.classpath.extract-native-dependencies
│ └── base+system+user+dev+test+test
│ ├── classes
│ │ └── META-INF
│ │ └── maven
│ │ └── clojure-sicp
│ │ └── clojure-sicp
│ │ └── pom.properties
│ └── stale
│ └── leiningen.core.classpath.extract-native-dependencies
└── test
└── clojure_sicp
└── core_test.clj
Q: How to run file brave.clj?
I've tried lein run -m clojure-sicp.braveclojure.brave
Here is brave.clj
(ns clojure-sicp.braveclojure.brave)
(defn latlng->point
"Convert lat/lng map to comma-separated string"
[latlng]
(str (:lat latlng) "," (:lng latlng)))
(defn points
[locations]
(clojure.string/join " " (map latlng->point locations)))
(def heists [{:location "Cologne, Germany"
:cheese-name "Archbishop Hildebold's Cheese Pretzel"
:lat 50.95
:lng 6.97}
{:location "Zurich, Switzerland"
:cheese-name "The Standard Emmental"
:lat 47.37
:lng 8.55}
{:location "Marseille, France"
:cheese-name "Le Fromage de Cosquer"
:lat 43.30
:lng 5.37}
{:location "Zurich, Switzerland"
:cheese-name "The Lesser Emmental"
:lat 47.37
:lng 8.55}
{:location "Vatican City"
:cheese-name "The Cheese of Turin"
:lat 41.90
:lng 12.45}])
(println (points heists))
Here output
lein run clojure-sicp.braveclojure.brave
50.95,6.97 47.37,8.55 43.3,5.37 47.37,8.55 41.9,12.45
Exception in thread "main" java.lang.IllegalStateException: heists already refers to: #'clojure-sicp.braveclojure.brave/heists in namespace: clojure-sicp.core, compiling:(clojure_sicp/core.clj:7:1)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6875)
at clojure.lang.Compiler.analyze(Compiler.java:6669)
at clojure.lang.Compiler.analyze(Compiler.java:6625)
at clojure.lang.Compiler.eval(Compiler.java:6931)
at clojure.lang.Compiler.load(Compiler.java:7379)
at clojure.lang.RT.loadResourceScript(RT.java:372)
at clojure.lang.RT.loadResourceScript(RT.java:363)
at clojure.lang.RT.load(RT.java:453)
at clojure.lang.RT.load(RT.java:419)
at clojure.core$load$fn__5677.invoke(core.clj:5893)
at clojure.core$load.invokeStatic(core.clj:5892)
at clojure.core$load.doInvoke(core.clj:5876)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invokeStatic(core.clj:5697)
at clojure.core$load_one.invoke(core.clj:5692)
at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
at clojure.core$load_lib.invokeStatic(core.clj:5736)
at clojure.core$load_lib.doInvoke(core.clj:5717)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invokeStatic(core.clj:648)
at clojure.core$load_libs.invokeStatic(core.clj:5774)
at clojure.core$load_libs.doInvoke(core.clj:5758)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invokeStatic(core.clj:648)
at clojure.core$require.invokeStatic(core.clj:5796)
at clojure.core$require.doInvoke(core.clj:5796)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at user$eval5$fn__7.invoke(form-init8450613833812556873.clj:1)
at user$eval5.invokeStatic(form-init8450613833812556873.clj:1)
at user$eval5.invoke(form-init8450613833812556873.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6927)
at clojure.lang.Compiler.eval(Compiler.java:6917)
at clojure.lang.Compiler.load(Compiler.java:7379)
at clojure.lang.Compiler.loadFile(Compiler.java:7317)
at clojure.main$load_script.invokeStatic(main.clj:275)
at clojure.main$init_opt.invokeStatic(main.clj:277)
at clojure.main$init_opt.invoke(main.clj:277)
at clojure.main$initialize.invokeStatic(main.clj:308)
at clojure.main$null_opt.invokeStatic(main.clj:342)
at clojure.main$null_opt.invoke(main.clj:339)
at clojure.main$main.invokeStatic(main.clj:421)
at clojure.main$main.doInvoke(main.clj:384)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalStateException: heists already refers to: #'clojure-sicp.braveclojure.brave/heists in namespace: clojure-sicp.core
at clojure.lang.Namespace.warnOrFailOnReplace(Namespace.java:88)
at clojure.lang.Namespace.intern(Namespace.java:72)
at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:546)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6868)
... 46 more
Please explain.
When you call lein run -m NAMESPACE
without explicit MAIN_FUNCTION leiningen lookup -main
in NAMESPACE. If your NAMESPACE doesn't have one it run main function from namespace declared under :main option in project.clj file.
try read lein help run
i've read)
And obviously there is no need to call clojure as any script language)
I understand how to run core.clj, but didn't understand how to run any other file
just require any namespace into core.clj
(ns any.core
(:require [any.foo :as foo]))
(defn -main [& args]
(foo/bar))
like this
you should pay attention that there is no need to call "another file". operate with namespaces in your program
what is bar
in foo/bar
?
function in any.foo namespace
(defn -main
[& args]
(brave/(println (points heists)))
right?(defn -main [& args]
(println (brave/points brave/heists)))
because (println (brave heists))
is not a function
its function call
In brave.clj
(defn print1
(println (points heists)))
In core.clj
(ns clojure-sicp.core
(:require [clojure-sicp.braveclojure.brave] :as brave))
(defn -main
[& args]
(brave/print1))
right, its better for understand what is going on
but again
lein run clojure-sicp.braveclojure.brave
Exception in thread "main" java.lang.IllegalArgumentException: Parameter declaration "println" should be a vector, compiling:(clojure_sicp/braveclojure/brave.clj:33:1)
(defn print1 []
(println (points heists)))
forgot about []
and after that you can start with lein run
without namespace
lein run /cygdrive/c/Users/a_s/clojure-sicp 1
Exception in thread "main" java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.Symbol, compiling:(clojure_sicp/core.clj:1:1)
(ns clojure-sicp.core
(:require [clojure-sicp.braveclojure.brave] :as brave))
should be
(ns clojure-sicp.core
(:require [clojure-sicp.braveclojure.brave :as brave]))
it is.
ok. work.
it is quite difficult.
little practice and you will be happy with clojure)
This is the only way to run the examples from the book http://www.braveclojure.com/do-things/#Pulling_It_All_Together ? That is, write the code in one file, then in core.clj:
(ns clojure-sicp.core
(:require [clojure-sicp.braveclojure.brave] :as brave))
and then place the name of desired function in -main
. Finally: lein run. So?[clojure-sicp.braveclojure.brave] :as brave
=> [clojure-sicp.braveclojure.brave :as brave]
misprint. in my file
[clojure-sicp.braveclojure.brave :as brave]
it happens)
мне показалось?
most clojure program has one entry point
@meow @ericlavigne Sorry Guys! I have a 8 month pregnant wife who needed me last night so I got dragged away lol
I appreciate it, it’s getting pretty crazy the closer we get!
I’m trying to differentiate between Reduce, Map and Apply
Thanks!
Hah, @joshua.d.horwitz, your life is about to change in a way you cannot even imagine. The first few months are incredible and fleeting so memorize, document, and journal every day. You’ll appreciate it later.
@akiva: I’m freaking out!
@joshua.d.horwitz, this is probably better off in #C03RZGPG3 but I highly recommend reading https://happiestbaby.com/product/the-happiest-baby-book-paperback/ and http://www.amazon.com/Sleep-Lady®%C2%92s-Good-Night-Tight/dp/1593155581/ref=sr_1_1?s=books&ie=UTF8&qid=1455634800&sr=1-1&keywords=sleep+lady+good+night+sleep+tight.
@akiva: That is great! Thanks for the advice, I’m going to get both, need all the help I can get!
@joshua.d.horwitz: Listen to your intuition and especially your wife's intuition. And forget about sleep for the next 13 years at least 😉
different one for every day of the week?
might have better luck with bear traps 😛
Hahaha. And anti-personnel landmines. And a moat that even Leinigen’s ants can’t cross.
what is wrong with this?: (apply js/Date. [2011 4 3])
is it not possible to use apply with a js function, or is ist something else i am doing wrong?
@thomasdeutsch: It appears to be a JavaScript restriction. new
and apply
don’t seem to mix the way you’re expecting it to
http://stackoverflow.com/questions/1606797/use-of-apply-with-new-operator-is-this-possible
I would recommend using cljs-time for working with dates https://github.com/andrewmcveigh/cljs-time
i do not need that lib I did not know about this js restriction. thank you @solicode !