On Dec 13, 9:34 pm, Dan Larkin wrote:
> I'm here to ask for python style triple-double-quotes syntax in clojure.
I'm not completely sure they're needed, to be honest. In Python,
triple quotes have 2 benefits: multi-line quotes and you don't have to
escape quotation marks. In Clojure, normal quot
On Dec 14, 2:01 pm, Mike Perham wrote:
> Hi, I'm just learning Clojure but I thought I would do a little
> experiment to see where Clojure sits performance-wise compared to a
> number of other languages on the old Fibonacci sequence. I think it
> handles itself quite well.
Interesting, but beca
I've notice that the latest builds of Clojure now use strings for keys
in proxy mappings, whilst in the past they used to use symbols. Was
this change deliberate?
- James
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Group
On Dec 14, 6:57 pm, Randall R Schulz wrote:
> Yes. Rich pointed this out in the SVN commit commentary for 1159:
Ah, somehow I managed to miss that message! I should really pay closer
attention.
- James
--~--~-~--~~~---~--~~
You received this message because you a
On Dec 15, 5:34 pm, Paul Reiners wrote:
> I have the following Clojure code and I'm not sure why it's not
> working:
>
> (defn match (x y &optional binds)
> (cond
> ((eql x y) (values binds t))
> ((assoc x binds) (match (binding x binds) y binds))
> ((assoc y binds) (match x (binding
On Dec 17, 8:25 pm, Chouser wrote:
> > ~x not in a syntax-quote yielded the form (unquote x) from the reader
>
> I very much like the sound of this.
>
> +1
I'm for this as well. I've been using keywords as a substitute, but an
unquote would be more intuitive.
- James
--~--~-~--~~---
On Dec 20, 5:07 pm, janus wrote:
> I wanted to use clojure.lang.Script in order to use SciTe editor,
> however, I am not getting any result. Has anyone used Script before,
> if yes, please I need your help. First ,I need direction on how to use
> it .Or anyone really used Scite with Clojure, if
On Jan 7, 7:14 pm, "Brian Doyle" wrote:
> (defn write-bytes
> "Writes the bytes from the in-stream to the given filename."
> [#^java.io.InputStream in-stream #^String filename]
> (with-open [out-stream (new FileOutputStream filename)]
> (let [buffer (make-array (Byte/TYPE
On Jan 8, 5:05 pm, "Brian Doyle" wrote:
> I incorporated most of James ideas but I don't like the name pipe-stream.
Then wouldn't copy-stream be better? write-stream isn't specific
enough, IMO.
Also, I don't think there's a huge amount of gain to be had from an
Integer type hint in this case, s
On Jan 9, 12:48 am, wubbie wrote:
> I can use file-seq
> (file-seq (File. "."))
> But how can I filter out all files ending with .clj?
> Do we use re-find, re-seq etc?
You can just use filter:
(filter
#(.endsWith (str %) ".clj")
(file-seq (File. ".")))
- James
--~--~-~--~~-
On Jan 10, 12:22 am, wubbie wrote:
> How can you add line numbers for each line printed from the file.
> Without line number, I have this:
>
> (with-open [rdr (reader "executors.clj")]
> (filter #(println %) (line-seq rdr)))
I don't believe there's a function to do this, but it's easy enough t
I've written a small XML pretty printing library that may be useful
for debugging XHTML or XML outputs, especially those generated from
libraries like clj-html or compojure.html. Usage is straightforward:
=> (use 'ppxml)
nil
=> (ppxml "Hello")
Hello
I've uploaded the library to the g
On Jan 10, 4:54 pm, e wrote:
> Concretely, this would mean following the "Getting Started"
> instructions on clojure.org. Then seeing what there is to see . . . I
> assume some sort of command line for doing "REPL" will come up as it
> says?
The Wiki covers getting started in much more detail:
On Jan 10, 1:17 pm, GS wrote:
> > (with-open [rdr (reader "executors.clj")]
> > (doseq [[line index] (zip-index (line-seq rdr))]
> > (.println System/out (str (inc index) " " line
>
> Why would you use Java's (.println System/out ...) instead of
> (println ...)?
Because println is, I t
On Jan 11, 6:32 am, "Nick Vogel" wrote:
> Ok, first of all, here's how I translated that python code:
>
> (defn msort [myList]
> (if (> (count myList) 1)
> (let [l1 (first myList) l2 (second myList)]
> (recur (concat (drop 2 myList) (my-merge l1 l2
> (first myList)))
I'd chan
Thinking functionally is hard when you're used to programming
imperatively. So instead of leaping straight into Clojure, lets stick
with Python for the time being.
So let's take your Python code:
def msort(someList):
myList = [[x] for x in someList]
while len(myList) > 1:
l1 = myList.pop
On Jan 11, 5:53 pm, e wrote:
> this seemed like a clean, nice way to merge to sorted lists into one
> sorted list. I'm not getting clojure syntax, it seems:
>
> (defn listmerge [l1 l2]
> (let [l1first (first l1) l2first (first l2)]
> (if (= l1first nil) l2)
> (if (= l2first nil) l1)
>
On Jan 11, 6:19 pm, e wrote:
> This gets to my question perfectly. Why is your code "my-list
> (rest (rest my-list)) " legal?
Because you're not actually changing anything.
In theory, the let form can be derived from anonymous functions. So
(let [x y] ...) is the same as ((fn [x] ...) y).
Or,
On Jan 11, 7:09 pm, e wrote:
> if it has tighter scope, then I don't understand why you don't have an
> infinite loop. The nested my-list that you redefined should have
> nothing to do with the my-list that you are doing the 'rest' check
> on.
That's what the loop/recur form does. Again, loop/r
On Jan 11, 7:19 pm, e wrote:
> oh. I missed the "recur my-list" in your answer. So we still don't
> have an iterative solution. Recursion should never be necessary. I
> agree that it simplifies things sometimes and you can use it when you
> are stuck. . . . .but no need to push a whole stack
On Jan 12, 5:24 am, e wrote:
> It's funny, whenever I tried to be all safe like this and take the time to
> make stuff safe in C++, coworkers would say, "we are grown-ups. At some
> point you gotta stop being a paranoid programmer.
Given that software bugs are a very common occurrence, I'd say
On Jan 13, 4:45 am, Mark McGranaghan wrote:
> In terms of Clojure web frameworks, I think that there is a lot to be
> gained by leveraging the Ring interface, especially from the modular
> functionality provided by Ring middleware. I'd like in particular to
> be able to run Compojure apps in Ring
On Jan 13, 6:45 pm, e wrote:
> sure . . . I'm just impressed with how many things "just work", and this
> could be one more. Not enough args, but you know what I wanted it to mean.
> There's no ambiguity.
This is a bad idea. It just adds confusion with no real benefit.
Reading the code would be
On Jan 13, 9:56 pm, "Mark McGranaghan" wrote:
> I choose not include the parameters, cookies, and sessions features
> from the Servlet API because I'm not confident that the interfaces
> presented by Servlets in these cases will be acceptable to all Ring
> applications. For example, different Rin
On Jan 14, 12:35 am, "Mark McGranaghan" wrote:
> For Ring, the HttpServlet API is a means to an end, not an end in
> itself. The interface that Servlets present for parameter parsing and
> session handling are too flawed to merit their inclusion as default
> choices for Ring apps and the binding
On Jan 15, 1:37 pm, e wrote:
> What would be a good way to implement quicksort in clojure (or any
> persistent language)?
Lennart Augustsson's point is that destructive updates are part of the
Quicksort algorithm. If we accept that, then you'd want to use a plain
old java array in your algorithm
On Jan 15, 2:54 pm, wubbie wrote:
> But in partial desctructuring, [[a [b]] has extra pair of outer-most
> [] which leads to confusion. Any explanation on that?
Extra pair of []? What do you mean?
The destructuring pattern is: [[a [b]] & leftover]
The pattern you're matching is: (("one" ("two")
On Jan 18, 4:24 pm, Stuart Sierra wrote:
> After thinking a while about the discussion about test-is groups.google.com/group/clojure/browse_thread/thread/59e9cebbe67cab3f/
> 508f1e8de753455c>, here's a short article with my current thoughts:
>
> http://stuartsierra.com/2009/01/18/tests-are-code
On Jan 19, 6:24 pm, Luke Amdor wrote:
> I also think that if your test needs a description of what it's doing,
> then that's a smell. It's an excuse for easily readable code and I
> think we can all agree that we should try to make our code as easily
> readable as possible.
The code can tell you
On Jan 19, 6:44 pm, Stuart Sierra wrote:
> > 1. I don't like the idea of putting tests next to the functions
> > they're testing.
>
> That's cool with me, I won't force you to do it one way or the other.
And here I was ready to start a holy crusade against you ;)
Honestly, it's cool with me too
On Jan 19, 8:12 pm, ".Bill Smith" wrote:
> Would you mind elaborating on that point? At a previous job, I worked
> on a corporate banking application that had numerous configuration
> settings. Thousands of companies used the application. It was
> impractical to test the application with ever
On Jan 21, 9:39 pm, Frank wrote:
> I am interested in trying to use Clojure to develop web-based
> applications. Can someone point me to any Clojure libraries that have
> been written that I can use. Thanks.
There's Compojure, which looks like this:
(defservlet demo-servlet
(GET "/"
(ht
On Jan 22, 10:15 pm, Frank wrote:
> I found two libraries written by Christophe Grand:
Only Enlive was written my Christophe; Ring was written by Mark. From
what I gather Ring is an abstraction layer like Rack, and isn't
designed to be used directly to build web applications. Rather, it's a
comm
On Jan 25, 5:34 pm, wubbie wrote:
> What's the typical usage of fn constantly ?
When you need a function that constantly returns the same result :)
That probably doesn't tell you any more than you know already, so I'll
give you a real world use. My rnd-utils library has a function
generating ra
Hi folks,
I've recently found myself having to choose between dividing
functionality between many specific namespaces, or having a few very
generic namespaces. In theory, being specific is the better choice, as
it allows users to more accurately pick what they want to use. But if
most of the time
On Jan 26, 10:29 pm, Cosmin Stejerean wrote:
> Can you help me understand the difference between this and use (or :use in
> ns)?
use is internal to the current namespace. You can use other namespaces
without their publics being added to the current namespace. So:
=> (ns a)
=> (def x 10)
=> (ns
On Jan 27, 2:08 am, Mark Volkmann wrote:
> Let's see if I've got this straight.
>
> (def foo 1) creates a Var in the default namespace with a value of 1.
>
> (create-ns 'com.ociweb.demo) ; creates a new namespace
> (intern 'com.ociweb.demo foo 2) ; creates another Var named foo, but
> it's not in
Name: Compojure
URL: http://github.com/weavejester/compojure
Author: James Reeves
Categories: web
License: EPL
Dependencies: clojure.contrib, a Java servlet container (e.g. Jetty)
Description:
Compojure is a web framework that emphasizes a thin I/O layer and a
On Jan 31, 3:06 am, Jeffrey Straszheim
wrote:
> Does anyone know of a gentle introduction to the Zipper stuff, and how
> it is used in Clojure?
My understanding of zippers is that they are a way of efficiently
navigating a tree data structure in a functional manner. So if we have
the tree:
On Jan 30, 4:00 pm, eyeris wrote:
> While testing Compojure, I've been using the embedded Jetty API. This
> has been convenient for getting up and running quickly. However I
> don't like having to restart my script each time I need to test a
> change.
I'd advise moving the code that starts the J
In Feb 1, 2:32 am, e wrote:
> I don't understand this: (def z (zip/zipper rest rest cons t))
>From the API docs on zipper:
(zipper branch? children make-node root)
The branch? predicate is rest, because if a node has children, then
rest will not be nil, and therefore true.
The children pr
On Feb 1, 2:42 am, Mark Volkmann wrote:
> When a function parameter is named "coll", does that generally mean it
> can be any kind of collection except a map?
> For example, the some function takes a predicate function and a
> "coll", but it can't be a map.
I thought all functions with coll took
On Feb 1, 1:27 pm, Jan Rychter wrote:
> (loop [[a b] [1 2]]
> (if (= a 2)
> true
> (recur [(+ a 1) (+ b 1)])))
>
> java.lang.NoClassDefFoundError: clojure/core$loop__4287$fn__4289
> (NO_SOURCE_FILE:1)
> [Thrown class clojure.lang.Compiler$CompilerException]
It works for
On Feb 2, 9:37 am, Tom Ayerst wrote:
> Is there anyone getting together in London to discuss Clojure?
> If so, can anyone play?
> If not, would anyone be interested?
I'm in London, and I might be interested. I tend to have a pretty
tight schedule, though :(
- James
--~--~-~--~~-
On Feb 4, 2:42 am, sbkogs wrote:
> If anybody is working on similar library, please drop me a line. I
> have some bandwidth to spend towards such work/fun.
I created some simple LL parser tools for my Rend library:
http://github.com/weavejester/rend/blob/43f882a9474fb8662007e5a5d0c50648fc0caa7
On Feb 5, 6:03 am, samppi wrote:
> user=> ((array) (seq "[0,0]")) ; This works as intended:
> [[\[ \0 \, \0 \]] nil]
> user=> (value (seq "[0,3]")) ; This should return nil, but a weird
> argument exception is raised instead:
> java.lang.IllegalArgumentException: Key must be integer
> (NO_SOURCE_
Name: Rend
URL: http://github.com/weavejester/rend
Author: James Reeves
Categories: strings, testing
License: EPL
Dependencies: None
Description:
Rend is a library for generating random strings from regular
expressions. Useful for generating test data
On Feb 7, 11:43 pm, samppi wrote:
> I never did figure out exactly why the behavior above occurred, but I
> found a solution for my problem at
> http://groups.google.com/group/clojure/browse_thread/thread/8c78b9934
Yep, if you want to refer to a var that hasn't been defined, wrap your
rule
e-rand":
Name: re-rand
URL: http://github.com/weavejester/re-rand
Author: James Reeves
Categories: strings, testing
License: EPL
Dependencies: None
Description:
re-rand is a library for generating random strings from regular
expressions. U
On Feb 13, 12:10 am, Conrad wrote:
> Hi, is there a standard way to tell if a variable is bound? I couldn't
> find a way.
There's an isBound method on the Var class:
(.isBound #'foo)
But the var has still got to exist, i.e. you have to (declare foo)
first.
If you want to check a var _exists_,
Hi folks,
I've been having some difficulty coming up with a scheme for writing
to files in a thread-safe manner. The files are named with the hash of
their content, so they are effectively immutable.
The problem comes with writing them for the first time. I need to
ensure that while a file is in
On Feb 14, 5:30 pm, Dan wrote:
> What about making the file an agent and sending write actions to it?
I don't see how that would solve the problem, unless you're suggesting
that I have a single agent to handle all reads and writes?
- James
--~--~-~--~~~---~--~~
Y
On Feb 14, 10:58 pm, Laurent PETIT wrote:
> You could maybe solve the read problem by also embedding, in the name of the
> file, its intended content size ?
That solves the read problem, but not the conflicting write problem.
It also seems harder than using a temporary file.
> If the file is im
On Feb 15, 12:42 pm, Laurent PETIT wrote:
> Well, so indeed, the temporary file solution seems a good one, then.
The consensus seems to be to use a temporary file, then. I had thought
there might be a flashy cutting-edge way of handling this sort of IO,
but I guess sometimes the best solutions a
On Feb 15, 5:18 pm, Rich Hickey wrote:
> The second option is to choose the best possible names, and deal with
> some short term pain in porting and confusion. I think the best names
> are:
>
> ;item
> (first x)
>
> ;collection of remaining items, possibly empty
> (rest x)
>
> ;seq on next item,
On Feb 16, 2:22 pm, Mibu wrote:
> rest is expected to be a sequence by Lispers, and next is expected to
> be an item by Java-ers.
I actually think next is pretty close to the next method on Java
iterators. In java.util.Iterator, the next method evaluates the next
item, increments state the itera
(ns html-table
(:use clojure.contrib.prxml)
(:use clojure.contrib.seq-utils))
(defn print-table [grid selected]
(prxml
[:table {:cellpadding 30, :bgcolor "#aa"}
(for [[x row] (indexed grid)]
[:tr
(for [[y cell] (indexed row)]
[:td {:bgcolor (if (=
Fahed Alrafidi wrote:
> How do I create a web service on Clojure? Thank you.
Depends what sort of web service. A simple RESTFUL web service is
pretty easy to develop in Compojure:
(ns web-service
(:use compojure))
(defservlet math-servlet
(POST "/add"
(let [x (Integer/parseInt (params :
On Feb 18, 5:38 am, CuppoJava wrote:
> (defn remove_at [coll & indexes]
> (map second
> (remove #(some #{(first %)} indexes) (map vector (iterate inc
> 0) coll
I'd have thought you could use dissoc, but it seems that only assoc
works with vectors. I wonder if this is an oversight or
On Feb 18, 8:25 pm, linh wrote:
> hello,
> what is the idiomatic way to do the following in clojure?
>
> # ruby pseudo
> arr = [3 9 4 5]
> arr[1] = 7
=> (def arr [3 9 4 5])
#'user/arr
=> (assoc arr 1 7)
[3 7 4 5]
Note that because Clojure data structures are immutable, assoc only
returns the ch
On Feb 21, 2:36 pm, bOR_ wrote:
> Note that clojure just changed the lazy branch to be the main version
> of clojure, so right now clojure-contrib and the latest svn do not
> play nicely yet. I belief there is a old version of clojure-contrib
> available and probably also for clojure-main.
All t
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
On Feb 23, 6:54 pm, Chouser wrote:
> (ns n01se.net.graph.issues
> (:import (java.text SimpleDateFormat ParsePosition)
> (java.util GregorianCalendar Calendar)
> (org.jfree.chart ChartFrame))
> (:use [clojure.zip :only (xml-zip node)]
> [clojure
On Feb 24, 3:11 am, "Michel S." wrote:
> I started Quiche after taking a look at Fact, actually; the difference
> between what I'm proposing and Fact is that the latter is a standalone
> test framework, whereas the random-testing part of Quiche (property)
> and Fact (fact) could, IMHO, be built o
Just to expand on Meikel's answer: when people upload files, it's
usually as an attachment to an existing thread. Reading though the
file list isn't a very good way of learning Clojure, as it's just a
flat list of every file anyone has ever uploaded to the group. Without
the context of the origina
On Feb 27, 6:39 pm, "John D. Hume" wrote:
> As a Java/Ruby guy who is not used to reading inside out, I'm curious
> as to whether people who ARE accustomed to LISP find the -> macro
> distracting since it flops things around. Are there circumstances
> where you prefer it?
It's pretty useful for
The nearest equivalent to Haskell type classes in Clojure are
multimethods, but as Clojure is a dynamically typed language, the
compiler does not enforce the 'interface' defined by the multimethods.
In Clojure, I can't think of any way you could enforce such a contract
at compile time. Clojure is
On Mar 11, 2:31 am, Jon Harrop wrote:
> > 2. The whole thing does not need to be complete or even functional for
> > you to start unit testing.
>
> Apples and oranges: unit tests are not the same between dynamic and static
> code bases because dynamic code bases rely upon a huge number of additio
On Mar 12, 12:26 am, Jon Harrop wrote:
> On Thursday 12 March 2009 00:01:43 James Reeves wrote:
> > This doesn't have to be the case. There is nothing inherently magical
> > about a types that makes them more concise to define than a unit test.
>
> Type inference: yo
On Mar 13, 11:50 pm, Raoul Duke wrote:
> i'm up to date with the clojure jar. the error messages i get seem
> awfully terse and not particularly helpful in learning what i'm doing
> wrong. for example, with the code below, when i try (bs 0 (vector 1 2
> 3)) i get "java.lang.ClassCastException:
>
On Mar 14, 11:44 am, Rock wrote:
> Now, I would love to recode this stuff in Lisp, especially Clojure.
> But is it possible to pull this off? From what I've been reading, it
> actually doesn't seem like it.
It's certainly possible to load in resource at runtime. Indeed, that's
how Clojure's use,
On Mar 16, 11:17 pm, BerlinBrown wrote:
> After many years (decade) of web development, here are the things that
> I want in a framework, mostly based in clojure:
>
> What do you think and what you add. This is ambitious and just a
> "ideas" of what I would add. What would you want from your id
A quick suggestion about rand-int. It would be useful if you could
supply it with a second argument to give a random integer over a
range. For example, (rand-int 5 10) to give a random integer between 5
(inclusive) and 10 (exclusive):
==
On Mar 20, 1:09 am, bgray wrote:
> (defmulti something :os-type)
>
> (defmethod something "Mac OS X" [os x y]
> (+ x y))
Try:
(defmulti something (fn [os x y] (:os-type os)))
- James
--~--~-~--~~~---~--~~
You received this message because you are subscribe
On Apr 5, 5:07 pm, Stuart Halloway wrote:
> Never worry about "foo" vs. (File. "foo") again!
>
> (doc file)
> -
> clojure.contrib.java-utils/file
> ([arg] [parent child] [parent child & more])
> Returns a java.io.File from string or file args.
>
> Notes:
>
> (1) You w
In Compojure, I called this str*, but I think I like as-str a little
better.
- James
On Apr 5, 5:19 pm, Stuart Halloway wrote:
> Never worry about the distinction between symbols, keywords, and
> strings when working with Java APIs that know only strings!
>
> (doc the-str)
> ---
I'd like it if they were combined. You could then use (file "foo/bar")
or (file "foo" "bar").
- James
On Apr 5, 9:25 pm, Stuart Halloway wrote:
> Doh! Missed that. The duck-streams and java-utils versions of file
> have overlapping but disjoint functionality. Other-Stuart, I can take
> a lo
On Apr 6, 4:10 am, Stuart Sierra wrote:
> I don't see an obvious way of combining them.
What about something like:
(defn- normalize-separator
[filepath]
(.. (str filepath)
(replace \\ File/separatorChar)
(replace \/ File/separatorChar)))
(defn file
[filepath & more]
(reduce
On Apr 6, 11:29 am, Jason Sankey wrote:
> I think there may be a misunderstanding over "combining" here - I read
> Stuart's mail to mean there was no obvious way to combine
> duck-streams/file and java-utils/file, whereas this implementation shows
> java-utils/file style behaviour only?
As far a
Hi folks,
A while ago I started writing a unit testing library called Fact that
was a cross between Haskell's QuickCheck, and Ruby's RSpec. I've done
a lot of work with it, and some people might conceivably be interested
in how I got on with it, so this post is to chart what I found whilst
playin
Hi folks,
In the latest versions of Clojure, the :file key in a var's metadata
seems to contain the full path of the file (relative to the
classpath). e.g.
=> (:file ^#'html)
"compojure/html/gen.clj"
=> (:file ^#'map)
"clojure/core.clj"
The get-source function in clojure.contrib.repl-utils seem
On Apr 19, 4:00 pm, Timo Mihaljov wrote:
> What's the idiomatic Clojure way of dealing with this issue?
I'd be tempted to use accessor functions, like:
(defn get-name [person]
(:name person))
When the data structure changes, I update the function:
(defn get-name [person]
(str (:fi
On Apr 21, 11:41 am, Mark Engelberg wrote:
> On Mon, Apr 20, 2009 at 11:00 AM, Timo Mihaljov wrote:
> > Is the concept of Abstract Data Types [1] useful in Clojure?
>
> > If yes, how would you implement one?
>
> I have composed a lengthy response to this question, and added it to my
> blog:http
Hi Vlad,
Are you aware you can compile Clojure code directly into Java class
files?
- James
On Apr 25, 7:10 pm, prhlava wrote:
> Hello,
>
> Currently, I do the following (the clojure application is called
> "isi"):
>
> 1. set-up a java netbeans project (called isi) with main class
> 2. add the
On May 8, 8:40 pm, Emeka wrote:
> Luke
> I was referring to map the data structure. I later decided to use struct
> which is a map. I intend to manipulate elements of each row.
>
> Emeka
Perhaps you could explain in more detail what you intend to do and
why? As Luke says, a "row" suggests a vect
On May 11, 4:42 am, tarvydas wrote:
> I added a full path to my working directory in the CLASSPATH
> environment variable (using the control panel) and that didn't appear
> to help.
In order for gui.Mainframe to work, there needs to be a directory $d
in your classpath such that the file $d/gui/M
On May 28, 2:52 am, Korny Sietsma wrote:
Basically, I have a FileInfo class that wraps a data file, used to
> compare lots of files on my system.
> It has an "exact_match" method similar to:
> def exact_match(other)
> return false if size != other.size
> return false if quickhash() !
On May 28, 9:23 pm, CuppoJava wrote:
> (defblockfn with_surrounding_text [text func]
> (println text)
> (func)
> (println text))
Okay, but it doesn't seem that much neater than just writing the macro
manually:
(defmacro with-surrounding-text [text & body]
`(do (println ~text)
~..
On Jun 12, 4:56 pm, CuppoJava wrote:
> I would approach it like this, and make full use of Clojure's lazy
> sequences:
>
> (count (take-while belowCount (filter identity (map isInteresting
> pixels
This particular piece of code doesn't look like it would work, unless
I've misunderstood what
On Jun 13, 9:17 pm, Laurent PETIT wrote:
> This thread is interesting because we have a solution that is
> suggested : using map then filter then take then count, which will
> result in creating, for at least num pixels, at worst the full number
> of pixels, 2 conses, and 3 times walking the arra
On Jun 13, 7:02 pm, Wrexsoul wrote:
> Nice, but
>
> user=> (count-more-than? 0 ())
> true
>
> (defn count-more-than? [n xs]
> (if (seq xs)
> (or (zero? n)
> (recur (dec n) (rest xs)
True enough. My code didn't take into account that edge case.
- James
--~--~-~--~~---
On Jun 13, 9:39 pm, Laurent PETIT wrote:
> Well, the array is iterated once by map, the new seq created by map is
> iterated once by filter, and the new seq created by filter is iterated
> once by count, so right, I should have written : 3 walks of seqs of
> the size of the array.
The filter and
On Jun 13, 9:57 pm, Laurent PETIT wrote:
> > The filter and map functions produce lazy seqs, so the sequence is
> > only walked once.
>
> Well, isn't walking 3 different sequences 1 time almost equivalent (in
> terms of computer work) to walking 3 times one sequence ?
Well, I guess there's the o
On Jun 13, 4:18 am, Wrexsoul wrote:
> Between files-and-dirs and file-lines-seq I think I have saved as many
> lines of code as are in the macro+helper fns, so those are at break-
> even.
I'm not completely sure what benefit super-lazy-seq is meant to have.
Could you perhaps give an example writ
On Jun 14, 3:21 am, Wrexsoul wrote:
> It lets you write the generator in a style similar to loop/recur, and
> generally in half the code. And, it demonstrates the kinds of things
> you can do with macros.
Ahh, I see. That could be useful under some circumstances. However,
most Clojure functions
On Jun 14, 4:37 am, Wrexsoul wrote:
> Seems to me that unless you completely consume the sequence, it will
> leak a file handle.
That's true, but that's a problem that affects all seqs. There's no
current way to mark a seq that comes from a stream as being discarded
or closed, except by closing
On Jun 14, 4:40 am, Wrexsoul wrote:
> What I miss is foo-array for foo not in #{int long float double},
> particularly for (= foo byte).
You can use (make-array Byte/TYPE size) and (into-array Byte/TYPE byte-
coll).
- James
--~--~-~--~~~---~--~~
You received this
On Jun 14, 3:28 am, tmountain wrote:
> java.lang.IllegalArgumentException: No matching method found:
> setCharAt for class java.lang.StringBuilder (NO_SOURCE_FILE:0)
> user=> (type (char \a))
> java.lang.Character
> ; should be char?
You could try: (.charValue \a)
- James
--~--~-~--~---
On Jun 14, 6:32 pm, Wrexsoul wrote:
> I wrote super-lazy-seq because repeatedly can't generate a finite
> sequence. It just spat out
>
> (File1 File2 File3 File4 nil nil nil nil nil nil nil ...
Well, you could wrap it in take-while:
(defn custom-lazy-seq [stream]
(take-while (complement n
On Jun 15, 4:58 am, Wrexsoul wrote:
> Eh. That didn't occur to me. It could be combined with the meta-nil
> trick, too:
>
> (defn custom-lazy-seq [genfn]
> (map #(first %)
> (take-while (complement nil?)
> (repeatedly genfn
>
> where the genfn returns nil for no-next-item and [i
1 - 100 of 992 matches
Mail list logo