I'm struggling to understand exactly what form(s) a Clojure program
can take. In particular, the empty section "The REPL and main entry
points" on the clojure.org web site doesn't help.
Obviously, interacting manually with the REPL is nice for learning the
language, but this becomes tedious as th
I'm new to Clojure so this may be a stupid question.
I want to make a tree out of these things:
(defstruct treeNode :parent :children :data)
so that every node knows which node is its parent and which nodes are
its children.
But, given that these things are immutable, I am baffled as to how th
I'm new to Clojure, just thought I would share this.
I was playing around, trying to understand Atoms and I devised a
function that generates the next value in the Fibonacci sequence each
time it is called.
(def fib-gen-val (atom [1 1]))
(defn fib-gen []
(let [[a b] @fib-gen-val]
(swap! fib
Thanks for these interesting replies - I have some way to go in my
understanding of the power of functional programming.
I look forward to seeing Stuart's chapter 5!
On Feb 16, 11:25 am, Timothy Pratley wrote:
> Also consider (fromhttp://en.wikibooks.org/wiki/Clojure_Programming/Examples):
>
> (
On the page describing Vars, I cannot get the meaning of this sentence
(a typo has made it incomprehensible I think):
"Bindings created with binding can be assigned to, which provides a
means for nested contexts to communicate with code before it the call
stack."
Thanks
--~--~-~--~~-
Can I make a small plea for people who submit source code to PLEASE
insert some sort of explanation of what the code is about.
I know it's usual in programming circles to think that if someone
can't understand something it's because they are dumb - but really -
this is a terribly inefficient way
nderstand, have no complex and ask for
> further explanation !
>
> Regards,
> --
> Laurent
>
> 2009/2/27 timc
>
>
>
> > Can I make a small plea for people who submit source code to PLEASE
> > insert some sort of explanation of what the code is about.
>
> >
Thanks for the responses - very helpful.
On Feb 27, 3:24 pm, Chouser wrote:
> On Fri, Feb 27, 2009 at 10:14 AM, James Reeves
>
> wrote:
>
> > 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 is
After checking out the trunk of clojure-contrib (revision 565) and
doing "ant jar", I get this:
compile_clojure:
[java] Compiling clojure.contrib.accumulators to C:
\eclipseWS1\clojure-cont
rib\classes
[java] java.lang.IllegalArgumentException: fn params must be
Symbols (accum
ulators.c
Thanks Konrad - that did the trick!
On Mar 4, 5:43 pm, Konrad Hinsen wrote:
> On Mar 4, 2009, at 18:21, timc wrote:
>
> > After checking out the trunk of clojure-contrib (revision 565) and
> > doing "ant jar", I get this:
>
> > compi
I would like to have a function which tells me about the values of a
var, where the parameter to the function is a string equal to the
'name' of the var.
For example:
(defn checkNil [name]
"If the var with the given (String) name is nil, display a
message; result = value of var".
(when
Can someone please see what's wrong with this.
(defn getArg [arg]
"Return a [keyword value] depending on the form of the string arg:
1. arg is of the form +x ==> [:x true].
2. arg is of the form -x ==> [:x false].
3. arg is of the form x=v ==> [:x v].
4. el
Thanks David.
On Mar 9, 4:22 pm, David Nolen wrote:
> The first regex is returning an empty list not nil.
> David
>
> On Mon, Mar 9, 2009 at 11:48 AM, timc wrote:
>
> > Can someone please see what's wrong with this.
>
> > (defn getArg [arg]
> > &
I am trying to understand how to use SwingWorker to do time-consuming
work that needs to update a Swing GUI. The following makes a frame
with a button (which starts a SwingWorker on the first click).
Thereafter, clicking the button increments an integer n that is
displayed in the first JTextField
It would be a great pity if there was no way to do this, as
SwingWorker is the 'proper' way for long-running code to interact with
Swing objects.
Any ideas for how to achieve this would be appreciated.
On Mar 19, 7:35 pm, MikeM wrote:
> > However the code (proxy-superpublish m) throws this exce
(catch Exception e (prn e
> (done []
> (prn (str "done"))
> (. cb (setSelected true)))))
>
> ie: don't use the publish/process part but instead put updates on the
> Event Thread explicitly.
>
> On Mar
Is there a way of invoking functions, or java methods "by name" in
Clojure?
Or, put another way, why does this work:
(+ 1 2)
but this does not:
((symbol "+") 1 2)
Similarly, this works
(. javaObj (methodName param))
but this does not:
(. javaObj ((symbol "methodName") param))
I suppose th
ame, use the Java Reflection
> API:http://java.sun.com/docs/books/tutorial/reflect/index.html
>
> -Stuart Sierra
>
> On Apr 26, 10:46 am, timc wrote:
>
> > Is there a way of invoking functions, or java methods "by name" in
> > Clojure?
> > Or,
at you're
> wanting to do.
>
> -Rich
>
> On Sun, Apr 26, 2009 at 11:50 AM, timc wrote:
>
> > Thanks Stuart.
>
> > I have figured out another way, which is much more general (and uses
> > the lowest level of how Clojure works).
>
> > (defn evalStr [s
Can someone please advise me if this is possible:
// --- IX.java ---
interface IX
{
void doit();
void doit(int n);
}
; --- x.clj ---
(def prx (proxy [IX][]
(doit
([] (doseq [x someSeq] (doit x))
([y] (print y
When I tried something of this form, it looks like the call of th
No, its a proxy for an interface.
On Oct 1, 7:22 pm, Jarkko Oranen wrote:
> On Oct 1, 9:18 pm, timc wrote:
>
>
> > (def prx (proxy [IX][]
> > (doit
> > ([] (doseq [x someSeq] (doit x))
> > ([y] (print y
>
> > When I tried something of
Oops, I spoke too hastily -- thank you Jarkko.
On Oct 1, 8:38 pm, timc wrote:
> No, its a proxy for an interface.
>
> On Oct 1, 7:22 pm, Jarkko Oranen wrote:
>
> > On Oct 1, 9:18 pm, timc wrote:
> >
>
> > > (def prx (proxy [IX][]
> > > (
Can someone suggest how to make the packets received on a socket into
a lazy sequence?
The application I'm making is a log file parser. A (Java) program is
producing log output using log4j, the output can go to file(s) or be
sent to a socket. So, the program has this outline:
(defn fileLines [fil
Thanks for the help.
On Oct 30, 1:23 pm, Meikel Brandmeyer wrote:
> Hi,
>
> if you have a stream, you can basically do:
>
> (defn stream-seq
> [stream]
> (take-while #(<= 0 %) (repeatedly #(.read stream
>
> This will give a character at a time. From there you can build the
> lines and tu
Can anyone please advise on how to structure a sort of 'nested lazy
sequence' in this sense:
Given a collection (say*command-line-args*) of file names, how to make
a lazy function that in effect does what clojure.contrib.duck-streams/
read-lines does, but of all the files in sequence.
Thanks
--
Thanks Michal -- however, (multi-read-lines *command-line-args*)
produces this exception:
java.lang.IllegalArgumentException: Mismatched argument count to
recur, expected: 0 args, got: 1
On Jan 28, 12:54 pm, Michał Marczyk wrote:
> On 28 January 2010 13:41, timc wrote:
>
>
Michal
The last, elegant one works -- marvellous!
Thanks a lot.
Tim
On Jan 28, 1:05 pm, Michał Marczyk wrote:
> Ouch, sorry, this won't work with recur... Use an explicit call instead:
>
> (defn multi-read-lines [sources]
> (when-let [source (first sources)]
> (lazy-cat (read-lines source)
The API documentation refers to EvalReader:
Quote
*read-eval* - var - When set to logical false, the EvalReader
(#=(...)) is disabled in the
read/load in the thread-local binding.
Unquote
Is #= an undocumented reader macro character?
And what is the EvalReader anyway? It doesn't appeared to be d
I'm trying to compile a program, with source files as follows.
com/minibar/PmsSimulator.clj -- containing these lines:
(ns com.minibar.PmsSimulator
(:require [com.minibar :as mb] ...etc)
(:load "pmssim/util" ...etc)
(:gen-class))
...etc
where the file com/minibar/pmssim/util.clj contain
Hello
I wonder if I could ask for advice on how to construct a lazy sequence. My
application might be of interest to some of you.
The context for this is that I have an embedded system with very limited
facilities for proper debugging.
I have inserted a 'trace' facility in the embedded code that
That was very helpful - thanks Meikel and Jonathon.
--
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.
Hello
I am a beginner when it comes to writing macros, so there may be an easy
way to do this.
I have a number of 'state machines' which have this sort of appearance:
(defn startFSM [eventQ]
(let [state (atom :1)
going (atom true)
timerId (atom -1)
startTimer (fn []
Thanks Cedric - that's very nice.
I'm beginning to understand the power of macros. I have to say they are not
very well explained in the clojure docs.
In particular, how many distinct 'macro operators' are there, and what are
their precise definitions?
For instance, is ~' a single operator, or is
I often write functions like this:
(defn foobar []
(let [log (makeLogger "foobar")]
blah blah ))
where makeLogger returns a logging function that prefixes all messages with
the name provided.
It looks as though macros don't have a "stringize" ability (like the C
preprocessor) so tha
Hello - I would appreciate some advice on how to implement something
equivalent to sub-classing.
The context for this is a finite state machine (FSM), by which I mean a
thread that waits on a queue of events, then deals with each event (one at
a time) according to the state it is in, possibly c
Hi
Can someone give example of parsing using zetta-parser for the case that
the input stream is intermittent (i.e. possibly incomplete at a particular
moment).
The author of zetta-parser refers to this very possibility in his readme
(for example parsing messages arriving at a socket or such).
How on earth is one supposed to do communication programming (not to
mention handling binary files etc) without an unsigned byte type?
I see that this issue has been talked about vaguely - is there a
solution?
Thanks
--
You received this message because you are subscribed to the Google
Groups "
arrays of bytes
> (Java byte[] and Clojure (byte-array ...))?
>
> I believe these are frequently used for Java I/O, and can be used for
> Clojure I/O as well.
>
> Andy
>
> On Feb 11, 2011, at 9:22 AM, timc wrote:
>
> > How on earth is one supposed to do communica
it
should).
So - what I'm pleading for, is that (byte b) and (int i), (short s),
etc. should simply perform a masking operation (on the appropriate
number of least significant bits) in the way that java clearly does.
On Feb 12, 1:08 pm, timc wrote:
> Sorry I did not make myself clear
011 at 4:54 PM, Aaron Cohen wrote:
> > On Sat, Feb 12, 2011 at 4:42 PM, Ken Wesson wrote:
> >> On Sat, Feb 12, 2011 at 8:28 AM, timc wrote:
> >>> (def b (byte i))
>
> >>> is doing something equivalent to this internally:
>
> >>> byte b =
40 matches
Mail list logo