Re: lein cljsbuild once works, but another build method doesn't -- ?

2015-12-28 Thread Erik Price
The -cp flag should be passed a colon-separated list of entires to search
for dependency code. Each entry in the list can be either a directory (in
which case the contents of the directory must immediately contain Java or
Clojure source files) or a JAR file. So the command you’re currently using
says “look for dependencies in the cljs.jar file and the src directory”.

Leiningen downloads and locally caches the dependencies you list in your
project.clj for you. If you’re sure those dependencies have already been
downloaded to your system, try including the paths to those dependencies’
JAR files in your -cp argument.

e
​

On Mon, Dec 28, 2015 at 5:54 PM,  wrote:

> hi
>
> I have a ClojureScript project. It builds successfully with lein
> cljsbuild once and I'm able to run my program on node.
>
> I'm trying to follow the QuickStart guide for getting a node REPL.
>
> I have node.clj
> (require 'cljs.build.api)
>
> (cljs.build.api/build "src"
>   {:main 'hello-world.core
>:output-to "main.js"
>:target :nodejs})
>
> But when I run java -cp cljs.jar:src clojure.main node.clj
>
> It says: No such namespace and refers to a dependency that I've listed in
> project.clj. Do I need to add something to the -cp argument when I call
> java?
>
> Thanks in advance for any help!
>
> --
> 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 first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Clojure Dev Environment

2015-10-05 Thread Erik Price
vim-fireplace lets you compile individual S-expressions into an existing
nREPL (one in which the rest of your code is typically also loaded and
available), so I typically make all my code changes right in the editor
against the actual file I'm working on. Then I just compile the function
I'm editing and send it to the REPL. I'll usually just add a comment block
near the changes I'm making and put test expressions inside of it, and
execute those expressions as needed to test my changes. It's awesome.

(Of course, I delete that comment block prior to committing my work.)

e

On Monday, October 5, 2015, Robin Heggelund Hansen 
wrote:

> Basically, I use stuart sierra's tools.namespace and component libraries
> to write an application that can be easily reloaded. So I write my code in
> regular files, then i tell the repl to reload my application with the
> latest changes from disk. I can also test the application while it's
> running, because I have access to every function. Hot-replacement is a
> matter of calling 'reset. Although that does technically shut down the
> application, so maybe it can't be called "hot".
>
> Anyway, you can read more here: https://github.com/stuartsierra/component
>
> --
> 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 first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Origin for Clojure using the term 'vector' instead of 'array'?

2015-10-03 Thread Erik Price
I always assumed it was because vectors have similar properties to the
classic java.util.Vector: they’re variable-length, contain heterogenous
objects accessible by integer index, and safe for concurrent access from
multiple threads:
http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html

e
​

On Fri, Oct 2, 2015 at 11:46 PM, Mars0i  wrote:

> I have no idea about the official reason, but outside of certain
> programming languages that use "array" for one-dimensional data structures,
> an array often has two (or more) dimensions.  In R, for example, arrays can
> have an arbitrary number of dimensions.  Honestly, when I'm away from Java
> for a while and then encounter the term "array" in Java, I have to stop and
> remember that it's 1-D, or check some documentation, because "array"
> doesn't automatically mean 1-D to me.
>
> On the other hand, I believe that vectors are always one-dimensional, as
> in linear algebra.
>
> So maybe Rich Hickey just decided that "vector" was a better, less
> ambiguous name.
>
> --
> 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 first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Opinion on core.async vs callbacks in abstract APIs?

2015-06-02 Thread Erik Price
On Tue, Jun 2, 2015 at 3:17 AM, Christopher Small metasoar...@gmail.com
wrote:

Additionally, I feel it worth responding to some of Timothy's comments
 about the difficulty of getting a core.async centric API right. While I
 agree that in general (and particular with more complicated APIs) getting
 things right can be tricky, the situation I'm dealing with (I think) can be
 dealt with quite simply. Imagine a stream of events coming in from The Real
 World (TM), and that we'd like to process somehow. The solution I've been
 chewing on is a function that let's us specify a single channel on which
 events should be placed. The nice thing about this is that it assumes
 almost nothing about how you'll use core.async, only that you'll be using
 it. You can decide whether you want a buffer or not, whether it should drop
 or slide or block/park, whether it should be tapped, etc.

I like and use core.async, but this sounds like something that I might want
to handle with a compositional event system like RxJava. A simple
callback-based API would suffice for that.

The potentially nice thing about core.async for this use case over
 callbacks (as far as the implementation is concerned) is that should we
 decide to stop listening to events, we can just close! the channel. This
 can then serve as a signal to the underlying code/process actually reading
 in events that it can stop. With callbacks, it will probably be necessary
 to have something that manages these processes and listens for kill
 signals, potentially complicating things quite a bit. (It's possible there
 is an elegant solution here, and I haven't thought about it too much yet,
 but this is my current intuition...)

Good point. CES systems that I’ve used have a first-class notions of
“stream complete” and “stream errored”, which is even more expressive than
core.async‘s “send nil“. If your API offered three separate callbacks (one
for each of those conditions and one for values, with the invariant that if
either the “stream complete” or “stream errored” callback fires for a
stream, no further callbacks will be invoked), it would be pretty easy for
a user to map them to their CES equivalents, and if someone prefers to work
in core.async, they can send whatever value they wish on the channel,
followed by nil.

e
​

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Opinion on core.async vs callbacks in abstract APIs?

2015-06-02 Thread Erik Price
Oh, so the events are for all intents and purposes infinite?

On Tue, Jun 2, 2015 at 11:10 AM, Christopher Small metasoar...@gmail.com
wrote:

 @Erik: I should clarify in this situation, the _user_ of the API would
 decide whether they want to stop listening to events. So there's not so
 much that _they_ would have to specify in terms of shutdown routines. I'm
 more concerned about how API implementations get notified that they don't
 need to deal with new events.

  --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: separation of concerns w/o encapsulation

2015-05-14 Thread Erik Price
On Thu, May 14, 2015 at 12:14 PM, Sean Corfield s...@corfield.org wrote:


 In an environment where you can’t trust your co-workers(!), you certainly
 want to hide *mutable* data so they can’t modify your objects’ state. When
 you remove mutability, there’s a lot less damage they can do and they it’s
 really more about which pieces of the system do you not want them to use
 (in terms of functional APIs).


The code itself is mutable. The nice thing about a private function is that
I have reserved the right to change how it works someday, without fear that
others have become dependent on the way it currently works.

e

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: contains? on String

2015-05-13 Thread Erik Price
 (get the char at index 4)
\c

e
​

On Wed, May 13, 2015 at 9:55 PM, Sam Raker sam.ra...@gmail.com wrote:

 I always assumed (contains? foo 2) worked because strings are arrays
 (i.e.  vectors) of characters, on some level.

 --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Anyone Worked with NW.js and ClojureScript

2015-04-07 Thread Erik Price
These are cool too:

https://github.com/frankhale/hello-atom-shell
https://github.com/oakmac/cuttle/

e

On Tue, Apr 7, 2015 at 8:03 AM, JPatrick Davenport virmu...@gmail.com
wrote:

 Well don't that beat all? Thanks. It looks good.

 If anyone else wants to add something, please do.


 On Tuesday, April 7, 2015 at 7:10:42 AM UTC-4, jaju wrote:

 You probably want to look at Assistant (https://github.com/29decibel/
 assistant) as an example.

 It uses lein-node-webkit-build (https://github.com/
 wilkerlucio/lein-node-webkit-build) - a lein plugin to build a shell app.

 Probably what you are looking for?

 Best,
 jaju

 On Tue, Apr 7, 2015 at 4:11 PM, JPatrick Davenport virm...@gmail.com
 wrote:

 Hello,
 I recently started looking at a project that's all about being offline.
 I thought about using Java + Clojure + JavaFX as my implementation path,
 but I fear that there's a security backlash against client side Java these
 days. Mulling it over, I thought, wouldn't it be terrifying to use some
 sort of shelled web project using ClojureScript to implement the
 application?

 To that end, has anyone done anything like that? I couldn't find a
 plugin for lein to build the shell app.

 Thanks,
 JPD

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+u...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


  --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: is ok use a blocking get !! at the end of sequence of async calls

2015-03-25 Thread Erik Price
There is no best approach for this. Yes, you do end up blocking the request
thread, but that’s what needs to happen if you the response requires the
value returned by the channel. You can’t return a response to the browser
and then change it later when the channel sends its value. (You’d have the
same problem with Rx, btw.)

The closest equivalent to Rx’s complete event is that a channel is closed
(in which case anything blocked or parked on that channel will receive nil).

e
​

On Wed, Mar 25, 2015 at 12:08 AM, coco clasesparticulares...@gmail.com
wrote:

 Hi guys...I've a code similar to this:

 (defn user-data []
   (!/go
 (let [a (!/! (fun-async 2))
   b  (!/! (fun-async a))]
   {:response b})))

 (defn handler-something []
   (let [data (!/!! (user-data))] ;;block here
 (print data)
 (response  data..)))

 user-data do a sucession of async calls and return a channel (because it's
 inside a go block no?)
 my handler-something need extract this data and return it in a ring
 response...I can wrap my response function inside a go block, if I do this
 I get

 java.lang.IllegalArgumentException: No implementation of method: :render
 of protocol: #'compojure.response/Renderable found for class:
 clojure.core.async.impl.channels.ManyToManyChannel

 so basically I use a block get !! and then return the data...I'm more
 familiar with FRP and in FRP I would use a onComplete method which
 basically do the same as !!

 this pattern is correct or I'll end blocking code?...which could be the
 best approach for this?..thanks!


  --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Border cases for doseq

2015-02-25 Thread Erik Price
Another way to structure this problem is as sequences:

   1. Start with a sequence of tables. (show-tables db-spec)
   2. Filter down to only the tables you care about. (filter my-pred
   tables-seq)
   3. Take only the first of these. (take 1 filtered-tables-seq)
   4. If there is a table, do your side effects with it. (doseq [t
   0-or-1-filtered-tables] (...))

That way, you will only do the work zero or one times, but the depth of
your code is much shallower, and easier to read.

e
​

On Wed, Feb 25, 2015 at 1:35 PM, Cecil Westerhof cldwester...@gmail.com
wrote:

 2015-02-25 19:23 GMT+01:00 Aaron Cohen aa...@assonance.org:

 On Wed, Feb 25, 2015 at 1:08 PM, Cecil Westerhof cldwester...@gmail.com
 wrote:



 2015-02-25 18:14 GMT+01:00 Andy Fingerhut andy.finger...@gmail.com:

 doseq does not have anything precisely like C/Java/Perl/etc.'s 'break'
 or 'continue'.  The closest thing might be the :while keyword.  You can see
 some one example of its use near the end of the examples on this page:
 http://clojuredocs.org/clojure.core/doseq

 The best way I know to get such behavior is to use Clojure's loop,
 where if/when/whatever-conditional-statements-you-wish can used to control
 explicitly to do another loop iteration using recur, or not.


 ​I made the following with loop:
 (defn do-show-table
   [table]
   (loop [all-tables (show-tables db-spec)]
 (let [this-table (get (first all-tables) :table_name)]
   (if (= all-tables ())
   (printf Table not found: %s\n table)
 (if (= (lower-case table) (lower-case this-table))
 (let [format %-20s %-30s %-5s %-5s %-20s\n]
   (printf Table %s:\n table)
   (printf format Field Type Null? Key Default)
   (doseq [{:keys [field type null key default]}
  (jdbc/query db-spec [(str SHOW COLUMNS FROM 
 table)])]


 Please don't get into the habit of doing db queries like this, you're one
 Little Bobby Tables away from an sql injection. In this case you should
 do (jdbc/query db-spec [SHOW COLUMNS FROM ? table]).


 ​That gives:
 JdbcSQLException Syntax error in SQL statement SHOW COLUMNS FROM ?;
 expected identifier; SQL statement:
 SHOW COLUMNS FROM ? [42001-184]  org.h2.engine.SessionRemote.done
 (SessionRemote.java:622)
 ​

 ​That is why I do it in this way. As I understood it this has to do with
 that with a 'show columns from' the table can not be supplied. (I first
 tried Yesql, only when that did not work I went to JDBC.)​




 I think you would be well-served by a general clojure principle here of
 trying to get the data you're are dealing within into values as quickly
 as possible, and then working with those.

 Rather than inter-mixing your querying and display as you're doing here,
 I would design this as a query to fill some maps describing your tables,
 and then use clojure.pprint/print-table to print out the resulting map when
 desired.


 ​This was just a proof of concept to get things working in the REPL. Later
 on it should be done much neater. (For example a text​

 ​based version and a GUI version.)​



  (printf format field type null key default))


   (println))
   (recur (rest all-tables)))

 It solves both problems.


 On Wed, Feb 25, 2015 at 8:59 AM, Cecil Westerhof cldwester...@gmail.com
  wrote:

 At the moment I have the following function:
 (defn do-show-table
   [table]
   (doseq [{:keys [table_name]} (show-tables db-spec)]
  (when (= (lower-case table) (lower-case table_name))
(let [format %-20s %-30s %-5s %-5s %-20s\n]
  (printf format Field Type Null? Key Default)
  (doseq [{:keys [field type null key default]}
   (jdbc/query db-spec [(str SHOW COLUMNS FROM
  table)])]
 (printf format field type null key
 default))

 In this case it is not very important, because the outer sequence will
 not be very big. But I would like to leave the doseq at the moment that 
 the
 when is executed. It will be done 0 or 1 times, so after it is done, there
 is no use in continuing the sequence walk.

 The second part is that I would like to do an action if it is done 0
 times after the doseq. Is this possible?


 --
 Cecil Westerhof

 --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to 

Re: Current best-of-breed JDBC libraries?

2015-02-24 Thread Erik Price
We tried Korma but found it too limiting for our needs. Later, I saw this
tweet:

https://twitter.com/ibdknox/status/557236505639665664

We are currently using HoneySQL to generate SQL which then gets passed to
clojure.java.jdbc.

e
​

On Tue, Feb 24, 2015 at 9:04 AM, Colin Yates colin.ya...@gmail.com wrote:

 Hi all,

 What are you all using for interacting with an RDBMS? In the past I looked
 at clojure.java.jdbc, honeysql and korma (and for querying, honeysql just
 rocks). I have lost touch a bit - any recommendations?

 Thanks.

 --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to stop a long running expression in the REPL

2015-02-23 Thread Erik Price
Vim Fireplace https://github.com/tpope/vim-fireplace supports Ctrl-c
without killing its REPL host. Highly recommended if you are a Vim user.

e
​

On Sat, Feb 21, 2015 at 7:32 AM, Shawn Rasheed unsh...@gmail.com wrote:

 If it's the clojure repl this might work:
 https://clojuredocs.org/clojure.repl/set-break-handler!

 On Sat, Feb 21, 2015 at 5:28 PM, Lucas Bradstreet 
 lucasbradstr...@gmail.com wrote:

 Which repl are you using? In lein repl, this does not happen to me, it
 just terminates the expression.

 On 21 February 2015 at 19:45, Cecil Westerhof cldwester...@gmail.com
 wrote:
  Sometimes I execute something that takes to long. With Ctrl-C I can
 cancel
  it, but this also cancels the REPL itself. Is there a way to terminate
 the
  running command without terminating the running REPL?
 
  --
  Cecil Westerhof
 
  --
  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
  first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google
 Groups
  Clojure group.
  To unsubscribe from this group and stop receiving emails from it, send
 an
  email to clojure+unsubscr...@googlegroups.com.
  For more options, visit https://groups.google.com/d/optout.

 --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.




 --
 ---sr

 --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: core.async: Deprecated - this function will be removed. Use transducer instead

2015-02-18 Thread Erik Price
(let [out (async/chan 0 (map inc))]
  (async/pipe in out)
  out)

Earlier in your email you mention printing, however. If you have I/O to
perform (like printing), I’m told that you don’t want to do it in a
transducer. You can use pipeline-async for this instead:

(defn f [v ch]
  (async/go
(println v)
(async/! ch v)))

(let [out (async/chan)]
  (async/pipeline-async 1 out f in)
  out)

(If I’m doing this wrong, someone please steer me in the right direction.)

e

On Wed, Feb 18, 2015 at 4:47 PM, Ben Smith-Mannschott bsmith.o...@gmail.com
wrote:

I'm probably just especially dense today, but perhaps someone can give me a
 poke in the right direction.

 I'm trying to wrap my head around transducers.

 (1) For debugging purposes I'd like to be able to consume the values on a
 channel and put them in a collection to be printed.

 I'm doing this at the REPL:

 (async/!! (async/into [] channel))

 This seems needlessly clunky. Is this really the best way to accomplish
 this?

 (2) async/map is deprecated, what's the alternative, exactly?

 (let [ch (async/to-chan [1 2 3])]
   (async/map inc ch))

 AFAICT this would produce a channel, which when consumed would yield the
 values 2 3 4, correct?

 Now I suppose if I didn't already have the channel ch, I could create one
 with an associated transformation function, and then stuff the values 1 2 3
 into it somehow, right?

 (let [ch (async/chan nil (map inc))]
   (async/onto-chan ch [1 2 3])
   ch)
 ;; returns a channel yielding items 2, 3, 4

 But, I'm not clear at all how I can apply the operation (inc) to the all
 values yielded by a channel I already have in my hand.

 Any help would be appreciated. I feel like I'm missing some critical bit
 of insight and that async and transducers might just fall into place for me
 if I could only find out what that bit is.

 // Ben

 --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

​

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: core.async -- lazy evaluation on take

2015-02-16 Thread Erik Price
Yes, the producer’s put will block until the consumer takes, but doesn’t
this still involve an eager initial request (so that the producer will have
something to put in the first place, so that it can block)?

e
​

On Mon, Feb 16, 2015 at 5:52 PM, janpaulbultm...@googlemail.com wrote:

 Make the channel unbuffered, that way it turns into a rondevouz a la ada
 and every producer will block until a consumer takes something from it.

 cheers Jan

 On 16.02.2015, at 21:45, Huey Petersen eys...@gmail.com wrote:

 Hello,

 I was playing around with having a lazy sequence abstracting over a paged
 http request.  First off, maybe this is dumb, I dunno, lemme know ;p

 So (resources url) returns a seq and no http request is made, but (take
 1 (resources url)) makes a request and (take 50 (resources url)) may
 make multiple requests (depending on how many per page).

 I'm wondering if it is possible to implement the same thing as a channel
 -- no http request is made until someone tries to take from it.  More of a
 curiosity.

 Thanks!

 --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

  --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: simple procedure for updating a value one level down

2015-01-26 Thread Erik Price
Many functions that affect keyed collections will work on vectors if you
supply the numeric index as a key.

e

On Monday, January 26, 2015, Josh Stratton strattonbra...@gmail.com wrote:

 I'm new to clojure and FP in general.  One thing that has always been a
 little confusing for me is working with immutable trees.  I have a vector
 of categories, each category containing a vector of items--each one a
 hashmap.  In that hashmap I have a bunch of attributes including an
 item-id.  Now, assuming I have an item id, what's the easiest way to update
 the appropriate hashmap?  I can't use an assoc, I believe, because my data
 is in a vector--not keyed by the id.

 What I have been doing is writing a function that maps the categories to
 new categories and then write another function that is called on every item
 and updates it iff the item id matches.  This works, but it seems really
 clunky and I'm assuming there's a simpler way to do it.

 ; categories is a vector of item vectors, where the item is a hash
 (def categories [ [ { :id 1 :text foo } { :id 2 :text bar :ack 5 } ] [
 { :id 3 :age 7 } ] ])

 Is there a more elegant workflow for updating categories?  Let's say I
 want to update item of id 3 with { :age 12 :somethingElse 29 }, what's the
 easiest way to do this?

 ; so the return would be
 [ [ { :id 1 :text foo } { :id 2 :text bar :ack 5 } ] [ { :id 3 :age 12
 :somethingElse 29 } ] ]

 --
 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
 javascript:_e(%7B%7D,'cvml','clojure@googlegroups.com');
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com');
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com
 javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com');.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: channels operations

2015-01-10 Thread Erik Price
Not sure if it’s “proper”, but you could just alts! twice on all three
channels:

(let [[_ p1] (alts! [player1-ch player2-ch timeout-ch])
  [_ p2] (alts! [player1-ch player2-ch timeout-ch])]
  (cond
(= p1 timeout-ch) No players played.
(= p2 timeout-ch) (str p1  played, and the other player did not play.)
:else Both players played before timeout.))

e
​

On Sat, Jan 10, 2015 at 12:53 PM, Jeremy Vuillermet 
jeremy.vuiller...@gmail.com wrote:

 Hi,

 I'm learning core.async with a game I'm developing.
 This is a one on one game where players have 5 seconds to play. If only
 one has played before 5 seconds, he is the winner. If none has played, I
 randomly choose a winner.

 I have 3 channels, player1-channel, player2-channel and timeout-channel.
 Although I know I can use alts! to detect the timeout like
 (alts! [player1-channel player2-channel timeout-channel])

 I won't be able to detect the case when only 1 player has played.

 I can't think of a proper way to do this. Any idea ?

 Thanks

 --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Prefer non-daemon threads in clojure.core.async/thread?

2015-01-07 Thread Erik Price
Howdy,

I see that the ThreadFactory used by clojure.core.async/thread‘s Executor
accepts a daemon parameter, to specify whether the threads are daemon or
not. But from reading the source, I don’t see any obvious way to specify
this for individual calls to clojure.core.async/thread. Is it possible?

Thanks!

e
​

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: beginner (fn) doubt

2015-01-03 Thread Erik Price
((fn [x] (* 5 x)) 5)

is the same as

(def my-function
(fn [x] (* 5 x)))
(my-function 5)

​

On Fri, Jan 2, 2015 at 8:13 PM, novato biofob...@gmail.com wrote:

 I choose clojure as my first programming language after some research. I
 am learning by doing Clojure Koans http://clojurekoans.com/ exercises.
 I reached to the functions lesson and I have a doubt on the following
 code:
 ((fn [x] (* 5 x)) 5)

 Why is that the last 5 is outside the fn parentheses? Why this doesn't
 work?
 (fn [x] (* 5 x) 5)

 Thanks in advice for the clarification and excuse my poor english.

 --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Please critique my code (barber problem with core.async)

2015-01-02 Thread Erik Price
 ;(async/timeout (* 10 1000)) ;; not sure why this doesn’t work here, would
make it portable to clojureScript I think

Did you forget to use ! on that line?


e
​

On Fri, Jan 2, 2015 at 11:04 AM, Thomas th.vanderv...@gmail.com wrote:

 Happy New to all of you!!!

 Recently I came across the barber problem (again) and while reading it I
 thought that code.async would be ideal for this kind of problem. Below is
 the code I have come up with. I think it does the trick but I am not
 entirely happy with it, for instance the fact that I use the two atoms as
 counters. I also wonder if there is a better way to time the ten seconds,
 something instead of the atom.

 So please critique the code below, any comments, improvements,
 obfuscations etc. are welcome!!

 Thomas


 (ns barber.core
   (:require [clojure.core.async :as async]))

 ;; A barber shop takes customers
 ;; Customer arrive at random intervals, from ten to thirty milliseconds
 ;; The barber shop has three chairs in the waiting room
 ;; The barber shop has one barber and one barber chair
 ;; When the barber's chair is empty, a customer sits in the the chair
 ;;   wakes up the barber, and gets a haircut.
 ;; If the chairs are occupied , all new customer will turn away
 ;; Haircuts takes twenty milliseconds
 ;; After a customer receives a haircut, he gets up and leaves.
 ;;
 ;; Write a program that determines how many haircuts a barber can
 ;;   give in ten seconds.

 (def running (atom false))
 (def counter1 (atom 0))
 (def counter2 (atom 0))

 (defn customers []
   (let [c (async/chan (async/dropping-buffer 3))]
  (async/go
   (while @running
 (async/! (async/timeout (+ 10 (rand-int 21
 (async/! c (swap! counter1 inc
 c))

 (defn barber [c]
   (async/go
(while true
  (let [r (async/! c)]
(async/! (async/timeout 20))
;(println r)
(swap! counter2 inc)

 (comment
   (reset! counter1 0)
   (reset! counter2 0)
   (reset! running true)
   (barber (customers))
   (Thread/sleep (* 10 1000))
   ;(async/timeout (* 10 1000)) ;; not sure why this doesn't work here,
 would make it portable to clojureScript I think
   (reset! running false)
   (println (str Served  @counter2  customers out of  @counter1 
 possible customers))
 )

  --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ClojureScript] Re: [ANN] cuerdas 0.1.0: A string manipulation library for clojure and clojurescript.

2014-12-24 Thread Erik Price
Note that there is precedent for this in clojure.string/blank?
http://clojuredocs.org/clojure.string/blank_q.
​

On Wed, Dec 24, 2014 at 7:58 AM, Andrey Antukh n...@niwi.be wrote:

 Hi!

 Thank you very much!

 You are right about nil handling, it should be documented and proper
 handled.

 But I'm not completely convinced with ruby behavior for that, in many
 other implementations in other languages it is slightly different.

 In my opinion that is more proper behavior:

 blank? (nil, whitespace chars resolves to true, something else, false)
 empty? (nil and  (empty string) resolves to true, something else is
 false)
 the purposed whitespace? is synonym of blank?

 I'll document and add tests for it in next days.

 Again, thanks for the feedback.

 Cheers.
 Andrey

 2014-12-24 13:03 GMT+01:00 Sean Johnson belu...@acm.org:

 Very nice work. I'll be using this!

 Also, I agree with Noam that there's a fairly common expectation of
 blank? that started in the Ruby world.

 Here's my suggestion for what it's worth:

 blank? - true iff  or nil
 empty? - true iff , false if nil
 whitespace? true iff  or only white space, false if nil

 Cheers,
 Sean

 On Tuesday, December 23, 2014 12:48:35 PM UTC-5, Andrey Antukh wrote:

 Hello everybody.

 I wanted to announce the first release of cuerdas. A string manipulation
 library for clojure and clojurescript.

 It is mainly based on underscore.string and string.js, but also
 influenced by lodash.

 Documentation: http://funcool.github.io/cuerdas/latest/
 Github: https://github.com/funcool/cuerdas

 Cheers.
 Andrey

 --
 Andrey Antukh - Андрей Антух - andrei@kaleidos.net / 
 ni...@niwi.be
 http://www.niwi.be http://www.niwi.be/page/about/
 https://github.com/niwibe

  --
 Note that posts from new members are moderated - please be patient with
 your first post.
 ---
 You received this message because you are subscribed to the Google Groups
 ClojureScript group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojurescript+unsubscr...@googlegroups.com.
 To post to this group, send email to clojurescr...@googlegroups.com.
 Visit this group at http://groups.google.com/group/clojurescript.




 --
 Andrey Antukh - Андрей Антух - andrei.anto...@kaleidos.net / 
 n...@niwi.be
 http://www.niwi.be http://www.niwi.be/page/about/
 https://github.com/niwibe

 --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: core.async go-loop questions

2014-12-20 Thread Erik Price
Part of what makes core.async great is that you don't have to use atoms to
communicate between threads in every case. For your case, I don't see what
using an atom gets you. It seems like you could replace the atom with a
channel, and put values on the channel whenever mail is sent. Your code
will be almost unchanged, except you'd replace your atom reset with a
channel put.

e

On Sat, Dec 20, 2014 at 10:17 PM, Jonathon McKitrick jmckitr...@gmail.com
wrote:

 I'd like to implement a thread that will send an email, then send a
 response via websocket to the client when the send completes.

 (defn my-wait-loop []
   (async/go-loop [status (async/! @mailer-status)]
 (if status
   (do
 (println Ready to send  status)
 (doseq [chan @connections]
   (println Channel chan)
   (send! chan (pr-str Done status)))
 (recur (async/! @mailer-status)))
   (println Go away

 (defn test-mailer []
   ;;(my-wait-loop)
   (reset! mailer-status
   (async/thread
 (try
   (mailer/send-speaker-confirmation-notification 1 
 http://localhost;)
   (catch Exception e
 (println (.getMessage e
 Success)))

 I would like to have the go-loop inside my-wait-loop run at all times,
 waiting for mailer-status to have a value.
 But I believe that can never happen, since the go-loop is waiting on an
 empty channel, and the reset! with the mailer will replace the channel with
 a new one after the emails are sent.

 Is there a batter way to do this, without needing to call my-wait-loop
 before the email thread is dispatched?

 --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: perform action after events stop for some period

2014-12-03 Thread Erik Price
Thank you for calling my attention to this possibility!

e

On Wed, Dec 3, 2014 at 2:49 PM, Dylan Butman dbut...@gmail.com wrote:

 Erik that's pretty! But be careful about go-loops and closed channels.
 This will recur infinitely if events-ch is closed (it will continuously
 return nil)

 (defn invoke-after-uninterrupted-delay

   ([period events-ch f]

 (invoke-after-uninterrupted-delay period events-ch f []))

   ([period events-ch f  args]

 (async/go-loop []

   (let [[v p] (async/alts! [(async/timeout period) events-ch])]

 (when v

   (if (= p events-ch)

 (recur)

 (apply f args)))
 will allow the go-loop to return when the channel is closed.


 On Monday, December 1, 2014 8:33:10 PM UTC-5, Erik Price wrote:

 Coincidentally, we recently wrote code to do something very similar. The
 following function will invoke f after period milliseconds, unless a
 value is sent on events-ch, in which case the timeout is reset (and
 starts counting down again):

 (defn invoke-after-uninterrupted-delay
   ([period events-ch f]
 (invoke-after-uninterrupted-delay period events-ch f []))
   ([period events-ch f  args]
 (async/go-loop []
   (let [[_ p] (async/alts! [(async/timeout period) events-ch])]
 (if (= p events-ch)
   (recur)
   (apply f args))

 e
 ​

 On Mon, Dec 1, 2014 at 6:50 PM, Brian Craft craft...@gmail.com wrote:

 That version has the unfortunate behavior that (func) can be interrupted
 if (event) is called while it is running. Here's another version using an
 agent:

 (defn queue-with-delay2 [period func]
   (let [q (agent nil)]
 (fn []
   (send-off q (fn [t]
 (when t
   (future-cancel t))
 (future (Thread/sleep period) (send-off q (fn [_]
 (func) nil

 Running with a sleep to see that (func) is not canceled by subsequence
 (event) calls:

 (def event (queue-with-delay2 2000 #(do (println running)
 (Thread/sleep 2000) (println ending

 Oddly, if calling (event) between running and ending messages, the
 repl will stack-overflow on the return value. No idea what that's about.
 But, running like this is fine:

 (do (event) nil)





 On Monday, December 1, 2014 1:37:56 PM UTC-8, Brian Craft wrote:

 I have need to perform an action when a series of events is quiet for
 some period. That is, if one event arrives an action is queued to execute
 after some timeout. If a second event arrives the timeout is reset, and
 so-forth.

 The following code seems to work, however I'm wondering if calling
 'future' from 'swap!' is a bad idea (side effecting), and if there's a
 better way.

 (defn queue-with-delay [period func]
   (let [f (atom nil)]
 (fn []
   (when @f
 (future-cancel @f))
   (swap! f (fn [_] (future (Thread/sleep period) (func)))


 Use like

 (def event (queue-with-delay 2000 #(println running)))
 (event)
 (event)
 (event)  ; pause 2 sec
 running



  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+u...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


  --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure

Re: perform action after events stop for some period

2014-12-02 Thread Erik Price
On Tue, Dec 2, 2014 at 12:22 PM, Brian Craft craft.br...@gmail.com wrote:


 It does seem like a single-thread solution would be better, not creating
 so many futures. Polling seems pretty crude, but I don't see another way of
 doing it with clojure abstractions. Maybe a pure java solution.


FWIW, the core.async-based solution satisfies both the criteria of being
single-threaded and non-polling.

e

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: perform action after events stop for some period

2014-12-01 Thread Erik Price
Coincidentally, we recently wrote code to do something very similar. The
following function will invoke f after period milliseconds, unless a value
is sent on events-ch, in which case the timeout is reset (and starts
counting down again):

(defn invoke-after-uninterrupted-delay
  ([period events-ch f]
(invoke-after-uninterrupted-delay period events-ch f []))
  ([period events-ch f  args]
(async/go-loop []
  (let [[_ p] (async/alts! [(async/timeout period) events-ch])]
(if (= p events-ch)
  (recur)
  (apply f args))

e
​

On Mon, Dec 1, 2014 at 6:50 PM, Brian Craft craft.br...@gmail.com wrote:

 That version has the unfortunate behavior that (func) can be interrupted
 if (event) is called while it is running. Here's another version using an
 agent:

 (defn queue-with-delay2 [period func]
   (let [q (agent nil)]
 (fn []
   (send-off q (fn [t]
 (when t
   (future-cancel t))
 (future (Thread/sleep period) (send-off q (fn [_]
 (func) nil

 Running with a sleep to see that (func) is not canceled by subsequence
 (event) calls:

 (def event (queue-with-delay2 2000 #(do (println running) (Thread/sleep
 2000) (println ending

 Oddly, if calling (event) between running and ending messages, the
 repl will stack-overflow on the return value. No idea what that's about.
 But, running like this is fine:

 (do (event) nil)





 On Monday, December 1, 2014 1:37:56 PM UTC-8, Brian Craft wrote:

 I have need to perform an action when a series of events is quiet for
 some period. That is, if one event arrives an action is queued to execute
 after some timeout. If a second event arrives the timeout is reset, and
 so-forth.

 The following code seems to work, however I'm wondering if calling
 'future' from 'swap!' is a bad idea (side effecting), and if there's a
 better way.

 (defn queue-with-delay [period func]
   (let [f (atom nil)]
 (fn []
   (when @f
 (future-cancel @f))
   (swap! f (fn [_] (future (Thread/sleep period) (func)))


 Use like

 (def event (queue-with-delay 2000 #(println running)))
 (event)
 (event)
 (event)  ; pause 2 sec
 running



  --
 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 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Naming Functions...

2010-02-04 Thread Erik Price
What kind of naming convention is appropriate for a function that
operates on a sequence, and, as one of its return values, returns a
new head for (or in other words a subsequence within) that sequence?
For example, a function that consumes some portion of a stream. Or is
it not conventional for a stream-consuming function to work that way?

e

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Domain Modelling

2010-02-01 Thread Erik Price
On Sun, Jan 31, 2010 at 10:33 PM, Barry Dahlberg
barry.dahlb...@gmail.com wrote:
 Perhaps I'll write up my findings once the language stops intimidating
 me.

 At the moment I'm writing an account object.  I have some standard
 CRUD type functions which operate on a map behind the scenes.  I would
 like to add some metadata to start specifying rules for validation, UI
 generation and so on.  The trouble is I can't really figure out where
 to attach this metadata as I don't have a type definition as such,
 e.g. I would do this in C#:

    [Required, MaxLength(50)]
    public string Name { get; set; }

 defstruct seems promising though I can't find an example with
 metadata.

 Any pointers of where to start looking?

You can attach metadata to Clojure constructs using the with-meta function:

user= (def x {:name Frank})
#'user/x
user= (def x-with-metadata (with-meta x {:RequiredParameter true,
:MaxLength 50}))
#'user/x-with-metadata
user= (:MaxLength (meta x-with-metadata))
50

As for whether you want to define the metadata directly on your map,
or on functions that construct/operate on your map, or somewhere else,
that's your design decision.

e

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure Kata

2010-01-28 Thread Erik Price
Thanks Sean, this was a great exercise. I'm comfortable reading
Clojure code, but writing it requires thinking differently from what I
am used to. My solution is clunky and less elegant than most of the
other submissions in this thread, but I avoided reading any of them
until I had implemented the solution myself, which was rewarding.

I welcome any criticism, especially where I could have used more
idiomatic Clojure.

http://gist.github.com/289274

e


On Jan 24, 3:31 pm, Sean Devlin francoisdev...@gmail.com wrote:
 I recently found a scheme problem that I think would be a good
 exercise for a new Clojure developer.  I've written about it here:

 http://fulldisclojure.blogspot.com/2010/01/code-kata-data-sifter.html

 Have fun.
 Sean

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Question about Responsiveness of Garbage Collection

2010-01-22 Thread Erik Price


On Jan 20, 7:22 pm, CuppoJava patrickli_2...@hotmail.com wrote:

 Some articles I read point to Java's use of garbage collection as the
 culprit, and I'm wondering whether that is true. I know Scheme and
 Common Lisp also use garbage collection, so do gui programs written
 those languages also feel sluggish?

Plenty of native Objective-C applications also use garbage
collection, and do not feel sluggish.

e

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Good refs on concurrency?

2010-01-18 Thread Erik Price
On Sat, Jan 16, 2010 at 7:02 PM, David Beckwith
thirdreplica...@gmail.com wrote:
 Hi,

 Can you guys recommend any good books, articles or code on
 concurrency?  I'm new to concurrency issues, and just finished the
 Halloway book, so it would be great to have an introductory reference
 with lots of examples of how to make your CPUs all work happily
 together.  Bascally, I'd like to read a whole book about it relevant
 to Clojure.  (Or maybe relevant to Java.)  I want to learn a lot more

If you're interested in learning about the kinds of problems that
motivate some of Clojure's concurrency features, Java Concurrency in
Practice is excellent. The concepts are not specific only to Java,
although the examples and libraries discussed happen to be Java-based.
I especially like its pragmatic approach - it's written for working
programmers rather than for coursework, so it's a pretty fast and
interesting read.

 about the difference between atoms, vars, refs, etc and when to use
 each in practice.  I guess there are probably several classes of
 situations of when you would need to use concurrency.  I'd like to

This book doesn't discuss these programming constructs, as they are
not available in Java. But it's still an insightful book if only to
learn about what kind of concurrency problems exist, despite Clojure
offering a different way to deal with them than does Java.

e
-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Good refs on concurrency?

2010-01-18 Thread Erik Price
On Sat, Jan 16, 2010 at 7:02 PM, David Beckwith
thirdreplica...@gmail.com wrote:

 Can you guys recommend any good books, articles or code on
 concurrency?  I'm new to concurrency issues, and just finished the
 Halloway book, so it would be great to have an introductory reference
 with lots of examples of how to make your CPUs all work happily
 together.

I should add that if you're more interested in learning only how
Clojure addresses concurrency issues, rather than a book on
concurrency topics, the best thing to read is others' code. Look for
the more interesting-looking Clojure projects on Github and Bitbucket
and study the code, see how agents and refs are actually being used.
Read the back issues of some of the Clojure blogs like bestinclass.dk
if you haven't already.

e
-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Parenthesis Inference

2009-12-19 Thread Erik Price
Personally, I don't think the problem for non-Lispers is with the
number of parentheses so much as with the *depth* of parens-nesting
and having to invert the reading order, starting from the deepest
s-expr and reading your way back out.

I'm still very new to Clojure (basically I have only been paying close
attention to it for a few weeks, and have not written any substantial
Clojure code yet), and I come from ten years of programming the usual
non-Lisp Python/Java/JavaScript/C-style languages. But I can honestly
say that reading Clojure code comes very naturally for me now, as long
as I'm familiar with all the functions in an expression, and I assure
you that it's certainly not that I'm special or particularly bright.

Interested programmers are willing to learn different syntaxes -
judging from the number of apps, there are probably at least fifty
thousand programmers who were willing to look past all the square
brackets in Objective-C so that they could write iPhone apps. What I
think makes it difficult to approach an S-expression isn't the
parentheses, but the fact that you often have to read it in an inverse
order, or maintain a mental stack of functions that have been applied
so far. For me, this is especially the case when function calls are
nested very deeply.

I'm not familiar with it, but from your example it appears that the
- macro lets the code be written in an order which is not inverted.
Furthermore, the first example looks like it has more parens than
the - example, even though it actually has fewer, because of its
deeper nesting - so it's easier to read through what's happening in
the - example, without having to maintain a mental stack of what
functions have are being applied to the expression. For interested
programmers new to Clojure, I would think this is way more useful than
reducing the number parentheses.

e

PS: I use the term interested programmers above because I don't
think Clojure will ever appeal to a programmer who isn't interested in
learning something new. The syntax is the easy part. The hard part is
learning a different approach to designing and structuring programs.



On Fri, Dec 18, 2009 at 2:07 PM, Martin Coxall pseudo.m...@me.com wrote:
 I had this thought at work, when I should have been working, so please bear 
 with me if it's nonsense.

 One of the things that always puts people off of Lisp, as we all know, are 
 the parentheses. Now, many ways have been suggested of doing this in other 
 Lisps, but have never taken off, mainly due to inertia and a fear of 
 sacrificing homoiconicity.

 However, I love Clojure, and want to see it really take off. And so I want to 
 see all barriers to that removed. Also, I think the language is young enough 
 that seemingly-but-not-really radical proposals can still be sneaked in.

 Let's take this example, since I note that Rich Hickey weighed in in the 
 comments:

 http://www.innoq.com/blog/st/2009/12/clojurelisp_readability.html

 (apply merge-with +
        (pmap count-lines
                (partition-all *batch-size*
                        (line-seq (reader filename)

 This little snippet has ten parentheses. And is potentially very unnerving to 
 a non-lisper. Ten parentheses in four lines seems a lot to most programmers.

 Rich, in the comments, suggests a pipelined style to make the code more 
 readable:

 (- (line-seq (reader filename))
  (partition-all *batch-size*)
  (pmap count-lines)
  (apply merge-with +))


 I accept that this is more readable because it has less nesting. But it now 
 has *12* parentheses, more than the original, potentially just as alarming to 
 the Lispophobes.

 My question is this: why can't we introduce a simple and importantly, 
 optional 'off-side rule' (much simpler than Haskell's) that allows the reader 
 to infer many of the parentheses?

 A very simple offside rule could turn the original into:

 apply merge-with +
        pmap count-lines
                partition-all *batch-size*
                        line-seq (reader filename)


 With a startling two parentheses and Rich's corrected version into:

 -
  line-seq (reader filename)
  partition-all *batch-size*
  pmap count-lines
  apply merge-with +


 Also with two. That last example in particular looks splendidly readable. 
 Almost... monadic.

 The parenthesis inference here is very simple, and could be stated in two 
 sentences:

 For each line that is not within a vector, and does not have an opening 
 parenthesis, infer an opening parenthesis at the start of the line. Remember 
 the level of indentation, and infer a closing parenthesis at the end of the 
 line *before* the next line whose indentation is the same as or less than the 
 remembered one.

 My question is: why would such a scheme work/not work, and why would/would 
 not it be desirable?

 Martin

 --
 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 

Re: mapmap

2009-12-17 Thread Erik Price
On Thu, Dec 17, 2009 at 12:16 PM, Konrad Hinsen
konrad.hin...@fastmail.net wrote:

 On 17 Dec 2009, at 15:44, Sean Devlin wrote:

  (defn map-vals [f coll]
   (into {} (map (juxt key (comp f val)) coll))

vs:

 (defmethod fmap clojure.lang.IPersistentMap
   [f m]
   (into (empty m) (for [[k v] m] [k (f v)])))

Are there any guidelines as to when it's appropriate to use the map
function vs a list comprehension?

e

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: more dumb noob pain (2dplot.clj)

2009-12-11 Thread Erik Price
On Fri, Dec 11, 2009 at 12:15 PM, rebcabin bc.beck...@gmail.com wrote:


 Any hints for me? I'm sure it's because I really don't know at all how
 to find out where java things are installed and how to refer to them
 if they're installed in weird places yadda yadda.


Are the Java 3D jar files in your CLASSPATH?

e

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: What about contains? for lists

2009-12-02 Thread Erik Price
On Wed, Dec 2, 2009 at 10:10 AM, Stefan Kamphausen
ska2...@googlemail.comwrote:


 OK, the doc of contains? told me that for indexed collection-types it
 will only check, whether the index is within the valid range.  So
 maybe:

 user (contains? (list 1 2 3) 1)
 false

 At that point I dived into the implementation and found that in
 RT.java checks for the type of collection passed but leaves out
 PersistenList.

 I'd like to understand the (probably well-grounded) reason for that.
 As far as I can see PersistentList extends Counted, so the check for
 the index-range should at least be possible.  However, I think people
 would expect an equality check in the background, which OTOH would be O
 (N), probably.


It was my impression that in Clojure, lists aren't numerically indexed
collections. That might explain the following:

user= (contains? '(1 2 3) 1)
false
user= ('(1 2 3) 1)
java.lang.ClassCastException: clojure.lang.PersistentList (NO_SOURCE_FILE:0)

even though:

user= (contains? [1 2 3] 1)
true
user= ([1 2 3] 1)
2

But I might be mistaken, so take this as speculation rather than
explanation.

e

-- 
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 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en