I'm not sure if anyone's already done this, but I recently got tired of
writing code that looked like this:
(let [a 1]
(ns cljutils.core)
(defn- form-check
Ensures the form represents an assignment.
Such as (:= a 1)
[form]
(and
(= 3 (count form))
(= := (first form))
(symbol?
I'm not sure if anyone's done this before, but I'm fed up with writing code
that looks like this:
(let [a 1]
(println this is a: a)
(let [b 2]
(println this is b: b)
(let [c 3]
(println this is c: c)
(+ a b c
I'd rather do something more like
On Thu, Oct 18, 2012 at 12:01 PM, JvJ kfjwhee...@gmail.com wrote:
I'm not sure if anyone's done this before, but I'm fed up with writing
code that looks like this:
What problem does this solve given you can do the following?
(let [a 1
_ (println a)
b 2
_ (println b)
c
I'm confused. How does the following not work?
(let [a 1 b 2 c 3]
(println a)
(println b)
(println c)
(+ a b c))
On Thursday, October 18, 2012 5:01:33 PM UTC+1, JvJ wrote:
I'm not sure if anyone's done this before, but I'm fed up with writing
code that looks like this:
(let [a 1]
On Thu, Oct 18, 2012 at 9:12 AM, keeds akee...@gmail.com wrote:
I'm confused. How does the following not work?
(let [a 1 b 2 c 3]
(println a)
(println b)
(println c)
(+ a b c))
It works, but all of the expressions on the RHS of the let
expression's binding vector have to be applied
I didn't realize you could bind to empty identifiers like that. Alright,
that makes more sense. I figured I was missing something.
On Thursday, 18 October 2012 12:11:49 UTC-4, David Nolen wrote:
On Thu, Oct 18, 2012 at 12:01 PM, JvJ kfjwh...@gmail.com javascript:wrote:
I'm not sure if
Exactly. A big part of the reason was that I needed to do things between
when other variables were initialized.
On Thursday, 18 October 2012 12:17:17 UTC-4, Ben wrote:
On Thu, Oct 18, 2012 at 9:12 AM, keeds ake...@gmail.com javascript:
wrote:
I'm confused. How does the following not
On Thu, Oct 18, 2012 at 12:23 PM, JvJ kfjwhee...@gmail.com wrote:
I didn't realize you could bind to empty identifiers like that. Alright,
that makes more sense. I figured I was missing something.
Just to be clear _ has not special meaning beyond convention. I could have
used x but that
There's nothing special going on, no empty identifiers. It's just a
common convention to use _ when uninterested in the return value.
(let [_ 1]
_)
;= 1
Pretty evil to actually use bindings called _ though :)
Thanks,
Ambrose
On Fri, Oct 19, 2012 at 12:23 AM, JvJ kfjwhee...@gmail.com wrote:
Thank you for this clarification!
On Thu, Oct 18, 2012 at 6:26 PM, David Nolen dnolen.li...@gmail.com wrote:
On Thu, Oct 18, 2012 at 12:23 PM, JvJ kfjwhee...@gmail.com wrote:
I didn't realize you could bind to empty identifiers like that. Alright,
that makes more sense. I figured I was
For the situation where the lets are nested because you're checking the
values in some way after each binding, I wrote a macro called let?. I find
it very useful and use it in nearly all my
code. https://github.com/egamble/let-else
--
You received this message because you are subscribed to
On Thu, Oct 18, 2012 at 11:11 AM, David Nolen dnolen.li...@gmail.com wrote:
On Thu, Oct 18, 2012 at 12:01 PM, JvJ kfjwhee...@gmail.com wrote:
I'm not sure if anyone's done this before, but I'm fed up with writing
code that looks like this:
What problem does this solve given you can do the
It's rare to get tired of this, because nobody does it: it's not
common because your interleaved statements are side-effecting only,
which is not encouraged in Clojure, and rarely needed. Certainly
sometimes it's the best way to do something, but not so often that I'd
become frustrated; if
On Thu, Oct 18, 2012 at 1:55 PM, Alan Malloy a...@malloys.org wrote:
It's rare to get tired of this, because nobody does it: it's not
common because your interleaved statements are side-effecting only,
which is not encouraged in Clojure, and rarely needed. Certainly
sometimes it's the best way
On Thu, Oct 18, 2012 at 2:55 PM, Alan Malloy a...@malloys.org wrote:
It's rare to get tired of this, because nobody does it: it's not
common because your interleaved statements are side-effecting only,
which is not encouraged in Clojure, and rarely needed. Certainly
sometimes it's the best
On Thu, Oct 18, 2012 at 1:32 PM, Grant Rettke gret...@acm.org wrote:
On Thu, Oct 18, 2012 at 11:11 AM, David Nolen dnolen.li...@gmail.com wrote:
On Thu, Oct 18, 2012 at 12:01 PM, JvJ kfjwhee...@gmail.com wrote:
I'm not sure if anyone's done this before, but I'm fed up with writing
code that
On Thu, Oct 18, 2012 at 3:06 PM, Grant Rettke gret...@acm.org wrote:
(- ((fn []
(let [a 1]
(println this is a: a)
a)))
((fn [a]
(let [b 2]
(println this is b: b)
(list a b
((fn [[a b]]
(let [c 3]
(println this is c:
On Thu, Oct 18, 2012 at 12:01 PM, Grant Rettke gret...@acm.org wrote:
On Thu, Oct 18, 2012 at 1:55 PM, Alan Malloy a...@malloys.org wrote:
It's rare to get tired of this, because nobody does it: it's not
common because your interleaved statements are side-effecting only,
which is not
On Thu, Oct 18, 2012 at 2:07 PM, David Nolen dnolen.li...@gmail.com wrote:
On Thu, Oct 18, 2012 at 3:06 PM, Grant Rettke gret...@acm.org wrote:
(- ((fn []
(let [a 1]
(println this is a: a)
a)))
((fn [a]
(let [b 2]
(println this is b: b)
On Thu, Oct 18, 2012 at 2:09 PM, Ben Wolfson wolf...@gmail.com wrote:
On Thu, Oct 18, 2012 at 12:01 PM, Grant Rettke gret...@acm.org wrote:
It isn't side effecting it is sequencing.
Clojure's let is already sequential, like Scheme's let*: The bindings
are sequential, so each binding can see
On Oct 18, 12:02 pm, David Nolen dnolen.li...@gmail.com wrote:
On Thu, Oct 18, 2012 at 2:55 PM, Alan Malloy a...@malloys.org wrote:
It's rare to get tired of this, because nobody does it: it's not
common because your interleaved statements are side-effecting only,
which is not encouraged in
When I want to add print commands for debugging, I usually either do it the
way David Nolen described, i.e., binding _ to a printf statement, or I use
a little utility macro like this (picked up from stackoverflow):
(defmacro dbg[x] `(let [x# ~x] (println dbg: '~x = x#) x#))
I agree with Evan
On Thu, Oct 18, 2012 at 2:50 PM, Mark Engelberg
mark.engelb...@gmail.com wrote:
Either way works well. I think Evan's way results in somewhat more compact
code for the common case, whereas Cgrand's way feels a little more versatile
(and his flatter cond is what I use). I strongly urge you to
On Thu, Oct 18, 2012 at 4:15 PM, Grant Rettke gret...@acm.org wrote:
On Thu, Oct 18, 2012 at 2:50 PM, Mark Engelberg
mark.engelb...@gmail.com wrote:
Either way works well. I think Evan's way results in somewhat more
compact
code for the common case, whereas Cgrand's way feels a little
On Thu, Oct 18, 2012 at 3:17 PM, David Nolen dnolen.li...@gmail.com wrote:
On Thu, Oct 18, 2012 at 4:15 PM, Grant Rettke gret...@acm.org wrote:
On Thu, Oct 18, 2012 at 2:50 PM, Mark Engelberg
mark.engelb...@gmail.com wrote:
Either way works well. I think Evan's way results in somewhat more
On Thu, Oct 18, 2012 at 4:22 PM, Grant Rettke gret...@acm.org wrote:
When you use def inside a defn is it equivalent to a let binding like this?
(defn foo []
(def a 1)
(println a))
(defn foo []
((fn [a]
(println a)) 1))
Not equivalent.
--
You received this message because
On Thu, Oct 18, 2012 at 3:32 PM, David Nolen dnolen.li...@gmail.com wrote:
On Thu, Oct 18, 2012 at 4:22 PM, Grant Rettke gret...@acm.org wrote:
When you use def inside a defn is it equivalent to a let binding like
this?
(defn foo []
(def a 1)
(println a))
(defn foo []
((fn [a]
A def, even inside defn, creates and binds a global variable.
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
On Thu, Oct 18, 2012 at 3:42 PM, Mark Engelberg
mark.engelb...@gmail.com wrote:
A def, even inside defn, creates and binds a global variable.
Woa, I see, thanks!
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to
On Thu, Oct 18, 2012 at 3:45 PM, Grant Rettke gret...@acm.org wrote:
On Thu, Oct 18, 2012 at 3:42 PM, Mark Engelberg
mark.engelb...@gmail.com wrote:
A def, even inside defn, creates and binds a global variable.
Woa, I see, thanks!
Anyone voted for internal define lately?
--
You received
On Thu, Oct 18, 2012 at 4:45 PM, Grant Rettke gret...@acm.org wrote:
On Thu, Oct 18, 2012 at 3:45 PM, Grant Rettke gret...@acm.org wrote:
On Thu, Oct 18, 2012 at 3:42 PM, Mark Engelberg
mark.engelb...@gmail.com wrote:
A def, even inside defn, creates and binds a global variable.
Woa, I
Exactly. Not only debugging, but java interop that involved calling
methods with side effects.
On Thursday, 18 October 2012 15:02:47 UTC-4, David Nolen wrote:
On Thu, Oct 18, 2012 at 2:55 PM, Alan Malloy al...@malloys.orgjavascript:
wrote:
It's rare to get tired of this, because nobody
I figured you would use doto for that.
On Thu, Oct 18, 2012 at 4:09 PM, JvJ kfjwhee...@gmail.com wrote:
Exactly. Not only debugging, but java interop that involved calling methods
with side effects.
On Thursday, 18 October 2012 15:02:47 UTC-4, David Nolen wrote:
On Thu, Oct 18, 2012 at
On Thu, Oct 18, 2012 at 4:05 PM, David Nolen dnolen.li...@gmail.com wrote:
On Thu, Oct 18, 2012 at 4:45 PM, Grant Rettke gret...@acm.org wrote:
Anyone voted for internal define lately?
At this point I think it's highly unlikely to change - the behavior is
pretty well documented:
I see. Just a
On a side note, I was partially inspired by Haskell's do notation, which is
imperative-looking syntactic sugar for monadic binds.
On Thursday, 18 October 2012 12:01:33 UTC-4, JvJ wrote:
I'm not sure if anyone's done this before, but I'm fed up with writing
code that looks like this:
(let
On a side note, I was partially inspired by Haskell's do notation, which is
imperative-looking syntactic sugar for monadic bind operators.
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Most of what could be accomplished by an internal define could be done with
a let statement. But if you don't want to add the brackets, you can create
your own function definition macro that converts defs to lets.
On Thursday, 18 October 2012 17:12:04 UTC-4, Grant Rettke wrote:
On Thu, Oct
The doto form is great, but as far as I know, it only lets you thread a
single object. I'm looking at creating several objects consecutively.
On Thursday, 18 October 2012 17:11:08 UTC-4, Grant Rettke wrote:
I figured you would use doto for that.
On Thu, Oct 18, 2012 at 4:09 PM, JvJ
On Thu, Oct 18, 2012 at 1:45 PM, Grant Rettke gret...@acm.org wrote:
Anyone voted for internal define lately?
On the one hand, internal define would be nice because it would help
alleviate the nested let problem and possibly be more intuitive for
newcomers.
On the other hand, sometimes
deja-vu :)
On Thu, Oct 18, 2012 at 11:16 PM, JvJ kfjwhee...@gmail.com wrote:
On a side note, I was partially inspired by Haskell's do notation, which
is imperative-looking syntactic sugar for monadic bind operators.
--
You received this message because you are subscribed to the Google
It's slightly different, but libraries such as Flow or Prismatic's Graph
can be used to achieve a similar effect.
Flow: https://github.com/stuartsierra/flow
Graph:
http://blog.getprismatic.com/blog/2012/10/1/prismatics-graph-at-strange-loop.html
Example using Flow:
(def the-flow
(flow b
2012/10/18 Mark Engelberg mark.engelb...@gmail.com
When I want to add print commands for debugging, I usually either do it
the way David Nolen described, i.e., binding _ to a printf statement, or I
use a little utility macro like this (picked up from stackoverflow):
(defmacro dbg[x] `(let
On Thu, Oct 18, 2012 at 4:11 PM, Herwig Hochleitner
hhochleit...@gmail.comwrote:
FWIW, when just wanting to print out debug values, I use a custom reader
tag similar to the above macro:
(let [x #log/spy (+ a b)]
(usage-of x))
That's nice! I haven't done anything with reader macros.
OK, just looked it up and realized that it's just how # works, and not a
special kind of macro.
On Thu, Oct 18, 2012 at 5:25 PM, Mark Engelberg mark.engelb...@gmail.comwrote:
On Thu, Oct 18, 2012 at 4:11 PM, Herwig Hochleitner
hhochleit...@gmail.com wrote:
FWIW, when just wanting to print
44 matches
Mail list logo