I've build up some file input/output utils over the past year that may be
of use to the Clojure community. They allow one to do fine-grained I/O
with native Java numeric types (both signed & unsigned), as well as create
& delete temporary files & directories.
Full API docs can b
Does anyone know of any libraries for Clojure that wrap up non-blocking
file I/O?
I'm interested in one suitable for use with core.async on Java 7+.
Below is a naïve stab at a function that reads file and returns it on a
channel. It blocks somewhat (in the open and length calls), but ov
Thank you for the answers, and sorry for late reply.
It seems I figured out what the problem was.
My code was placed at the top level of a file sci-clustering/examples.clj,
and I was loading the namespace from REPL like this:(use
'sci-clustering.examples :reload-all).
So it looks like clojure.c
On Thu, 2012-06-14 at 13:33 -0700, dmirylenka wrote:
> Could you please explain a bit more?
>
> I don't have any dosync in my code.
Look through your backtrace for a call to
clojure.lang.LockingTransaction.runInTransaction. Its caller is using
dosync.
--
Stephen Compall
^aCollection allSatisf
Hi,
Am 14.06.2012 um 22:33 schrieb dmirylenka:
> Could you please explain a bit more?
>
> I don't have any dosync in my code.
transaction* contains an io! form which throws such an exception when called in
a dosync. How does the code look like, which does not work?
Kind regards
Meikel
--
Yo
Could you please explain a bit more?
I don't have any dosync in my code.
Daniil
On Thursday, June 14, 2012 4:17:46 PM UTC+2, Meikel Brandmeyer (kotarak)
wrote:
>
> Hi,
>
> the exception probably stems from the fact that you do the database
> interaction inside a dosync transaction.
>
> Kind re
Hi,
the exception probably stems from the fact that you do the database
interaction inside a dosync transaction.
Kind regards
Meikel
--
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
I'm trying to insert some values into MySQL db, via clojure.java.jdbc.
When I call my code from Leiningen REPL, I get:
IllegalStateException I/O in transaction
clojure.java.jdbc.internal/transaction* (internal.clj:212).
The same code runs without exception when executed outside repl (
How about a memory mapped file? Not lazy at all, but could be quick, given
that you have enough memory.
http://docs.oracle.com/javase/1.4.2/docs/api/java/nio/MappedByteBuffer.html
There can be times where a database is too low performant or clumsy for
quick searching in a large utf-8 file, but so
On Jan 5, 2012, at 5:07 PM, Andy Fingerhut wrote:
> I realize that with variable-length multi-byte character encodings like
> UTF-8, it would be a bad idea to seek to a random byte position and start
> trying to decode a UTF-8 character starting at that byte position. I'm
> thinking of cases
ndomAccessFile [3], which provides byte-oriented
I/O on a file with the ability to tell your current byte position, or seek
to a specified byte position.
I know that some of the subclasses of Reader have mark and reset methods,
but those appear to have implementation-specific limitations on how far
On Thu, 25 Aug 2011 19:24:13 +0300
Mats Rauhala wrote:
> The simplest way is to slurp or spit. slurp reads a file into a
> string, and spit writes a string into a file.
Yes, true, but first you have to know them. And "slurp" is not the
first think I am looking for when attempting to read a file,
On Aug 26, 2011, at 12:01 PM, Laurent PETIT wrote:
>
> What kind of problem with Eclipse / CCW ?
> CCW uses a standard java launcher, so to say it uses the Eclipse Java
> Development Tools defaults, which are to create a launch configuration with
> the project's path as the current directory (o
launch configuration, later on : "Run > Run as ...
> [choose the launch configuration, edit, save]")
Cheers,
--
Laurent
> If I run a lein repl from a non-project directory then it's set to my home
> directory, which makes some sense I guess, but why not the directory fr
Friends,
Thank you for the replies. I think you have proved my point.
--
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 w
On Aug 26, 2011, at 9:15 AM, Terje Dahl wrote:
> I disagree.
>
> Simply use: (System/getProperty "user.home")
>
> This will give you a useful path to work with, no matter where you
> start from.
> Works on my Mac. Should work on Windows.
>
> From there I would build a simple library which tes
Exactly right. That explains why.
>
> Thanks also for all of the other details and workaround suggestions on the
> clooj list. Alas, the bottom line does seem to be that there's no simple way
> to get simple file I/O to work relative to a project's location without
> launching
d thus all further file system operations will be relative to that.
Ah. Exactly right. That explains why.
Thanks also for all of the other details and workaround suggestions on the
clooj list. Alas, the bottom line does seem to be that there's no simple way to
get simple file I/O to work relat
'm wondering: Is it specified somewhere that
> this should always be set to the project directory? If I run a lein repl from
> a non-project directory then it's set to my home directory, which makes some
> sense I guess, but why not the directory from which the repl was launche
;s set to my home directory, which makes some
sense I guess, but why not the directory from which the repl was launched?
FWIW my larger point was just that all of this is less clear than it is in many
other languages, and that simple file I/O is therefore less simple than one
might hope.
Thanks
On Thu, Aug 25, 2011 at 6:49 PM, Lee Spector wrote:
> While slurp and spit are beautifully elegant it's not so elegant to tell
> slurp how to find the file you want it to slurp. In many other
> languages/environments there's a concept of the working directory or project
> directory, relative to
August 25, 2011, Walter van der Laan <
waltervanderl...@gmail.com> wrote:
> This gives several I/O examples:
> http://nakkaya.com/2010/06/15/clojure-io-cookbook/
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
&g
In my current configuration (in Mac OS X running clooj -- which is really
shaping up beautifully, BTW) spit with a simple file name seems to go to my
Downloads directory. I don't know why or how to change it.
Much worse is the problem with interactive console-based I/O, which is often
one
> I think part of the reason for
> this is the conception (maybe misconception) that most people are
> familiar with java and since there is java interopt they should be
> able to figure this out. As more and more schools are starting to use
> Python as their beginning CS language, this may well n
This gives several I/O examples:
http://nakkaya.com/2010/06/15/clojure-io-cookbook/
--
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 moderate
For that you'll have to look into the clj-http library:
https://github.com/mmcgrana/clj-http
>From the readme: (client/post "http://site.com/resources"; {:body "string"})
On Thu, Aug 25, 2011 at 2:00 PM, Terje Dahl wrote:
> Great question. And great answer.
> Seriously! I did not know it coul
Great question. And great answer.
Seriously! I did not know it could be that easy.
So an http GET just needs 1 lines!:
(slurp (reader "http://google.com";))
(Don't forget: (use 'clojure.java.io) )
Is there an equally easy way to do an http POST?
And also a multi-part (including one or mor
I too stumbled upon this a while ago. I might even say that on some
level it's so simple that there is not much documentation about it, and
at some point it gets 'complex' enough that you should know about java
enough.
The simplest way is to slurp or spit. slurp reads a file into a string,
and spi
One of the first things that I want to know how to do when I learn a
new programming language is how to read from or print to a file. The
problem is that none of the clojure books do a good job of explaining
how to do so, in my opinion. What little is said is usually tucked
away and not highlight
tions is overkill, so
it should be a setting passed into dosync. One key benefit of this
approach is that it doesn't require the user to specify nested
transactions. Transactions boundaries should be about correctness
alone; performance should be kept orthogonal. This approach takes the
lo
d to add if
clojure also
exposes some kind of prepare methods to makes sure that the
transaction
is able to commit.
For the Multiverse STM I have introduced CommitBarriers for this
purpose,
but I don't think they would be hard to add to the Clojure STM.
>
> c) Somewhat different: I'm not
Thanks Tim that with the readers and writers is what I figured.
On Oct 16, 12:12 am, Timothy Baldridge wrote:
> I can't answer most of these, but I'll take a crack at a)
>
> From my understanding of the clojure code, the answer to long running
> transactions will depend on your application. If yo
dosync is a way of ensuring whole stateful operation is done atomically.
(ie as if everything was happening in one step.)
That contradicts b). During a whole dosync, you can only see one state
of the world.
If you do not need atomicity, do multiple dosync.
You should create another abstraction fo
I can't answer most of these, but I'll take a crack at a)
>From my understanding of the clojure code, the answer to long running
transactions will depend on your application. If you have one writer,
and 100 readers, you'll be fine. The readers will read the old value
while the writer is updating t
pt part depends on are changed concurrently but not
the parameters/result of the first part, then only the second
calculation has to be repeated, not both. The second part could be
enclosed in an inner dosync but currently Clojure will unnecessarily
redo the whole thing.
c) Somewhat different:
On Dec 2, 3:10 am, Ivan Sagalaev wrote:
> My question is how to model a non-blocking I/O.
netty is excellent if you want NIO for performance. But for requesting
a URL - really quite massively overkill. You can write a URL request
in a threaded way very simply (even containing a callback if
John Harrop wrote:
> The java.nio.channels package. :)
In other words there's no special patterns for non-bocking I/O in
Clojure and it's done with callbacks as usually, right?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group
http://mina.apache.org/
--
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 gr
t;
> My question is how to model a non-blocking I/O. For example I want to
> request a URL over HTTP and do something with its content. I don't want
> to block on waiting for network. In my current working language Python I
> can setup a non-blocking socket and a callback that will t
Hello!
I'm looking at Clojure for a couple of days, having watched two of
Rich's video presentations. So I'm not yet familiar with Clojure's
practical patterns but I can read the code :-).
My question is how to model a non-blocking I/O. For example I want to
request a
Anybody else getting bombarded by multiple copies of this message?
--- On Tue, 11/10/09, John Harrop wrote:
> From: John Harrop
> Subject: Re: Using agents and blocking I/O.
> To: clojure@googlegroups.com
> Date: Tuesday, November 10, 2009, 8:45 AM
> On Tue, Nov 10,
> 2009
On Tue, Nov 10, 2009 at 11:41 AM, John Harrop wrote:
> user=> (take 10 (p-lazy-seq 3 true (thread-local-rand 10)))
> (1 2 6 1 5 1 7 8 4 3)
>
> This should generate the random numbers on multiple threads, using multiple
> RNGs. In the limit, on multicore hardware and with a slow enough RNG
> imple
On Tue, Nov 10, 2009 at 10:41 AM, pmf wrote:
> On Nov 10, 7:07 am, David Brown wrote:
> > Ok. So, it's the existence of this future-like entity that blocks
> > upon deref until filled is indeed somewhat missing. It's not
> > particularly difficult to implement.
> >
> > This thing could easily
On Tue, Nov 10, 2009 at 07:41:41AM -0800, pmf wrote:
>> This thing could easily create a lazy sequence, in fact, the code
>> would look a lot like the code for seque, with just a separation of
>> the writer from the reader. I'll have to think about it to make sure
>> that it can be used safely.
>
On Nov 10, 7:07 am, David Brown wrote:
> Ok. So, it's the existence of this future-like entity that blocks
> upon deref until filled is indeed somewhat missing. It's not
> particularly difficult to implement.
>
> This thing could easily create a lazy sequence, in fact, the code
> would look a lo
On Mon, Nov 09, 2009 at 10:07:41PM -0800, David Brown wrote:
>On Mon, Nov 09, 2009 at 09:42:28PM -0800, Mark Engelberg wrote:
>>But let's say the agent is responsible some enormous database, and
>>it's impractical for the in-memory state to hold all the information
>>that readers might find useful
On Mon, Nov 09, 2009 at 09:42:28PM -0800, Mark Engelberg wrote:
>But let's say the agent is responsible some enormous database, and
>it's impractical for the in-memory state to hold all the information
>that readers might find useful. In this case, I think you're right
>that the basic agent func
On Mon, Nov 9, 2009 at 8:28 PM, David Brown wrote:
> Let's say I have some thing that keeps track of the state of some I/O
> entity, let's say some kind of file-based storage. There is state
> associated with the entity. It's important that only one thread be
> able
(locking resource (read/write)) sounds appropriate for such a resource
to me. Maybe you should do locking writes through an agent, and just
rely on locking for blocking reads. I don't really know how lock
requests are queued, is that why you are looking for more complicated
answers?
;; ugh this i
David,
Agents are designed to be call only once. That's why they're useful
for I/O (stuff w/ side effects). refs, however, will retry inside a
transactions.
As always, Rich explains it better than me:
http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey
Sean
On Nov 9
On Mon, Nov 09, 2009 at 08:28:43PM -0800, David Brown wrote:
>In both cases, the reads run completely synchronously, waiting for
>their answer, and really the whole thing isn't really any better than
>just using locks.
I guess a deeper concern is that there seems to only be a single call
in the
I'm trying to get a better grasp of how Agents are intended to be
used, so let me give an example scenario.
Let's say I have some thing that keeps track of the state of some I/O
entity, let's say some kind of file-based storage. There is state
associated with the entity. It
George Jahad writes:
> Hmmm. I'm seeing different behaviour. When I run your code
> untouched, I never get the "unchunked" error. Instead, I see a bunch
> of garbage printed after the echoed "hello" like so:
>
> echo "hello" | ng nailgun.Example
>
> hello
> ^...@^@^...@^@^...@^@^...@^@^...@^@
Hmmm. I'm seeing different behaviour. When I run your code
untouched, I never get the "unchunked" error. Instead, I see a bunch
of garbage printed after the echoed "hello" like so:
echo "hello" | ng nailgun.Example
hello
^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^
George Jahad writes:
> I think it is just an input stream encoding problem. I think if you
> change this line:
> (copy (-> context .in) out)
>
> to this:
> (copy (-> context .in InputStreamReader.) out)
>
> it will work.
Thanks, but that gives the same result. =\
Contributing to the p
Hey Phil:
I think it is just an input stream encoding problem. I think if you
change this line:
(copy (-> context .in) out)
to this:
(copy (-> context .in InputStreamReader.) out)
it will work.
George
On Jul 6, 5:06 pm, Phil Hagelberg wrote:
> So a common counter to "the VM startup
So a common counter to "the VM startup time is so bad" problem is to use
Nailgun for a long-running server process. I've gotten this working in
some respects, but I get a "Unexpected chunk type 83 ('S')" error quite
often when I'm trying to read from the stdin that the nailgun context
provides.
On Mon, Apr 6, 2009 at 12:58 AM, Dex Wood wrote:
>
> If you want to do I/O from a transaction, just use an agent to do the
> I/O. Since the agent is only sent off at commit, you don't have to
> worry about retries. This doesn't answer your questions about
> idempotent
If you want to do I/O from a transaction, just use an agent to do the
I/O. Since the agent is only sent off at commit, you don't have to
worry about retries. This doesn't answer your questions about
idempotent I/O, but I think it is a strategy that you can use.
On Apr 5, 2:11 pm, Hu
On Apr 5, 2009, at 3:11 PM, Hugh Winkler wrote:
From http://clojure.org/refs : "I/O and other activities with
side-effects should be avoided in transactions, since transactions
will be retried. The io! macro can be used to prevent the use of an
impure function in a transaction."
Hi all,
>From http://clojure.org/refs : "I/O and other activities with
side-effects should be avoided in transactions, since transactions
will be retried. The io! macro can be used to prevent the use of an
impure function in a transaction."
Isn't it OK to do I/O in a tran
This is repeated from the compojure group.
Hi,
I'm developing an app that lets users upload files. I checked the
docs and tests, and I didn't notice anything about uploading files.
Is there a standard way of doing this in compojure, or do I need to
interact with the java servlet directly?
--~--~-
It's due to a type hint Rich put in a couple revisions ago to reduce
reflection in clojure.core. I've filed an issue for it, it will be
worked out in time.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Clojure" gro
On Feb 21, 2009, at 6:10 PM, Mark Volkmann wrote:
Thanks the suggestion. That works! However, it seems to me that
(read-line) should do the same thing. Is there a reason it doesn't?
There were a couple of discussions about this recently:
http://groups.google.com/group/clojure/search?group=cl
On Sat, Feb 21, 2009 at 4:48 PM, James Reeves
wrote:
>
> On Feb 21, 10:11 pm, Mark Volkmann wrote:
>> (print "Enter your name: ")
>> (flush)
>> (def nm (read-line))
>> (newline)
>> (println "Your name is" nm)
>>
>> The read-line throws java.lang.ClassCastException:
>> clojure.lang.LineNumberingP
On Feb 21, 10:11 pm, Mark Volkmann wrote:
> (print "Enter your name: ")
> (flush)
> (def nm (read-line))
> (newline)
> (println "Your name is" nm)
>
> The read-line throws java.lang.ClassCastException:
> clojure.lang.LineNumberingPushbackReader.
> Should it do that? I just want to read from stdin
(print "Enter your name: ")
(flush)
(def nm (read-line))
(newline)
(println "Your name is" nm)
The read-line throws java.lang.ClassCastException:
clojure.lang.LineNumberingPushbackReader.
Should it do that? I just want to read from stdin.
--
R. Mark Volkmann
Object Computing, Inc.
--~--~--
ds of IO libraries.
I don't know that there's anything provided already in Clojure, but
you could use the clojure.lang.LockingTransaction#getRunning() method
to check if there is a running transaction on the current thread.
>From there it's pretty easy to write some sort of ass
from
> > the main body of the functional program?
>
> You can't, other than manually.
>
> > How can I ensure referential transparency in Clojure?
>
> You can't, other than manually.
>
> > What I/O primitives Clojure provides?
>
> All of Java's.
I
> How can I ensure referential transparency in Clojure?
You can't, other than manually.
> What I/O primitives Clojure provides?
>
All of Java's.
Rich
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google G
Providing that Clojure is NOT a pure functional language like Haskell,
yet how can I isolate imperative-style computational structures from
the main body of the functional program?
How can I ensure referential transparency in Clojure?
What I/O primitives Clojure provides?
Thanks
71 matches
Mail list logo