Re: Newbie : Java Interop question

2010-10-15 Thread Randy Hudson
Nested classes require the syntax AClass$NestedClass -- this being the
real name of the class in the JVM.
Static members of classes are referenced as AClass/member --
essentially treating the class as a namespace of its static members.
So this should do it:

(IEssbase$Home/create IEssbase/JAPI_VERSION)

On Oct 15, 12:32 pm, oak ismail.oka...@gmail.com wrote:
 Hi All,

 This is how i see the package in package explorer.
 IEssbase.class
   (I) IEssbase
       (C, s f) Home
              (M, s) create(String) IEssbase
              (M, c) Home()
        (P, s f) JAPI_VERSION

 I can import like this in Clojure
 =(import `(com.essbase.api.session IEssbase))`

 I can also call the property like this with success.
 =(IEssbase/JAPI_VERSION)
 11.1.1
 =

 In java the code to get this API instance looks like this.

 IEssbase ess = null;
 ess = IEssbase.Home.create(IEssbase.JAPI_VERSION);

 when in Clojure i try the following
 = (.. IEssbase Home create IEssbase.JAPI_VERSION)

 I get the message no such Field exists.

 Do i have to use a proxy since IEssbase is an Interface if so how do i
 make call to create to get instance of API back.

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Agent errors

2010-10-05 Thread Randy Hudson
The docstring for set-error-handler!, to which the docstring for agent
refers, does document the argument list of a handler-fn.

I'd also be interested in an explanation of the new scheme. The
discussion on  http://clojure.org/agents hasn't been updated to 1.2.

On Oct 5, 8:48 pm, Lee Spector lspec...@hampshire.edu wrote:
 On Oct 5, 2010, at 8:31 PM, Lee Spector wrote:



  Do I understand this correctly to mean that the new and improved way that 
  agent errors are handled in 1.2 is to fail silently and leave any pending 
  awaits hanging without comment? I'm having a hard time imagining how this 
  could be a good thing. If I want to know about errors (preferably by 
  getting meaningful error messages) should I convert my agent code to use 
  other concurrency mechanisms like pmap or futures?

 Posted too soon -- browsing the new documentation I found the error-handler 
 argument to agent. It took reading the source to find out that the supplied 
 function should take two arguments, the agent and the exception. I don't see 
 the rationale for the defaults -- wouldn't it be reasonable to report errors 
 by default? -- but I can use this to get what I need.

 Sorry for jumping the gun on that.

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: big integers in 1.2 leading to parked processes? (maybe somehow, I think)

2010-10-03 Thread Randy Hudson
One thing that did change between 1.1 and 1.2 is agent error handling.
The 1.2 changes doc  (http://github.com/clojure/clojure/blob/1.2.x/
hanges.txt) shows several new agent error handling functions, a couple
of deprecated ones, an improved 'await docstring -- which now says:

 Blocks the current thread (indefinitely!) until all actions
  dispatched thus far, from this thread or agent, to the agent(s) have
  occurred.  Will block on failed agents.  Will never return if
  a failed agent is restarted with :clear-actions true.

So I'm surmising that you have a failed agent, and because of the 1.2
changes you're not getting the same kind of error indication you were
apparently expecting.

-- Randy

On Oct 3, 9:59 am, Lee Spector lspec...@hampshire.edu wrote:
 Although this isn't yet making any real sense to me I believe I MAY have 
 traced an elusive problem in code that I ported from clojure 1.1 to 1.2 to 
 the way in which big integers are handled in 1.2. I've seen (and participated 
 in) some conversations about handling bignums but I don't recall what 
 particular changes were slated to happen in the change from 1.1 to 1.2 or to 
 1.3-in-progress -- can someone point me to a summary?

 Regardless of what is supposed to change which each version (and if I recall 
 correctly some of the changes are things that I won't love...) I think that 
 the behavior that I've observed may point to a bug because I'm not getting 
 numeric exceptions or incorrect numeric results but rather hung processes 
 awaiting agent send results. The computations being performed in the forms 
 that I send to the agents aren't stuck in infinite computations -- the CPU 
 usage goes to near zero and eclipse's debugger shows the thread pool threads 
 suspended (but I don't get any an agent had errors messages). They look to 
 me like they're deadlocked, but I can't understand how they could be, since 
 none of the computations in the send forms uses any concurrency primitives 
 that might block.

 I don't have any direct evidence that it's the numerics at all, and I have 
 not yet been able to produce a repeatable example that reliably produces the 
 problem -- this emerges only after a long time in a system that involves a 
 lot of randomness -- but after exploring many other options I found that if I 
 could prevent the problem by lowering one of my numeric limits. I think I've 
 ruled out other obvious candidates for this behavior, and lowering the limits 
 does seem to fix the problem, so I'm beginning to think that it really might 
 be the numerics.

 Does anyone have an idea of anything in the 1.2 numerics that might be 
 responsible for this? If so, then I hope I'm correct in assuming that that 
 should be fixed. Producing an exception or an incorrect result are both bad 
 enough -- I'd personally have automatic promotion to prevent such things even 
 at a small cost for all math -- but mysteriously hung processes are certainly 
 worse.

 Here are the stacks as shown in the eclipse debugger when I'm in the hung 
 state. Each of my thread pool threads looks like this:

 Thread [pool-1-thread-2] (Suspended)    
         Unsafe.park(boolean, long) line: not available [native method]  
         LockSupport.park(Object) line: 158      
         AbstractQueuedSynchronizer$ConditionObject.await() line: 1925 [local 
 variables unavailable]    
         LinkedBlockingQueueE.take() line: 399 [local variables unavailable] 
    
         ThreadPoolExecutor.getTask() line: 947 [local variables unavailable]  
   
         ThreadPoolExecutor$Worker.run() line: 907 [local variables 
 unavailable]
         Thread.run() line: 637 [local variables unavailable]    

 And my main thread -- the one that is stuck at await -- looks like this:

 Thread [main] (Suspended)      
         Unsafe.park(boolean, long) line: not available [native method]  
         LockSupport.park(Object) line: 158      
         
 CountDownLatch$Sync(AbstractQueuedSynchronizer).parkAndCheckInterrupt() line: 
 747      
         
 CountDownLatch$Sync(AbstractQueuedSynchronizer).doAcquireSharedInterruptibl 
 y(int) line: 905    
         
 CountDownLatch$Sync(AbstractQueuedSynchronizer).acquireSharedInterruptibly( 
 int) line: 1217    
         CountDownLatch.await() line: 207 [local variables unavailable]  
         core.clj line: 2485    
         core$await(RestFn).applyTo(ISeq) line: 138      
         core.clj line: 540      
         clojush.clj line: 1549  
         clojush$pushgp(RestFn).invoke(Object, Object, Object, Object, Object, 
 Object, Object, Object, Object, Object, Object, Object, Object, Object, 
 Object, Object, Object, Object, Object, Object) line: 1178        
         regression.clj line: 281        
         Compiler.eval(Object, boolean) line: 5424      
         Compiler.load(Reader, String, String) line: 5857        
         RT.loadResourceScript(Class, String, boolean) line: 340
         RT.loadResourceScript(String, boolean) line: 327        
      

Re: big integers in 1.2 leading to parked processes? (maybe somehow, I think)

2010-10-03 Thread Randy Hudson
Oops, that changes doc is
http://github.com/clojure/clojure/blob/1.2.x/changes.txt

On Oct 3, 6:52 pm, Randy Hudson randy_hud...@mac.com wrote:
 One thing that did change between 1.1 and 1.2 is agent error handling.
 The 1.2 changes doc  (http://github.com/clojure/clojure/blob/1.2.x/
 hanges.txt) shows several new agent error handling functions, a couple
 of deprecated ones, an improved 'await docstring -- which now says:

  Blocks the current thread (indefinitely!) until all actions
   dispatched thus far, from this thread or agent, to the agent(s) have
   occurred.  Will block on failed agents.  Will never return if
   a failed agent is restarted with :clear-actions true.

 So I'm surmising that you have a failed agent, and because of the 1.2
 changes you're not getting the same kind of error indication you were
 apparently expecting.

 -- Randy

 On Oct 3, 9:59 am, Lee Spector lspec...@hampshire.edu wrote:



  Although this isn't yet making any real sense to me I believe I MAY have 
  traced an elusive problem in code that I ported from clojure 1.1 to 1.2 to 
  the way in which big integers are handled in 1.2. I've seen (and 
  participated in) some conversations about handling bignums but I don't 
  recall what particular changes were slated to happen in the change from 1.1 
  to 1.2 or to 1.3-in-progress -- can someone point me to a summary?

  Regardless of what is supposed to change which each version (and if I 
  recall correctly some of the changes are things that I won't love...) I 
  think that the behavior that I've observed may point to a bug because I'm 
  not getting numeric exceptions or incorrect numeric results but rather hung 
  processes awaiting agent send results. The computations being performed in 
  the forms that I send to the agents aren't stuck in infinite computations 
  -- the CPU usage goes to near zero and eclipse's debugger shows the thread 
  pool threads suspended (but I don't get any an agent had errors 
  messages). They look to me like they're deadlocked, but I can't understand 
  how they could be, since none of the computations in the send forms uses 
  any concurrency primitives that might block.

  I don't have any direct evidence that it's the numerics at all, and I have 
  not yet been able to produce a repeatable example that reliably produces 
  the problem -- this emerges only after a long time in a system that 
  involves a lot of randomness -- but after exploring many other options I 
  found that if I could prevent the problem by lowering one of my numeric 
  limits. I think I've ruled out other obvious candidates for this behavior, 
  and lowering the limits does seem to fix the problem, so I'm beginning to 
  think that it really might be the numerics.

  Does anyone have an idea of anything in the 1.2 numerics that might be 
  responsible for this? If so, then I hope I'm correct in assuming that that 
  should be fixed. Producing an exception or an incorrect result are both bad 
  enough -- I'd personally have automatic promotion to prevent such things 
  even at a small cost for all math -- but mysteriously hung processes are 
  certainly worse.

  Here are the stacks as shown in the eclipse debugger when I'm in the hung 
  state. Each of my thread pool threads looks like this:

  Thread [pool-1-thread-2] (Suspended)    
          Unsafe.park(boolean, long) line: not available [native method]  
          LockSupport.park(Object) line: 158      
          AbstractQueuedSynchronizer$ConditionObject.await() line: 1925 
  [local variables unavailable]    
          LinkedBlockingQueueE.take() line: 399 [local variables 
  unavailable]    
          ThreadPoolExecutor.getTask() line: 947 [local variables 
  unavailable]    
          ThreadPoolExecutor$Worker.run() line: 907 [local variables 
  unavailable]
          Thread.run() line: 637 [local variables unavailable]    

  And my main thread -- the one that is stuck at await -- looks like this:

  Thread [main] (Suspended)      
          Unsafe.park(boolean, long) line: not available [native method]  
          LockSupport.park(Object) line: 158      
          
  CountDownLatch$Sync(AbstractQueuedSynchronizer).parkAndCheckInterrupt() 
  line: 747      
          
  CountDownLatch$Sync(AbstractQueuedSynchronizer).doAcquireSharedInterruptibl 
  y(int) line: 905    
          
  CountDownLatch$Sync(AbstractQueuedSynchronizer).acquireSharedInterruptibly( 
  int) line: 1217    
          CountDownLatch.await() line: 207 [local variables unavailable]  
          core.clj line: 2485    
          core$await(RestFn).applyTo(ISeq) line: 138      
          core.clj line: 540      
          clojush.clj line: 1549  
          clojush$pushgp(RestFn).invoke(Object, Object, Object, Object, 
  Object, Object, Object, Object, Object, Object, Object, Object, Object, 
  Object, Object, Object, Object, Object, Object, Object) line: 1178        
          regression.clj line: 281        
          Compiler.eval(Object

Re: Using Enum Qt.AlignmentFlag ClassNotFoundException

2010-09-21 Thread Randy Hudson
Try Qt$AlignmentFlag

On Sep 21, 6:20 am, Matt Hoyt mrho...@yahoo.com wrote:
 I trying to use QtJambi and I'm having problems using the enums that
 have this format Qt.EnumName.

 Error:

 error: java.lang.ClassNotFoundException

 Code:

 (ns collab-web-qt.dialog.connect
   (:import (com.trolltech.qt.gui QDialog QWidget QVBoxLayout QFormLayout
 QLineEdit)
            (com.trolltech.qt.core.Qt.AlignmentFlag)))

 (defn -create-username-field [#^QWidget parent])

 (defn -create-password-field [#^Widget parent])

 (defn -create-retype-password-field [#^Widget parent])

 (defn -create-login-form [#^QWidget parent]
   Used to create the login form.
 Returns the list of fields and the layout manager.
   (let [username (-create-username-field parent)
         password (-create-password-field parent)
         retype-password (-create-retype-password-field parent)
         layout (new QFormLayout parent)]
     (doto layout
       (. addRow Username: username)
       (. addRow Password: password)
       (. addRow Retype-Password: retype-password)
       (. setLabelAlignment (Qt.AlignmentFlag/AlignRight)))
     (list username password retype-password layout)))

 (defn -create-layout [#^QWidget parent]
   Creates and layouts the widgets.
   (doto (new QVBoxLayout parent)))

 (defn connect [#^QWidget parent]
   Creates the dialog to connect to the server.
   (let [dialog (new QDialog parent)]
     (doto dialog
       (. setLayout (-create-layout dialog)

 Matt

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Interesting Paper on Macros

2010-09-12 Thread Randy Hudson
Here's the teaser, er, I mean abstract:

Existing macro systems force programmers to make a choice between
clarity of specification and robustness. If they choose clarity, they
must forgo validating significant parts of the specification and thus
produce low-quality language extensions. If they choose robustness,
they must write in a style that mingles the implementation with the
specification and therefore obscures the latter.
This paper introduces a new language for writing macros. With the new
macro system, programmers naturally write robust language extensions
using easy-to-understand specifications. The system translates these
specifications into validators that detect misuses—including
violations of context-sensitive constraints—and automatically
synthesize appropriate feedback, eliminating the need for ad hoc
validation code.

Haven't read the whole thing yet, but it seems promising.

On Sep 12, 9:29 am, Base basselh...@gmail.com wrote:
 HI Clojurians -

 I found a reference to this interesting paper on macros on Lamda the
 Ultimate.  An interesting read by the our old friend Matthias
 Felleisen who helped many of us learn Lisp.

 http://www.ccs.neu.edu/scheme/pubs/icfp10-cf.pdf

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Knowing in advance the complexity of count

2010-09-09 Thread Randy Hudson
Inexplicably (counted? abcd) returns false.

On Sep 9, 11:33 am, Sunil S Nandihalli sunil.nandiha...@gmail.com
wrote:
 actually there is a function called

 counted?

 Sunil.

 On Thu, Sep 9, 2010 at 8:59 PM, Nicolas Oury nicolas.o...@gmail.com wrote:
  Thank you very much.

  Never looked closely at count definition.

  I assumed it was a forawrd to .count of Counted, which explains my problem.

  I kind of remembered the O(1) of Counted and get mixed up.

  Best regards,

  Nicolas.

  On Thu, Sep 9, 2010 at 3:50 PM, Meikel Brandmeyer m...@kotka.de wrote:
   Hi,

   On 9 Sep., 16:45, Nicolas Oury nicolas.o...@gmail.com wrote:

   is it a way to do so?

   You can check the Counted marker interface for clojure collections.
   But this won't cover Strings etc. More information here:

 http://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT...

   Sincerely
   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 that posts from new members are moderated - please be patient with
  your first post.
   To unsubscribe from this group, send email to
   clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com
   For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en

  --
  Sent from an IBM Model M, 15 August 1989.

  --
  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 group, send email to
  clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: trouble using nested map fn

2010-08-23 Thread Randy Hudson
Well, #(= lo % hi) is to my mind much more readable than (fn [x] (=
lo x hi)), especially embedded in another form or two (as it would
be).

On Aug 23, 11:48 am, gary ng garyng2...@gmail.com wrote:
 On Mon, Aug 23, 2010 at 8:31 AM, Luka Stojanovic li...@magrathea.rs wrote:
  It's not about nested maps, but about nested anonymous functions: if you
  nest anonimous functions you must use (fn [] ...) like:

  (map (fn [t s] (map #(map * %1 %2) t s)) target signal)

 This has me question, how useful the #(...) form is as clojure's
 lambda form i.e. (fn [t s] ...) is already very clean and it conveys
 more information of what it is than the relatively cryptic %1 %2 ...

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Protocols and default method implementations

2010-08-12 Thread Randy Hudson
Protocols are very similar to Java interfaces: they specify a set of
functions/methods without providing an implementation. The big
distinction is in more dynamic usage. Rich Hickey's description at
http://clojure.org/protocols is well written.


On Aug 12, 7:52 pm, Tim Daly d...@axiom-developer.org wrote:
 I find that I'm horribly confused at this point about what a
 protocol is. Can someone use some other comp. sci. terms to
 define this idea? I thought of them as Java interfaces with
 default methods but clearly I'm wrong.



 Sean Devlin wrote:
  I've posted a follow up to my article yesterday about protocols  code
  reuse.  In today's article I discuss what I've termed partially
  implemented protocols, which is geared toward providing a default
  implementation.  Granted, it's a bit ugly and I'll be the first to
  admit that it starts to confuse the difference between a protocol 
  implementation.  Still, it cuts down on the bookkeeping required.

 http://fulldisclojure.blogspot.com/2010/08/partially-implemented-prot...

  Have fun
  Sean

  On Aug 12, 3:16 pm, Nicolas Oury nicolas.o...@gmail.com wrote:

  Can I erase my last mails?

  I just discovered (.bar (Foo. 5)) = 5

  It is a bit embarrassing. Sorry about that. (I am not a Java person, I 
  reckon)

  As far as traits are concerned, I think they can be made with a couple
  of macros.
  I might try to have a go over the week-end.

  Best,

  Nicolas.

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: take-while2?

2010-08-07 Thread Randy Hudson
Andreas, there's no such function in Clojure core, and I'm fairly sure
there's not one in contrib.

Stop reading if you don't want to see my version; it was a fun little
puzzle.

(defn take-while-reduction [f pred coll]
  (let [rf (juxt #(reductions f %) identity)]
(- coll rf (apply map vector) (take-while #(- % first pred))
(map second

On Aug 7, 1:44 pm, Andreas Liljeqvist bon...@gmail.com wrote:
 Thanks that works.

 What I really want is a function like in my initial posting.
 Is there something like that in core or contrib?

 Your example code can be quite slow since all sublists are summed before
 comparision.
 I would like a function that does this with a accumulator for the reduced
 values.

 I am not asking somebody to write this for me - I just want to know if it
 exists

 btw: take-until isn't a bad name

 2010/8/7 Steve Purcell st...@sanityinc.com



  Oh, right, so maybe:

  (last (take-while #( (apply + %) 100) (reductions conj [] (iterate inc
  0
  = [0 1 2 3 4 5 6 7 8 9 10 11 12 13]

  -Steve

  On 7 Aug 2010, at 13:57, Andreas Liljeqvist wrote:

  It should use + for reducing the taken list.
  Behind the scenes I would envision some accumulator passed to pred.
  This examples takes elements while their total sum is less than 100.

  2010/8/7 Steve Purcell st...@sanityinc.com

  On 7 Aug 2010, at 11:15, bonega wrote:

   Hi.

   Are there some function like this:

   (defn take-while2 [f pred coll] ...

   usage: (take-while2 + #( % 100) (iterate inc 0))
   returns: (0 1 2 3 4 5 6 7 8 9 10 11 12 13)

  I'm feeling a bit stupid because I can't see from the above example how
  take-while2 is supposed to work. Can you clarify please?

  -Steve

  --
  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 group, send email to
  clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com
   
  For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

  --
  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 group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

   --
  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 group, send email to
  clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com 
  
  For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: take-while2?

2010-08-07 Thread Randy Hudson
Nice!

On Aug 7, 11:56 pm, Michał Marczyk michal.marc...@gmail.com wrote:
 Yet another version:

 (defn take-while-acc [f pred coll]
   (map (fn [_ x] x)
        (take-while pred (reductions f coll))
        coll))

 Seems to work:

 user (take-while-acc + #( % 100) (range))
 (0 1 2 3 4 5 6 7 8 9 10 11 12 13)

 Note that reductions does use an accumulator (in the form of a
 closed over local), so the above works as requested. Also, this
 version constructs no auxiliary data structures, not even two-element
 vectors.

 Sincerely,
 Michał

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: 2 links for beginners

2010-08-05 Thread Randy Hudson
Here's a nice commentary by fogus on Yegge's piece:
http://blog.fogus.me/2009/02/06/yegge-clojure-arc-and-lolita-or-days-of-future-past/

For all intents and purposes, Clojure’s creator Rich Hickey is Arc’s
Torvalds quipped on by Mr. Yegge. 

On Aug 5, 8:08 am, faenvie fanny.aen...@gmx.de wrote:
 http://steve-yegge.blogspot.com/2006/04/lisp-is-not-acceptable-lisp.html

 a prophetic writing ... great !

 thank you mike.

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Need help with syntax for implementing multiple arity protocol method

2010-08-04 Thread Randy Hudson
You need to name the protocol before the method implementations.
That's why the PersistentList cannot be cast to Symbol message --
the compiler's expecting a protocol (or interface) symbol after [r].

And, as the examples on http://clojure.org/protocols show, you need to
define the different arities of method-two separately:

(defrecord record-two [r]
  protocol-two
(method-two [x] (str x))
(method-two [x y] (str x : y)))

Also note that all the examples use capitalized names for protocols
and records. And I'm dubious about the hyphens in those names, too. I
would have gone with  ProtocolTwo (or Protocol2) and Record2.

On Aug 4, 3:59 pm, James jamesbo...@gmail.com wrote:
 I am having trouble getting syntax right when defining a protocol
 function/method with multiple arities.  When the defrecord is
 evaluated I get:

 java.lang.ClassCastException: clojure.lang.PersistentList cannot be
 cast to clojure.lang.Symbol
   [Thrown class java.lang.RuntimeException]

 I have tried different variations, but cannot seem to get it right.
 Please point out what I am doing wrong.

 The repl:
 user *clojure-version*
 {:major 1, :minor 2, :incremental 0, :qualifier RC1}
 user (defprotocol protocol-two
           (method-two [x] [x y]))
 protocol-two
 user (defrecord record-two [r]
         (method-two ([x] (str x))
                     ([x y] (str x : y

 Thanks for the help.

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: = and byte arrays

2010-08-03 Thread Randy Hudson
(= (seq ba1) (seq ba2)) will give you a value (byte-by-byte)
comparison.

On Aug 3, 2:00 pm, Steven Devijver steven.devij...@gmail.com wrote:
 Given two byte arrays that have the same content (value) the code
 below runs without errors:

 (def ba1 (...))
 (def ba2 (...))

 (assert (not= ba1 ba2))
 (assert (= (String. ba1) (String ba2)))

 Is this as expected?

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: dtd question

2010-08-01 Thread Randy Hudson
Hi Manfred,

I'm sorry the code wasn't quite correct. The EntityResolver is set on
the parser's XMLReader, not on the parser itself:

(def parser (.newSAXParser (SAXParserFactory/newInstance))
(.setEntityResolver (.getXMLReader parser) resolver)

You don't need any external jars: all the classes and interfaces are
in the JRE.

On Aug 1, 5:31 am, Manfred Lotz manfred.l...@arcor.de wrote:
 Hi Randy,
 Thanks for your help. A bit late my answer because in the meantime I was
 on vacation and only now found the time to pursue it further.

 On Tue, 29 Jun 2010 18:53:30 -0700 (PDT)





 RandyHudson randy_hud...@mac.com wrote:
  Yes, you can do this by defining an EntityResolver that corrects the
  bad system id, define a SAXParser that uses that resolver, and pass
  the parser into the xml/parse call. Something like this:

  (import
    '[javax.xml.parsers SAXParserFactory]
    '[org.xml.sax EntityResolver InputSource])

  (def resolver
    (proxy [EntityResolver] []
      (resolveEntity [public-id system-id]
        (InputSource.
          (if (= system-id the-bad-system-id)
            the-good-system-id
            system-id)

  (def parser
    (doto (.newSAXParser (SAXParserFactory/newInstance))
      (.setEntityResolver resolver)))

  (defn parse-xml [source] (xml/parse source parser))

 The problem I have with it is that I don't seem to find the right jar.
 I get an exception like this:

 Exception in thread main java.lang.IllegalArgumentException: No
 matching method found: setEntityResolver for class
 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl (test.clj:14)

 I tried sax2r2.jar fromhttp://www.saxproject.org/.

 --  
 Manfred

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: dtd question

2010-08-01 Thread Randy Hudson
Right you are Michael; sorry for the missing paren at the end of the
def.

On Aug 1, 11:59 am, Michael Wood esiot...@gmail.com wrote:
 On 1 August 2010 17:15, Manfred Lotz manfred.l...@arcor.de wrote:





  Hi Randy,

  On Sun, 1 Aug 2010 06:23:58 -0700 (PDT)
  Randy Hudson randy_hud...@mac.com wrote:

  Hi Manfred,

  I'm sorry the code wasn't quite correct. The EntityResolver is set on
  the parser's XMLReader, not on the parser itself:

  (def parser (.newSAXParser (SAXParserFactory/newInstance))
  (.setEntityResolver (.getXMLReader parser) resolver)

  It doesn't work. Even if I add a ) in the end I get
  Exception in thread main java.lang.Exception: Too many arguments to
  def (test.clj:21)

  I tried then:

  (def parser (doto (.newSAXParser (SAXParserFactory/newInstance))
         (.setEntityResolver (.getXMLReader parser) resolver)))

 I think he meant this:
 (def parser (.newSAXParser (SAXParserFactory/newInstance)))
 (.setEntityResolver (.getXMLReader parser) resolver)

 --
 Michael Wood esiot...@gmail.com

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: dtd question

2010-08-01 Thread Randy Hudson
I think we're almost there, sorry for the various mistakes.

If you look in the source for clojure.xml, you can see that the
default startparse argument for xml/parse is

(defn startparse-sax [s ch]
  (.. SAXParserFactory (newInstance) (newSAXParser) (parse s ch)))

and we've only gotten as far as the newSAXParser part with the
definition of parser. So:

(defn startparse [s ch] (.parse parser s ch))
(defn parse-xml [source]  (xml/parse source startparse))

should finally do it.

I do apologize, I'd forgotten about the function wrapper part of this
machinery. I hope this has been helpful despite my mistakes.


On Aug 1, 2:50 pm, Manfred Lotz manfred.l...@arcor.de wrote:
 Hi Randy,

 On Sun, 1 Aug 2010 10:04:16 -0700 (PDT)

 Randy Hudson randy_hud...@mac.com wrote:
  Right you are Michael; sorry for the missing paren at the end of the
  def.

 Now compiling the code works:

 (def parser (.newSAXParser (SAXParserFactory/newInstance)))

 (.setEntityResolver (.getXMLReader parser) resolver)

 (defn parse-xml [source] (xml/parse source parser))

 however when trying to apply it by adding

 (parse-xml (java.io.File. test.xml))    

 it no longer compiles:
 Exception in thread main java.lang.ClassCastException:
 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl cannot be cast to
 clojure.lang.IFn (xmltest1.clj:0)

 --
 Thanks,
 Manfred

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: destructuring using :as in fn arg vector

2010-07-27 Thread Randy Hudson
The form you're looking for is (defn foo [  [a b :as c]] ...)


On Jul 27, 2:57 pm, Cameron cpuls...@gmail.com wrote:
 Hey all, just wondering if this is normal or not. There seems to be
 something weird going on with :as in a functions arg vector.

 This little example works as I'd expect...
 user= (defn foo [[a b :as c]] c)
 #'user/foo
 user= (foo [1 2])
 [1 2]

 But this one does not
 user= (defn foo [a b :as c] c)
 java.lang.Exception: Unsupported binding form: :as (NO_SOURCE_FILE:11)
 user=

 I would expect to call the second example like (foo 1 2) and have it
 return [1 2].

 So if this happens to be expected behavior, is there an idiomatic way
 to do destructure args but also refer to them all as one list?

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: java.lang.OutOfMemoryError

2010-07-26 Thread Randy Hudson
You can get a lazy sequence of all the lines in all the files by
something like:

(for [file out-files
  line (with-open [r (io/reader file)] (line-seq r))]
  line)

If StatusJSONImpl is on a separate line, you can throw in a :when
clause to filter them out:

(for [file out-files
  line (with-open [r (io/reader file)] (line-seq r))
  :when (not= line StatusJSONImpl)]
  line)

If it's a line prefix, you can remove it in the body:

(for [file out-files
  line (with-open [r (io/reader file)] (line-seq r))]
  (string/replace line StatusJSONImpl ))

This is all assuming io is an alias for clojure.java.io, string for
clojure.string, and that getting your files line by line is useful.



Re OutOfMemoryException: if all the allocated heap memory is really
not freeable, then there's nothing the JVM can do -- it's being asked
to allocate memory for a new object, and there's none available.

On Jul 26, 9:53 am, atucker agjf.tuc...@googlemail.com wrote:
 Hi all!  I have been trying to use Clojure on a student project, but
 it's becoming a bit of a nightmare.  I wonder whether anyone can
 help?  I'm not studying computer science, and I really need to be
 getting on with the work I'm actually supposed to be doing :)

 I am trying to work from a lot of Twitter statuses that I saved to
 text file.  (Unfortunately I failed to escape quotes and such, so the
 JSON is not valid.  Anyone know a good way of coping with that?)

 Here is my function:

 (defn json-seq []
   (apply concat
          (map #(do (print f) (str/split (slurp %) #\nStatusJSONImpl))
               out-files)))

 Now there are forty files and five thousand statuses per file, which
 sounds like a lot, and I don't suppose I can hope to hold them all in
 memory at the same time.  But I had thought that my function might
 produce a lazy sequence that would be more manageable.  However I
 typically get:

 twitter.core (nth (json-seq dir-name) 5)
 {createdAt=Fri  etc.   GOOD

 twitter.core (nth (json-seq dir-name) 5000)
 
 Java heap space
   [Thrown class java.lang.OutOfMemoryError]   BAD

 And at this point my REPL is done for.  Any further instruction will
 result in another OutOfMemoryError.  (Surely that has to be a bug just
 there?  Has the garbage collector just given up?)

 Anyway I am thinking that the sequence is not behaving as lazily as I
 need it to.  It's not reading one file at a time, and it's not reading
 thirty-two as I might expect from chunks, but something in the
 middle.  I did try the dechunkifying code from page 339 of Joy of
 Clojure, but that doesn't compile at all :(

 I do seem to keep running into memory problems with Clojure.  I have
 2GB RAM and am using Snow Leopard, Aquamacs 2.0, Clojure 1.2.0 beta1
 and Leiningen 1.2.0.

 Cheers
 Alistair

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Efficiency of reduce function for lists.

2010-07-25 Thread Randy Hudson
This is a wholly appropriate use of reduce; it's the obvious function
to use when you want to accumulate some calculation over a sequence.


As you say, you can just produce a function that acts on the result,
something like

(defn fstep [c] (if (= c \) pop #(conj % c))

However, the obvious way of accumulating the application of these
functions is ... reduce:

(reduce #(%2 %1) [] (map fstep input-chars))


You can gain some efficiency by using transient operations:

(defn tstep [v c] (if (= c \) (pop! v) (conj! v c)))   ;cf. step

(defn run [cs] (persistent! (reduce tstep (transient []) cs))  ; cf.
run-program

On my machine this reduced the runtime of your 6e6 test about 20%

On Jul 24, 6:16 pm, samnardoni samnard...@googlemail.com wrote:
 I have a simple string (or list of characters to be precise) in a form
 of: 123456789.

 I want to parse this string and end up with: 123569.

 The  is essentially the same as a backspace.

 I managed to implement this fairly simply using the reduce function -
 source:http://gist.github.com/489019.

 Although it can be implemented easily using the reduce function, I was
 concerned with the performance (especially with large inputs). As the
 reduce function invokes the provided function with the previous
 result, this list that is getting built is being passed around a huge
 amount.

 I'm not too sure as to what will be going on under the hood in this
 sample. Whether the previous result of the function application is
 really being passed around or not clear to me.

 For the program, I know that when processing a character, I do not
 need the previous result. All I need is the current character, and I
 can return a function that acts on the result. I'm not sure if this is
 simple to implement in a functional way.

 So, I have 2 questions:

 1) Is this a correct use of the reduce function? (I know there is a
 clue in the word reduce, but it's also called inject and else in
 other languages.)

 2) Is there a more efficient way of solving this?

 I appreciate any replies (for such a trivial topic). Answers to this
 will hopefully enlighten me to using functional languages more
 effectively, or possibly to a more suitable high-order function.

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Remove-first function

2010-07-24 Thread Randy Hudson
Here's my take:

(defn remove-first [x coll]
  (let [[pre post] (split-with #(not= x %) coll)]
(concat (pre (rest post

On Jul 24, 11:41 am, nickikt nick...@gmail.com wrote:
 Hallo all,

 I'm working trough Essentials of Programming Languages. I'm trying to
 right a function like this one:

 (defn scheme-remove-first [syb lst]
   (if (empty? lst)
     '()
     (if (= (first lst) syb)
       (rest lst)
       (cons (first lst) (scheme-remove-first syb (rest lst))

 in a idiomatic clojure way (this is just a scheme to clojure 1:1
 version). I don't like that this function produces stack overflows.

 I tried some stuff but I it (almost) semantically correct working but
 I didn't like my code. Can anyone come up with a good version?

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: gobble up a collection 2 at a time

2010-07-22 Thread Randy Hudson
(partition 2 coll) will give you the sequence two at a time.
To map your function, you'd do (map #(apply myfcn %) (partition 2 '(1
2 3 4 5 6 7 8)))

On Jul 21, 10:20 pm, Glen Rubin rubing...@gmail.com wrote:
 Hi!  I want to process a collection 2 elements at a time using map.

 My function accepts 2 parameters (a,b) and returns a result (c):

 (myfcn [a b])

  = c

 so I want to iterate myfcn over a collection and create a new sequence

 for example let's say myfcn sums a and b, then i would like to do
 something like this:

 (map myfcn '(1 2 3 4 5 6 7 8)

 = 3 7 11 15

 accept i get the error that myfcn is being passed the wrong number of
 arguments, since map is passing them in 1 at a time.  How do I get map
 to pass in 2 at a time?

 thx!

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: randomizing a vector

2010-07-21 Thread Randy Hudson
Clojure 1.2 has a shuffle function. If you're using 1.1, you can just
cop the 1.2 implementation.

On Jul 21, 1:18 pm, Ryan Waters ryan.or...@gmail.com wrote:
 http://gist.github.com/484747

 - - -

 My sad little program has a number of issues and I would welcome
 suggestions on any aspect of it.  I come from an imperative
 programming background and clojure is my first experience with a
 functional or lisp language.

 I'd like to take a list of things (really, a vector) and randomly add
 items of that list to another list.  I chose to work with vectors
 because clojure is efficient at adding things their ends and because I
 can address their consistent ordering with an index.

 Issues:

 1) Idiomatic: please point out anything that looks generally awkward
 or otherwise less than ideal for clojure (and suggest an alternative)
 : )  For example, in my loop I rebind symbols to themselves and have
 received mixed advice on IRC as to whether it's appropriate to do
 that.

 2) Transients: For speed and because I don't care about the
 intermediate values of the vectors, I'd like to use them.  I was able
 to easily work with the transient vector 'random-ips' but receive an
 error when trying to wrap the vector 'ordered-ips' in a transient:
 Exception in thread main java.lang.ClassCastException:
 clojure.lang.PersistentVector$TransientVector cannot be cast to
 clojure.lang.IPersistentVector (gen_ips.clj:36)

 3) Overall speed: it's abysmal but I don't blame Clojure.  It's either
 because I'm Doing It Wrong or what I'm doing is simply expensive in a
 big O notation sort of way.  I'm trying to randomly order 1.1 million
 strings.

 4) Clojure side-gripe: I wish it were easier to mix clojure's
 different 'types': vectors, lazy sequences, etc.  It's probably an
 ignorance thing on my part but, for what I know right now, I find
 using different macros with all the different return types
 problematic.

 - - -

 Thanks in advance to addressing one or more of these issues!

 - Ryan

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en