The most general case would be a codec that can have mixture of big
and little endian fields,
so legacy comms protocols or file formats can be supported.
For example:
(defcodec mixed (ordered-map :b :int16, :a :float32-le))
; total 6 bytes, first 2 bytes short in big endian format (JVM
default),
On Fri, Nov 26, 2010 at 5:28 PM, tpeng wrote:
> but this foldr can't handle the infinite list, am i right?
>
I doubt there is a foldr that handles the infinite list.
To do anything, it would have to read at least one element: the last.
Alex nice answer is a foldl.
--
You received this message
"nicolas.o...@gmail.com" writes:
> I doubt there is a foldr that handles the infinite list.
> To do anything, it would have to read at least one element: the last.
>
> Alex nice answer is a foldl.
Actually I think you have them backwards. Wikipedia has a pair of
diagrams which I find very usefu
Hello,
I would like to know if it is possible to find out the name of the
structure from its instance. my attempt to use the function class is not
giving me any useful info. It kept saying that it is a structmap and
nothing more...
Regards,
Sunil
--
You received this message because you are sub
On Nov 27, 6:24 am, Sunil S Nandihalli
wrote:
> Hello,
> I would like to know if it is possible to find out the name of the
> structure from its instance. my attempt to use the function class is not
> giving me any useful info. It kept saying that it is a structmap and
> nothing more...
> Regard
Hello Sunil,
Saturday, November 27, 2010, 11:24:58 AM, you wrote:
> Hello,
> I would like to know if it is possible to find out the name of the
> structure from its instance. my attempt to use the function class is
> not giving me any useful info. It kept saying that it is a structmap and
> no
Hi,
when trying to use FatJar from Eclipse / CCW I manage to get the fatjar to
be generated;
however, when I run the jar I get:
D:\src\Clojure\First>java -jar First_fat.jar
Exception in thread "main" java.lang.UnsupportedOperationException:
First.core/-
main not defined
at First.core.main
Hi,
Perhaps it is a typo but you should have
(defn -main [] ...) rather than (defn- main [] ...)
Note the place of the dash "-".
defn- yields a non public var (a private declaration)
(http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/
defn-)
-main uses the dash, which is the
I think you can either use either defrecord or factory-function +
metadata:
http://bitumenframework.blogspot.com/2010/10/typed-abstractions-in-clojure.html
Regards,
Shantanu
On Nov 27, 4:24 pm, Sunil S Nandihalli
wrote:
> Hello,
> I would like to know if it is possible to find out the name of t
> Thought some Clojure folk might enjoy this:
>
> http://blog.stephenwolfram.com/2010/11/100-years-since-principia-mathematica/
Though I don't use Clojure (I follow this list out of curiosity), I
have a hard time imagining why anything Wolfram writes is interesting,
and furthermore why any a user
user=> (let [a 'b] (str a))
"b"
user=> (let [b 5 a 'b] (eval a))
java.lang.Exception: Unable to resolve symbol: b in this context
(repl-1:7)
user=> (let [a 'b b 5] (eval a))
java.lang.Exception: Unable to resolve symbol: b in this context
(repl-1:9)
user=> (def b 5)
#'user/b
user=> (def a 'b)
#'us
I want to partition a sequence based on the values of a predicate so
that every true starts a new sequence in the partition. Here is an
example of how partition-with could be used:
(partition-when true? '(true false false true false true true))
-> '((true false false) (true false) (true) (true))
cool! Although I think with-seperator should be spelled "with-separator"
--Robert McIntyre
On Thu, Nov 25, 2010 at 9:13 AM, Sunil S Nandihalli
wrote:
> I just tried to re-write with-seperator without using the symbol-macros from
> macro-utils and it seems to work fine ..
>
> On Thu, Nov 25, 201
First of all, thank you for this awesome library.
I'm experimenting with ClojureQL for accessing Postgis, the spacial
extender for Postgres. To improve the ClojureQL for this use case, it
would be useful to have a way to add custom predicates. For example to
find all places whose location column i
Could do it this way. Use index-filter (borrowed from Programming
Clojure) to get the indices where the predicate is true in the
sequence. partition-when-true then just calls subvec with pairs of
indices to get the subsequences.
coll-end is the index just past the end of the collection. This is
partition-by does exactly what you need.
On Sat, Nov 27, 2010 at 3:04 PM, Benny Tsai wrote:
> Could do it this way. Use index-filter (borrowed from Programming
> Clojure) to get the indices where the predicate is true in the
> sequence. partition-when-true then just calls subvec with pairs of
Subvec, however, isn't lazy. This is:
(defn split-when [pred coll]
(let [ipred (complement pred)
bits (iterate
(fn [[out coll]]
(let [[a b] (split-with ipred (rest coll))]
[(cons (first coll) a) b]))
[nil coll])]
(map
2010/11/27 rob levy
> partition-by does exactly what you need.
Nope.
partition-by will split each time the value changes. Not each time a
particular value is seen.
>
>
> On Sat, Nov 27, 2010 at 3:04 PM, Benny Tsai wrote:
>
>> Could do it this way. Use index-filter (borrowed from Programmin
On Sat, Nov 27, 2010 at 4:00 PM, rob levy wrote:
> partition-by does exactly what you need.
Not quite.
user=> (take 10 (partition-by #(= 0 (rem % 3)) (iterate inc 1)))
((1 2)
(3)
(4 5)
(6)
(7 8)
(9)
(10 11)
(12)
(13 14)
(15))
At first it seems you can fix this as follows:
user=> (defn
Something like this?
(defn partition-when [f l]
(reduce #(if (f %2)
(conj %1 (vector %2))
(conj (butlast %1)
(conj (last %1) %2)))
[] l))
On Sat, Nov 27, 2010 at 4:15 PM, Ken Wesson wrote:
> On Sat, Nov 27, 2010 at 4:00 PM, rob levy wrot
On Sat, Nov 27, 2010 at 10:45 AM, Eduardo Julian wrote:
> user=> (let [a 'b] (str a))
> "b"
> user=> (let [b 5 a 'b] (eval a))
> java.lang.Exception: Unable to resolve symbol: b in this context
> (repl-1:7)
> user=> (let [a 'b b 5] (eval a))
> java.lang.Exception: Unable to resolve symbol: b in th
This is more correct, because conj does not preserve the order correctly. I
wonder if there is a more idiomatic way to cons things onto the end of the
list.
(defn partition-when [f l]
(reduce #(if (f %2)
(concat %1 (vector (vector %2)))
(concat (butlast %1)
This is clearer to read though:
(defn partition-when [f l]
(reduce #(if (f %2)
(conj %1 (vector %2))
(conj (vec (butlast %1))
(conj (vec (last %1)) %2)))
[] (vec l)))
On Sat, Nov 27, 2010 at 4:47 PM, rob levy wrote:
> This is more correct
On Sat, Nov 27, 2010 at 4:31 PM, Ken Wesson wrote:
> On Sat, Nov 27, 2010 at 10:45 AM, Eduardo Julian wrote:
>> user=> (let [a 'b] (str a))
>> "b"
>> user=> (let [b 5 a 'b] (eval a))
>> java.lang.Exception: Unable to resolve symbol: b in this context
>> (repl-1:7)
>> user=> (let [a 'b b 5] (eval
One of the biggest frustrations in maintaining the Emacs libraries for
Clojure has been the fact that ELPA, the original package archive for
Emacs, is manually curated, so updates can take a very long time to
propagate. In Emacs 24 (currently under development), they have bundled
the package.el pa
If it's helpful, I have a snapshot of autodoc 0.8.0 on clojars that
I'm using in cake-autodoc: http://clojars.org/org.clojars.rayne/autodoc
On Nov 26, 9:21 pm, James Reeves wrote:
> I've investigated this a little further, and it looks like I was
> misinterpreting the dependency error messages.
>
> Subvec, however, isn't lazy.
That's true. I just realized there's another problem with my approach
as well: it does not preserve elements before the first true index.
user=> (partition-when true? [false true])
([true])
When the result should probably be:
user=> (partition-when true? [false t
thanks Alex for this nice foldr. ;-)
however this lazy-foldr can only be used when the fn can stop by
itself (in this case, it's 'and' which is short-circuited) otherwise
lazy-foldr will never get stop.
i think for a good foldr, the evaluation of #(lazy-foldr f val xs)
should be only forced when
Hi -
I'm surprised your work doesn't generate more interest from folks. I
wish I had more time, I would definitely jump in and help.
On Nov 24, 3:37 pm, Alyssa Kwan wrote:
> Extension
> ofhttp://groups.google.com/group/clojure/browse_thread/thread/7c917e983...
>
> Hi everyone!
>
> I've extende
Thanks for you help.
I was missing sonthing, in fact the class day wasn't where i expected
it to be.
And in addintion i have to say:
Once the importe is done using :
(ns org.codingkata.unit.MyKata
(:import org.codingkata.unit.api.BaseKataSolution
org.codingkata.unit.api.BaseKataSolu
Hi Gijs,
it wasn't a typo, but lack of knowledge :-)
Indeed this is the solution.
Thanks for your help!
Regards,
Arie
2010/11/27 Gijs S.
> Hi,
>
> Perhaps it is a typo but you should have
>
> (defn -main [] ...) rather than (defn- main [] ...)
>
> Note the place of the dash "-".
>
> defn-
On Sat, Nov 27, 2010 at 1:10 PM, Mark wrote:
> Hi -
>
> I'm surprised your work doesn't generate more interest from folks. I
> wish I had more time, I would definitely jump in and help.
Persistence doesn't seem to generate much interest in general. I
posted my own stab at a way of persisting the
My simple web app
(http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
some stuff that needs to happen just once (in this case, opening the
serial port). It's not clear how to get this to happen using ring. If
I do it inside my ring handler, then it gets run on every request, and
I ha
fwiw my folding solution above yields the expected result.
On Sat, Nov 27, 2010 at 7:07 PM, Benny Tsai wrote:
> > Subvec, however, isn't lazy.
>
> That's true. I just realized there's another problem with my approach
> as well: it does not preserve elements before the first true index.
>
> user
Woah. That's as weird as you can get.
Thanks, man.
--
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.
I was trying to use the fnmap API at clojure.contrib for some things
and I needed to add metadata to the function maps but I got this
exception:
java.lang.ClassCastException: clojure.contrib.fnmap.PersistentFnMap
cannot be cast to clojure.lang.IObj
Stuart, can you make PersistentFnMa extend IObjec
Here's a fixed version that...
1. Is lazy everywhere.
2. No longer loses elements :)
(use '[clojure.contrib.seq :only (indexed)])
(defn index-filter [pred coll]
(when pred
(for [[idx elt] (indexed coll) :when (pred elt)] idx)))
(defn subsequence [coll start end]
(take (- end start) (dro
I really dig the succinctness of your folding solutions.
On Nov 27, 5:52 pm, rob levy wrote:
> fwiw my folding solution above yields the expected result.
>
>
>
>
>
>
>
> On Sat, Nov 27, 2010 at 7:07 PM, Benny Tsai wrote:
> > > Subvec, however, isn't lazy.
>
> > That's true. I just realized ther
If you don't mind, I would love to see your version with lazy-seq and
recursion. Seems like that's the idiomatic way of solving problems
like this, judging by the source for the partition functions.
On Nov 27, 10:02 am, Asim Jalis wrote:
> I want to partition a sequence based on the values of a
On Sat, Nov 27, 2010 at 7:50 PM, Mike Meyer
wrote:
> My simple web app
> (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
> some stuff that needs to happen just once (in this case, opening the
> serial port). It's not clear how to get this to happen using ring. If
> I do it insid
Hi,
Normally this is done use an initialization servlet.
You need a separate class inheriting javax.servlet.http.HttpServlet
and a entry in your web.xml file to get it executed once at application
startup.
Look at load-on-startup here:
http://www.caucho.com/resin-3.0/servlet/servlet.xtp#load-on-s
On Sat, Nov 27, 2010 at 9:19 PM, Ken Wesson wrote:
> On Sat, Nov 27, 2010 at 7:50 PM, Mike Meyer
> wrote:
>> My simple web app
>> (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
>> some stuff that needs to happen just once (in this case, opening the
>> serial port). It's not cl
On Sat, Nov 27, 2010 at 8:35 PM, Benny Tsai wrote:
> Here's a fixed version that...
>
> 1. Is lazy everywhere.
> 2. No longer loses elements :)
...
> (defn split-when [pred coll]
> (let [coll-end (count coll)
Er, did you just say "is lazy everywhere"? :)
--
You received this message because
Caveat: since eval-with-local-vars is a macro you won't be able to
directly use it in HOFs. Wrapping it in a closure works, however:
user=> (let [a 1 b 2] (map #(eval-with-local-vars [a b] %) ['(+ a b) '(* a b)]))
(3 2)
--
You received this message because you are subscribed to the Google
Groups
Hi all,
Sorry for my noob question (again). I'm trying to understand clojures
binding model.
Typing:
(def state {:status "foo"})
(def rule '(if (= (:status sate) "foo") (println "foo") (println
("bar")))
(defn fn []
(let [state {:status "bar"}]
(eval rule)))
This prints "foo". However, I wo
That's what I get for coding without taking my afternoon nap :)
Try 3. Tweaked 'subsequence' and 'split-when' so that it is no longer
necessary to calculate the index for the end of the collection. Also
added a check to 'split-when' to return an empty list when called on
an empty collection; oth
Mike Meyer writes:
> My simple web app
> (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
> some stuff that needs to happen just once (in this case, opening the
> serial port). It's not clear how to get this to happen using ring. If
> I do it inside my ring handler, then it gets
You might wanna check out the post I recently made and the answer by
Ken Wesson:
http://groups.google.com/group/clojure/browse_thread/thread/9b042a2ddb8017aa
It's basically the same thing.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to th
On Sat, Nov 27, 2010 at 10:42 PM, Andreas Kostler
wrote:
> Hi all,
> Sorry for my noob question (again). I'm trying to understand clojures
> binding model.
> Typing:
> (def state {:status "foo"})
> (def rule '(if (= (:status sate) "foo") (println "foo") (println
> ("bar")))
>
> (defn fn []
> (let
Is this a 'bug' with eval?
On 28 November 2010 14:09, Ken Wesson wrote:
> On Sat, Nov 27, 2010 at 10:42 PM, Andreas Kostler
> wrote:
> > Hi all,
> > Sorry for my noob question (again). I'm trying to understand clojures
> > binding model.
> > Typing:
> > (def state {:status "foo"})
> > (def rule
On Sat, Nov 27, 2010 at 11:03 PM, Benny Tsai wrote:
> That's what I get for coding without taking my afternoon nap :)
>
> Try 3. Tweaked 'subsequence' and 'split-when' so that it is no longer
> necessary to calculate the index for the end of the collection. Also
> added a check to 'split-when' t
On Sat, Nov 27, 2010 at 11:15 PM, Andreas Kostler
wrote:
> Is this a 'bug' with eval?
It seems to be intended, if undocumented* and sometimes awkward, behavior.
* In that (doc eval) doesn't say anything about this issue.
--
You received this message because you are subscribed to the Google
Gro
Huh, didn't know that about 'distinct'. Thank you for the tip.
On Nov 27, 9:18 pm, Ken Wesson wrote:
> On Sat, Nov 27, 2010 at 11:03 PM, Benny Tsai wrote:
> > That's what I get for coding without taking my afternoon nap :)
>
> > Try 3. Tweaked 'subsequence' and 'split-when' so that it is no lo
I had no issues with swank-clojure 1.3.0:
in project.clj [swank-clojure "1.3.0"]
I had plenty of issues using other libraries as there are some breaking
changes in 1.3. YMMV.
On Thu, Nov 25, 2010 at 05:52, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:
> Hello Everybody,
> I would lik
The servlet interface includes the init method for this exact
purpose. In java, this would be used by subclassing one of the
abstract servlet classes, and filling in the init method with whatever
initialization you need. Or by implementing the servlet interface
directly.
>From the javadoc, the i
This works as I would expect it to.
'rule' brings in 'state' from the global binding into it's scope
giving it priority over the outer scope bindings found in the parent
function.
On Nov 27, 9:15 pm, Andreas Kostler wrote:
> Is this a 'bug' with eval?
>
> On 28 November 2010 14:09, Ken Wesson w
Jason,
Actually Alex was a little off the mark here. The problem was in the
templates that generate the autodoc so they were pretty easy to fix
for all versions.
The github links are now fixed and I expect to modify the assembla
pointers to the new confluence/jira stuff tonight or tomorrow.
Plea
I thought his blog had some interesting points. I enjoyed reading it. Do I
wish Mathematica was more affordable and/or open source? Yes. So what.
That doesn't make Wolfram a lunatic or a fraud. Remember that
mathematicians like Mandelbrot where also considered frauds at first.
On Fri, Nov 26,
Andreas Kostler writes:
> Is this a 'bug' with eval?
No, eval is a simply a function and so like any other function it can't
"see" the lexical (local) environment which it was called from.
Doing this:
(let [a 1, b 2] (eval '(+ a b)))
Is similar to doing this:
(defn cake []
(+ a
>From http://docstore.mik.ua/orelly/java-ent/servlet/ch03_03.htm
-
Just like applets, servlets can define init() and destroy() methods. A servlet's
init(ServletConfig) method is called by the server immediately after the server
constructs the servlet's instance.
60 matches
Mail list logo