I'm trying to encode a java string into utf-8 for encapsulation within
an OtpErlangBinary
(http://erlang.org/doc/apps/jinterface/java/com/ericsson/otp/erlang/OtpErlangBinary.html).
When I try to construct an OtpErlangBinary from the results of
String.getBytes(encoding), I get bad data. A string
> Maybe there's something about the particular [ s ] object that you're
> passing in?
I believe that you're right; in general, the getBytes seems to work.
It is just in this one freakish case that it doesn't, but I have no
idea how to tell what's special about my string. I'm not exactly
proficie
> Well, under the covers the str function applies the java "toString"
> method to any passed in object and hence the result could for some
> reason be different to the original String object passed in. I think
> this could occur if the object subclasses String, but has a different
> representation
> I guess that if you enable reflection warnings, you'll get a warning on
> the line where you invoke the constructor.
>
> I think the reflective dispatch doesn't pick the good constructor and
> invokes OtpErlangBitstr(Object) instead of OtpErlangBitstr(byte[]).
> Thus your byte[] is serialized an
> I guess that if you enable reflection warnings, you'll get a warning on
> the line where you invoke the constructor.
As a bit of an aside, is there a reason that using multimethods with
class-based dispatch doesn't add type hints by itself? It seems sort
of strange that it's necessary to defin
> It's a type hint, it's not a type coercion.
>
> Without the type hint, the compiler doesn't know the type of s, so it
> can't find the .getBytes method (nor, of course, its return type) and,
> in doubt, picks the "broader" constructor: OtpErlangBinary(Object).
> With the type hint, the compiler
I'm having some trouble getting clojure to generate .class files. I
have a directory layout like this:
test/
main.clj
where main.clj is the same file as from
http://clojure.org/compilation, but with the 'clojure.examples.hello
replaced with 'test.main . I've tried running clojure a few dif
> You probably need to set (and create!) the correct compilation
> (output) directory. This defaults to a "classes" directory as a
> subdirectory of your current working directory. So if you had:
And this worked! Now that I'm looking for the *compile-path*
variable, I see that it's mentioned in
Is there an example of using :rename in a :use in the ns macro? I'm
trying to get it to work, but the best I can come up with is:
(ns namespace
(:use other-namespace :rename { :existing :newname }))
and when compiling, I get "ClassCastException: java.lang.Boolean
cannot be cast to clojure.lan
> Here's the correct syntax:
>
> (ns namespace
>(:use [other-namespace :rename {existing newname}]))
aha, brackets. Is there a plan to flesh out the API page to have more
examples of things like that? As it stands, I think the API page is
probably great for somebody who needs a reminder, bu
I have a java class whose constructor expects (among other things) a
BlockingQueue. It's easy to create a BlockingQueue in clojure
(obviously), but I can't figure out the syntax to specialize it to the
Long type. Is this possible, or does it even make sense? I seem to
recall that generics are j
> user=> (show Class)
> === public final java.lang.Class ===
> [ 0] static forName : Class (String)
> [ 1] static forName : Class (String,boolean,ClassLoader)
> [ 2] asSubclass : Class (Class)
> [...]
> nil
> user=> (show Class 2)
> # java.la
I have a function to get the path out of a lucene searcher
(documentation at
http://lucene.apache.org/java/2_3_2/api/core/org/apache/lucene/search/IndexSearcher.html).
The searcher has a Reader, which has a Directory. The Directory is
abstract, but in my case I know that it's a FSDirectory, so I
> I thought it might be fun to try out the new repl-utils expression-info fn
> on
> this.
Is this just in source control, or is it in a release? I'm using
1.0.0, and I don't seem to have that function.
> So first I had to recreate your 'import' line (you might consider including
> this
> kind o
> repl-utils is a library in clojure-contrib. Docs here:
>
> http://code.google.com/p/clojure-contrib/wiki/ReplUtilsApiDoc
>
> Source here:
>
> http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/repl_utils.clj
>
> HTH,
Yup, that certainly does help :) Thanks!
--~--
Is there any way for me to tell what exceptions I'm not handling in a
clojure function? javac will yell at me if I don't either handle or
declare every possibility. I don't want the behaviour from clojure,
but having something like *warn-on-reflection* or even a function to
check for exception e
> Clojure is dynamic, and there's simply no way to tell what exceptions
> a function might throw, because functions can be redefined and they
> can take other functions as parameters. On the Java side, the core
> code actually has a catch-all that wraps all exceptions, just to stop
> Java from com
Does clojure still have a concept of a namespace's exports? I'd like
to be able to list, in my ns declaration, the "publicly available"
functions that my module has, but I'm not seeing any way to do this.
It looks like there used to be an export function, and an ns-exports
function to query the e
Most languages I've used define a zip method, where you can take two
lists and get a list of the pairs of elements in those lists. So,
(zip '(1 2 3) '(4 5 6)) would give ([1 4] [2 5] [3 6]). Does clojure
have a core function like that? I've been poking around, but all I'm
finding is zipmap, whi
> map can do this.
>
> user> (map vector '(1 2 3) '(4 5 6))
> ([1 4] [2 5] [3 6])
Yeah, that works pretty well. Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send em
I'd like to add a :signature entry to the attr-map of defn, that
provides a haskell-style type signature to functions of the
single-arglist-body form. I find the the normal way of providing
hints to a function:
(defn [ #^Class1 var1 #^Class2 var2 #^Class3 var3] ... )
is way too noisy, and the v
> - There's already a lot of moving parts to type hinting, so adding
> this optional approach into defn seems like it'd lead to unintended
> consequences. That said, there's absolutely nothing wrong with an
> alternative def form (defh? as in 'define hinted fn') -- there's
> plenty of them throug
> (defh a
>[b:String [c:Double :as list:java.util.List] {d:java.util.Random :d}]
>(.toCharArray b)
>(.size list)
>(.floatValue c)
>(.nextInt d))
What's that :as in the [ c:Double :as list:java.util.List ] vector?
--~--~-~--~~~---~--~~
You recei
> The official docs for this are at: http://clojure.org/
> special_forms#let .
That's a great link. Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to cloju
Does anybody have a download link for the QCon talk that is linked
from the clojure front page? I tend to use platforms where Flash
support is even worse than normal, whereas mplayer tends to be very
good at playing videos on every machine I use.
--
You received this message because you are subs
> If you watch the http traffic, e.g. in firebug, you'll see it makes a
> request to:
>
> http://flv.thruhere.net/presentations/09-mar-persistentdatastructures.flv
>
> You'll have to find the slides on the qcon homepage if you want to
> follow.
Thanks!
--
You received this message because you ar
What is the clojure idiom for running multiple (in this case IO bound)
functions simultaneously? My use case is the parallel activities are
coordinated, basically running in lockstep. I've been using (.start
(Thread. myfn)). It works, but I'm wondering if there's a better way.
The data shared b
> When you send-off an action to an agent, that agent gets is
> allocated a thread for at least the duration of that action. So
> using send-off on long-running actions to two agents will result
> in those actions being run in parallel.
Ok, I re-read the docs on agents, and it looks like they don
> As a major convenience over starting separate threads by hand I would
> use "future". For each invocation future will run a given function on
> a different thread. You can then either dereference each future which
> will block until the function completes or ask if a future has
> completed with "
> java -classpath "C:\Program Files\Clojure\clojure.jar";"C:\Program
> Files\Clojure\clojure-contrib-1.1.0.jar" clojure.main
>
> This starts the repl without a problem, but still, any attempt to use
> a class or function from the contrib library fails, for example,
> running this at the repl...
I'
> I had already tried using a colon as the separator, but it gave an
> error. I've also noticed that if neither path resolves to a file, it
> also errors, so it's finding clojure-contrib-1.1.0.jar.
Can you use it with
(use 'clojure.contrib.duck-streams) ?
Both ways work for me, but it's the only
Just to try to see if clojure is a practical language for doing
byte-level work (parsing files, network streams, etc), I wrote a
trivial function to iterate through a buffer of bytes and count all
the newlines that it sees. For my testing, I've written a C version,
a Java version, and a Clojure ve
> (defn countnl-lite
> [#^bytes buf]
> (areduce buf idx count (int 0)
> (if (= (clojure.lang.RT/aget buf idx) 10)
> (unchecked-add count 1)
> count)))
>
> Key points are initializing count to a primitive integer and directly
> calling clojure's aget to avoid an u
> Replace also (unchecked-add count 1) with (unchecked-add count (int 1))
>
> (this should get easier in 1.3)
That didn't change anything for my tests, but this code:
(defn countnl
[#^bytes buf]
(areduce buf idx count (int 0)
(if (= (aget buf idx) 10)
(unchecked-add
> This one is quite good for me.
> (defn countnl
> [#^bytes buf]
> (let [nl (int 10)]
> (areduce buf idx count (int 0)
> (if (== (int (aget buf idx)) nl)
> (unchecked-inc count)
> count
>
>
> It appears that == is not resolved for bytes. So converting to
> How would that have helped? The problem lay in the fact that there
> could be many subclasses of Document, but only one specific subclass,
> Attachment, could go into the attachments[] field. So if we had to
> split the code into two files, we'd have
>
> class Attachment(Document) # <-- attachmen
I have two (apparently unrelated) questions about ClojureCLR.
First, does Clojure 1.2 build under mono? The clojure-clr tree only
appears to have a .sln file; is there some sane way to convert that to
a Makefile or a shell script that can be used under *nix?
Secondly, has anybody tried deploying
> First of all, MonoDevelop should be able to load the .sln
Ok, I'll have a look at that. I currently know nothing of .NET or
mono, so it's all news to me :)
> As far as XNA...last I heard XNA did not have any support for emit,
> and as such is incapable of running any sort of jit code. Basicall
>> As far as XNA...last I heard XNA did not have any support for emit,
>> and as such is incapable of running any sort of jit code. Basically
>> all .NET code has to be ahead-of-time compiled to run a XBOX via XNA.
>> It's the same limitation that IronPython has
>> (http://ironpython.codeplex.com/w
39 matches
Mail list logo