Re: Clojure Books

2011-07-19 Thread CuppoJava
Let Over Lambda is more a collection of advanced and narrow tricks that a experienced Lisper would find interesting (and maybe useful). It assumes you know the good practices already, and then proceeds to break them for awe and effect. I would not suggest it to a newcomer. -Patrick On Jul 19, 9:

Re: No any? function

2011-06-14 Thread CuppoJava
There is one use of any? over some which hasn't been mentioned: checking whether a list contains a nil. ie. (when (any? nil? xs) (do stuff)) vs. (when (some nil? xs) (do stuff)) -Patrick On Jun 14, 9:00 pm, Ken Wesson wrote: > On Tue, Jun 14, 2011 at 12:29 PM, Ambrose Bonnaire-Sergeant > > w

Re: Clojures macro system is essentially hygienic -- In the good sense.

2011-04-12 Thread CuppoJava
Paul Graham's "On Lisp" has a nice little section on anaphoric macros. It has a few nice tricks, but generally the Clojure style tends to avoid them if possible. ie. using if-let instead of an anaphoric-if macro. Also, I think the book Rob was referring to is called "Let Over Lambda" by Hoyte. As

Re: Why I'm getting an empty result?

2011-03-27 Thread CuppoJava
What exactly does the line (= (obj obj-locs) loc) do? What is an "obj" exactly? From your code it seems that an obj is going to be 'bottle or 'bucket. I'm not sure what happens if you treat a symbol as a function. -Patrick On Mar 27, 10:02 pm, HB wrote: > Hi, > Would you please have a look at

Re: Software Engineering Practices for Marking Algorithms?

2011-03-16 Thread CuppoJava
Thank you Mark and Ken. Your suggestions have been very helpful. There are certainly many options for me to pursue now. I will do some careful profiling and see which approach is most suitable. -Patrick On Mar 16, 8:14 pm, Mark Engelberg wrote: > On Wed, Mar 16, 2011 at 4:35 PM, CuppoJ

Re: Software Engineering Practices for Marking Algorithms?

2011-03-16 Thread CuppoJava
Thank you for the reply again Mark. Actually, now that I've had some time to think about your solution, I think it, is in fact, suitable for myself after all. There's just some trickiness involving handing out the numeric ids that I need to figure out. eg. Nodes are automatically assigned a unique

Re: Software Engineering Practices for Marking Algorithms?

2011-03-16 Thread CuppoJava
ng two data objects, two pointers, a pointer to Node[], and a > length property. Throw away that extra crap and you have more than > enough room for a temporary hashtable. > > On Mar 16, 11:17 am, CuppoJava wrote: > > > > > It sounds like hashing is the only solution that

Re: Software Engineering Practices for Marking Algorithms?

2011-03-16 Thread CuppoJava
It sounds like hashing is the only solution that can really compete with these markers. My particular problem cannot use hashing because the space waste and extra compute time is unacceptable. I'll just have to be particularly careful for multithreading my app. Thanks for the replies -Patrick O

Software Engineering Practices for Marking Algorithms?

2011-03-15 Thread CuppoJava
Hello everyone, This has been a long-time software engineering issue that I've never solved happily. It concerns implementing marking algorithms without making a kludge of your software structure. eg. Say I have a binary graph: Where each node in the graph is like this: class Node{ Node[] child

Re: Tricky Macro to write.

2011-02-11 Thread CuppoJava
n Thu, Feb 10, 2011 at 11:10 PM, CuppoJava > wrote: > > Your solution with map-ps is quite elegant. > > Thanks. My implementation of macrolet also uses it. In fact, I wrote > my macroexpand-all as a tool to aid in developing that. It was useful > both for debugging macrolet its

Re: Tricky Macro to write.

2011-02-10 Thread CuppoJava
environment (ie. they're not side-effect free). So I had to ensure that macroexpand-all actually *does* run all the macros appropriately. -Patrick On Feb 10, 6:29 pm, Ken Wesson wrote: > On Thu, Feb 10, 2011 at 11:01 AM, CuppoJava > wrote: > > Thanks for all your help everyone! > &

Re: Tricky Macro to write.

2011-02-10 Thread CuppoJava
r wrote: > On Wed, 9 Feb 2011 20:34:56 -0800 (PST) > > > > > > CuppoJava wrote: > > Description: (bind-later bindings & body)  and (do-binding & body) > > (bind-later) is used like a let-form, except that it doesn't > > *immediately* make the

Re: Tricky Macro to write.

2011-02-10 Thread CuppoJava
Brandmeyer wrote: > Hi, > > On 10 Feb., 14:58, CuppoJava wrote: > > > That's an awesome solution Meikel! > > You are welcome. :) > > > I forgot to specify that I want the bindings to have lexical scope > > only. But I think I can get that to work eas

Re: Tricky Macro to write.

2011-02-10 Thread CuppoJava
That's an awesome solution Meikel! I forgot to specify that I want the bindings to have lexical scope only. But I think I can get that to work easily by modifying your solution. Thanks! -Patrick On Feb 10, 2:09 am, Meikel Brandmeyer wrote: > Whoops. Misclick. Sorry > > Here again: > > (def *d

Tricky Macro to write.

2011-02-09 Thread CuppoJava
Hello everyone, I'm having trouble writing the following tricky macro. I think I might need some feature that Clojure doesn't have, but I'm not sure. Description: (bind-later bindings & body) and (do-binding & body) (bind-later) is used like a let-form, except that it doesn't *immediately* make

Re: Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
lementing let. Thanks for everyone's contribution -Patrick On Feb 7, 11:45 pm, Ken Wesson wrote: > On Mon, Feb 7, 2011 at 10:06 PM, CuppoJava wrote: > > I've thought about that actually. And it wouldn't work. > > > So (defn destructure [form value] > >    

Re: Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
ach won't work because "body" is only a symbol within the macro. We don't know it's value until runtime. -Patrick On Feb 7, 7:01 pm, Alan wrote: > (defn destructure [binding-form] >   ...magic...) > > (defmacro let [forms body] >   `(let* ~(vec (destruc

Re: Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
atrick On Feb 7, 3:32 pm, Ken Wesson wrote: > On Mon, Feb 7, 2011 at 3:01 PM, Meikel Brandmeyer wrote: > > Hi, > > > Am 07.02.2011 um 20:51 schrieb CuppoJava: > > >> Thanks for your answer Meikel. > > >> Your answer isn't that ugly. It's very simil

Re: Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
Meikel Brandmeyer wrote: > Hi, > > Am 07.02.2011 um 20:26 schrieb CuppoJava: > > > I was wondering whether the "destructure" function can be written > > using the existing "let" form. Thanks for your help. > > Ah ok. Nevermind. > > Sincerely &

Re: Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
Sorry, I wasn't being very clear about my needs. I need this function to run at *run-time*. So the following: (def values [1 2 [3 4 5 6 7 8]]) (def form '(a b (c d & e))) (destructure form values) Should return: {:a 1 :b 2 :c 3 :d 4 :e [5 6 7 8]} I was wondering whether the "destructure" functi

Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
Hello everyone, I am trying to write the following function: --- Suppose form = [1 2 [3 4 5 6 7 8]] (destructure '(a b (c d & e)) form) should return: {:a 1 :b 2 :c 3 :d 4 :e [5 6 7 8]} -

Re: discussing Clojure with non-CS types

2010-11-24 Thread CuppoJava
I must admit that even though I love Clojure and use it daily for many things, I don't like using it very much for my research (machine learning) which involves a lot of number crunching. The main reasons being: Numerical software involves a lot of array indexing, and loops, and not much else. Cl

Re: Java gotchas now clojure gotchas

2010-11-02 Thread CuppoJava
Personally, I find the added time and complexity required to be careful about such problems (ie. numerical overflow) is easier to deal with than later having to optimize subtle performance problems that arise from these automatic boxing / upcasting solutions. From the frequency of performance-relat

Re: An Emacs command to close the various balanced expressions in Clojure

2010-09-26 Thread CuppoJava
I'm curious what you don't like about the automatic insertion scheme that you talked about. I'm using Parenedit with emacs and I'm quite happy with it. I think the scheme is quite simple... whenever you type '(', it inserts ')'. Similarly with '[' and '{'. -Patrick On Sep 26, 7:51 pm, blais wro

Re: var args

2010-09-14 Thread CuppoJava
Hi mike, Your problem is about to calling a function with a list of arguments, which is independent of varargs. Take a look at the "apply" function. It does what you're looking for. Cheers -Patrick On Sep 14, 2:47 am, Michael Ossareh wrote: > Hi, > > I don't fully understand how to make real use

Re: A difficult Metaphor for Macros (especially for Java people)

2010-09-08 Thread CuppoJava
Patrick, > > yes, I think thats the right way to teach this stuff. My problem > arises earlier - I still have to motivate my collegues, to get them > interested, and, maybe, teach them later ;-) > > Regards, alux > > On 8 Sep., 16:28, CuppoJava wrote: > > > > >

Re: A difficult Metaphor for Macros (especially for Java people)

2010-09-08 Thread CuppoJava
I found the easiest way to introduce macros is just to introduce them as small syntactic sugaring. For example, getting rid of the explicit (fn [] ...) for macros like (with-open file ...). Once people get accustomed to this, they naturally extend it to more and more complicated usages. -Patrick

Re: Can Clojure compile a source-file? How does it do it?

2010-09-05 Thread CuppoJava
Ah that makes sense! Thanks Michal! I have looked through Lisp in Small Pieces, and didn't find it very well written. I think a lot was lost through the translation. Besides SICP, the other great lisp book I read was actually "The Scheme Programming Language". The chapter on continuations is mind-b

Re: Can Clojure compile a source-file? How does it do it?

2010-09-05 Thread CuppoJava
Sep 5, 6:48 pm, Michał Marczyk wrote: > On 5 September 2010 18:46, CuppoJava wrote: > > > I'm writing a simple lisp for educational purposes, and I can't figure > > out how to do compilation. > > The final chapter of SICP [1] deals with compilation of Scheme

Re: Clojure macros

2010-09-05 Thread CuppoJava
I'm not sure if this is intended behavior or not, since unquote- splicing was originally meant for splicing into lists. But for now anyway, you can use this as a workaround? (defmacro tm [& args] `(hash-map ~@(mapcat (fn [x] (list (keyword x) x)) args))) Hope that helps -Patrick On Sep 5, 3:

Can Clojure compile a source-file? How does it do it?

2010-09-05 Thread CuppoJava
Hi everyone, I'm writing a simple lisp for educational purposes, and I can't figure out how to do compilation. In particular, I can't figure out how I can get a compiled file to run in the same way as if it were loaded. I read on the webpage that Clojure can do this. Does anyone know how Clojure do

Re: Question about `binding'

2010-09-04 Thread CuppoJava
Your original understanding is correct. Your first example is not working the way you expect it because Clojure is inlining "inc" for speed purposes. Hope that helps -Patrick On Sep 3, 11:21 pm, Yang Dong wrote: > (binding [inc dec] >   (println (inc 1))) > > ;=> 2 > > If I put a declare on top

Re: Thinking in Clojure

2010-09-03 Thread CuppoJava
I had the exact same problem transitioning from OOP to Lisp, and I can only offer my own experiences. I finally "understood" lisp, by programming a new pet project FROM SCRATCH, in the most STRAIGHTFORWARD way possible. I originally started by porting over a program I had written in Java, and found

Re: Simple Regex Question

2010-08-22 Thread CuppoJava
Haha. No I'm not trying to solve the correspondence problem. I'm writing a simple parser for a toy language that I'm working on. Thanks for everyone's help! -Patrick On Aug 22, 4:34 am, Luka Stojanovic wrote: > On Sunday 22 August 2010 01:11:38 CuppoJava wrote: &g

Re: Simple Regex Question

2010-08-21 Thread CuppoJava
Wow that's so short! Thanks Chouser! I will abstain from showing the awful hack that I've been working with currently. -Patrick On Aug 21, 8:45 pm, Chouser wrote: > On Sat, Aug 21, 2010 at 7:11 PM, CuppoJava wrote: > > Hi Everyone, > > > I'm extremely st

Simple Regex Question

2010-08-21 Thread CuppoJava
Hi Everyone, I'm extremely stuck on this simple regex question, which I'm sure someone with a little more experience will be able to write in a second. I would really appreciate the help. Given a string consisting of a's, b's, and spaces: "aaa bbb abb ab bb" I want to tokenize this into string'

Re: Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread CuppoJava
Thanks for the reply Jarkko. That helps quite a lot. I have some hacks in place that works most of the time, but was stuck trying to figure out a general solution. Knowing that there isn't one puts my mind at ease. -Patrick On Aug 9, 1:56 pm, Jarkko Oranen wrote: > On Aug 9, 7:54 pm, C

Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread CuppoJava
Hello everyone, Just for educational purposes, I'm writing a simple lisp compiler and am stuck on a small problem. I'm trying to write a function called (compile-function), which will take a function as input and compile it. If that function calls other functions, I would like (compile- function)

Re: Elegant way of expressing this in Clojure?

2010-05-28 Thread CuppoJava
Thanks Christophe. That looks relatively clean as well. (As clean as the Java version anyway). And it's the fastest version shown so far. -Patrick On May 28, 9:57 am, Christophe Grand wrote: > On Fri, May 28, 2010 at 3:09 PM, CuppoJava wrote: > > > d,w are arrays that are

Re: Elegant way of expressing this in Clojure?

2010-05-28 Thread CuppoJava
ing that's explicitly avoided because it distracts from the FP paradigm. The lack of them is making this code somewhat awkward to write. -Patrick On May 28, 4:44 am, Christophe Grand wrote: > On Thu, May 27, 2010 at 9:07 PM, CuppoJava wrote: > > > The purpose is quite straightforwa

Re: Elegant way of expressing this in Clojure?

2010-05-27 Thread CuppoJava
Thanks Laurent! I'll stick to that for now then. On May 27, 3:56 pm, Laurent PETIT wrote: > 2010/5/27 CuppoJava > > > Laurent's solution will be suitable for my purposes. I really do need > > to stay in the mutable world for this application. The Java code is >

Re: Elegant way of expressing this in Clojure?

2010-05-27 Thread CuppoJava
itive integer? Laurent uses a local-var. There's also atoms, refs, arrays ...? -Patrick On May 27, 3:41 pm, Meikel Brandmeyer wrote: > Hi, > > On Thu, May 27, 2010 at 12:33:20PM -0700, CuppoJava wrote: > > Your solution is very clear Meikel. I don't have a benchmark.

Re: Elegant way of expressing this in Clojure?

2010-05-27 Thread CuppoJava
t documents can only be loaded in one at a time. Loading a new document releases the currently loaded document. So memoize won't quite work. But I can figure out the details myself. Thanks for the help -Patrick On May 27, 3:24 pm, Meikel Brandmeyer wrote: > Hi, > > On Thu, May 27, 2

Re: Elegant way of expressing this in Clojure?

2010-05-27 Thread CuppoJava
The purpose is quite straightforward. I just have to call process() on every word in the w and d array. But I don't want to load docs if they have already been loaded. And I want to stop when it hits the first malformed document. Thanks for the help. Is there a nice efficient way of doing it with

Elegant way of expressing this in Clojure?

2010-05-27 Thread CuppoJava
Hi, I have a little snippet of Java code that I want to express in Clojure. But all my attempts thus far have been much more unreadable than the equivalent Java. Some help would be greatly appreciated. d and w are arrays of integers, d: [0 0 0 0 0 1 1 1 1 2 2 3 3 3 3 3 4 4 ... ] w: [1

Re: finding sequential items from a sequence

2010-04-27 Thread CuppoJava
Here's an attempt, but it's not my best work. =) (def temp [2 3 4 6 8 1]) (let [l (filter identity (for [[a b c] (map vector temp (rest temp))] (if (= (- b a) 1) a nil)))] (concat l [(+ (last l) 1)])) -Patrick -- You received this message b

Re: Achieving high performance, mutable primitives?

2010-03-13 Thread CuppoJava
I see, so that's what I was missing. Thanks for your help! -Patrick -- 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

Achieving high performance, mutable primitives?

2010-03-13 Thread CuppoJava
Hi, I just ran these two microbenchmarks, where I attempted to measure the overhead in Clojure's loop-recur form as compared to just mutating an array. ;;loop-recur (5300 msecs) (time (dotimes [n 5000] (loop [accum (int 0) i (int 0)] (if (< i 5) (recur (+ accum i) (inc i))

Re: filter sequence until false result

2010-03-13 Thread CuppoJava
You can use either take-while or for to do what you want. (take-while #(< % 20) primes) (for [p primes :while (< p 20)] p) Hope that helps -Patrick -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@google

Re: I confused myself. How can I solve this simple problem?

2010-03-08 Thread CuppoJava
Thanks for the responses. The let form is suitable enough as a workaround. The thing that really bothered me about this is because separation of responsibilities breaks down somewhat. Imagine I create a library of different println's for use in different circumstances. (defn fancy-println [] ) (

I confused myself. How can I solve this simple problem?

2010-03-07 Thread CuppoJava
So I just stumbled across this bug in my code, and it arose very innocently so I wonder if anyone has an elegant solution to this problem. There is already a function called (println). Now I would like to write another version of it, which just tacks some stuff at the end of what it normally does

Re: Rebinding vars at compile time

2010-03-07 Thread CuppoJava
I agree that the issue with not being to change the root value of *assert* seems odd. But I actually like the macroexpand-all solution. It's done at compile- time, so performance is not a big problem, and clojure's macroexpand resolves everything to the proper namespace anyway. -Patrick -- Yo

Re: newbie question: Please help me stop creating constructors

2010-02-17 Thread CuppoJava
I think it will help you get used to Clojure by spending some time to "program in the most straight-forward way possible". Sometimes it's really helpful to just learn from a blank-slate instead of trying to find analogies to Java. -Patrick -- You received this message because you are subscri

Re: newbie question: Please help me stop creating constructors

2010-02-17 Thread CuppoJava
Hi Yaron, You've slightly misunderstood my suggestion. I hope this will shed some reasoning on it: In OO, what you are effectively doing is this: The Object represents the "environment" under which you do your calculations. The "environment" object is created by your constructor. Once this "envi

Re: newbie question: Please help me stop creating constructors

2010-02-17 Thread CuppoJava
Hi Yaron, Have you considered my example yet? It seems to fulfill your requirements. One of the primary use-cases of (binding) is to avoid bloating the parameter list of a group of functions. If my example does not satisfy your needs, then I think we may have all misunderstood what it is you're lo

Re: newbie question: Please help me stop creating constructors

2010-02-16 Thread CuppoJava
What do you think of the following style? (defmacro in-environment [env & body] `(binding [*months-to-find-tenant* (:months-to-find-tenant env) *months-in-lease* (:months-in-lease env) *lease-cycles* (:lease-cycles env) etc...] ~...@body)) So "env" is

Destructuring in clojure/binding

2010-02-16 Thread CuppoJava
Hi, I found this old post: http://groups.google.com/group/clojure/browse_thread/thread/45e118a638a5af8e/02eab5ae0d9023ff?lnk=gst&q=binding+destructuring#02eab5ae0d9023ff And was wondering what is the status of Stephen's patch? Is there a reason why clojure/binding does not support destructuring

Re: When to use loop recur / seq functions?

2010-02-15 Thread CuppoJava
Here's your second implementation cleaned up a little: (defn perimeter [& pn] (apply + (map euclidean-distance pn (rest pn My own personal opinion is: The second approach is (1) faster to write (2) easier to understand (3) less error-prone So that's the one that I prefer. IF the first

Re: Help me make this more idiomatic clojure

2010-02-12 Thread CuppoJava
Yup, literal syntax for vectors are very convenient and heavily used in Clojure code. And (let) bindings are evaluated left to right. It's analogous to Scheme's let* i think? Only thing to watch out for is that (binding) bindings are not evaluated left to right. It's for performance reasons I thi

Re: Help me make this more idiomatic clojure

2010-02-11 Thread CuppoJava
Most of that java code is just pasting together library function calls. I'm not sure if there's any more elegant ways of doing that. Your clojure code looks fine for the most part I think. It's mostly just a question of style. The only thing that sticks out is the call to (list). That's generally n

Re: How would I write an emitter/collector?

2010-02-10 Thread CuppoJava
It sounds like Clojure might be a good fit for you then. I personally came to Clojure after getting fed up with Java, and experimenting with Ruby, so I can understand your predicament. The most dangerous thing to watch out for, and this really can't be stressed enough, is that learning Clojure is

Re: How would I write an emitter/collector?

2010-02-10 Thread CuppoJava
There are some bugs with my previous post. Here's a revised version. ;;--USING LIST COMPREHENSIONS--- (for [n (range 10) :when (even? n)] n) (apply concat (for [n (range 10) :when (even? n)] [n (* 2 n)])) ;;EMIT/COLLECT IMPLEMENTATION-- (def -collector) (defn em

Re: How would I write an emitter/collector?

2010-02-10 Thread CuppoJava
It looks like you want to implement something akin to what other languages call "generators". In Clojure, we generally use list comprehensions to get (almost) the same effect, but it's a little cleaner in my opinion. eg. in your first two examples (collect (doseq [ n (range 10)] (when (even?

Re: Parens again

2010-02-03 Thread CuppoJava
As trivial as it seems, proper indentation was also my most significant hurdle when learning Clojure. I finally was only able to "get" s-exps after realizing: 1. That indentation is *extremely* important. 2. That it's not straightforward ( relative to C-languages ). 3. You're not expected to

Re: Lazy (apply concat ...) ?

2010-02-01 Thread CuppoJava
Thanks for helping me through this Richard. I think I got the gist of the argument now from the blog post you linked to. Now that I think about it, *most* code doesn't break with chunked sequences, so that seems to be alright. Though generally I prefer following the principle of least-surprise...

Re: Lazy (apply concat ...) ?

2010-02-01 Thread CuppoJava
Thanks for the help Richard. After playing around with 1.1.0 some more (I just upgraded). I'm finding that the chunked sequences is destroying all my code that relied on lazy sequences. Isn't the following a pretty standard thing to do? (for [i (range 20)] (do (println i)

Re: Lazy (apply concat ...) ?

2010-02-01 Thread CuppoJava
Oh I see. Thanks for the explanation. I always assumed that chunked sequences can be viewed as purely an optimization and transparent from the user. Is there a way (short of writing a lazy version of apply concat) that I can achieve my desired result? -Patrick -- You received this message becau

Lazy (apply concat ...) ?

2010-02-01 Thread CuppoJava
Hi, I'm wondering whether (apply concat ...) can be re-written to be lazy. ---Expected behavior--- (def temp (for [i (range 20)] (do (println i) [i i i]))) (def temp2 (apply concat temp)) Should print nothing. -Behavior in 1.1.0-RC- Under Clojure-1.1

Re: Newbie question - Functional programming & special cases

2010-02-01 Thread CuppoJava
Hi ka, You're right. Eliminating special cases is more a factor of the design of the API than of the programming language. Nevertheless, a well- designed API (that has eliminating special cases in mind) in combination with a functional programming language makes your code extremely elegant. Thus ma

Re: Clojure Kata

2010-01-24 Thread CuppoJava
That's very thoughtful Travis. I was also considering generalizing regular expressions to apply to arbitrary ordered collections for this question. That is the most elegant abstraction for this problem. I suppose there just isn't enough real-world use for a regex on collections to justify the effor

Re: Clojure Kata

2010-01-24 Thread CuppoJava
It's an elegant puzzle. Thanks Sean! Here's my take: (defn sift [pred? s] (lazy-seq (if (seq s) (let [key (first s) [vals remaining] (split-with #(not (pred? %)) (rest s))] (cons [key vals] (sift pred? remaining)) Running: (sift string? ["a" 2 "b" 3 4 "c" "d" 4

Re: What are Vars supposed to be used for?

2010-01-24 Thread CuppoJava
That makes sense Jarkko, thanks for the explanation. So then, for my example, using a binding and set! would be the proper way of going about it right? Because I don't intend for multiple threads to access the job queue. And is there a way to change the bound value for another thread? The reason

Re: What are Vars supposed to be used for?

2010-01-23 Thread CuppoJava
Thanks for the reply. That seems to match well with how I thought they were supposed to work. I'm just a little confused by the set!, with-local-vars, functions. What are they supposed to be used for? -Patrick -- You received this message because you are subscribed to the Google Groups "Cloju

Replacing " with \" in a string.

2010-01-21 Thread CuppoJava
Hi, I'm trying to write a simple function to replace every " inside the string with \", but am having an extremely difficult time. Can someone enlighten me as to why the following is returning true? (= (.replaceAll "\"" "\\\"" "a") (.replaceAll "\"" "\\\"" "\\a")) Thanks a lot -Patrick --

Re: Question about Responsiveness of Garbage Collection

2010-01-21 Thread CuppoJava
Thanks for the responses. It seems the consensus is that the slow responsiveness of Java apps is mostly due to an issue with Swing and how it is used rather than with garbage collection. That sounds very encouraging. The last point that interested me was: I heard someone mention that applications

Question about Responsiveness of Garbage Collection

2010-01-20 Thread CuppoJava
Hi, Java was my first language, and my favorite platform to work in, but I do notice (especially after buying a mac and experiencing Mac OS X) that gui programs written on the JVM are noticeably less responsive than their native counterparts. Some articles I read point to Java's use of garbage col

Re: Using Runtime.exec to copy a file to a secure server.

2010-01-19 Thread CuppoJava
Thanks for your replies. I'll checkout shell-out to see what it's doing differently than what I'm doing. That will help me figure out what I'm missing. -Patrick -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to cloj

Using Runtime.exec to copy a file to a secure server.

2010-01-19 Thread CuppoJava
I've run into the need to copy the same file to 500 different nodes on a computing cluster, so I thought I'd save myself some time by writing a loop in Clojure to do that. But the server requires a password to be entered, and I'm not sure how to automatically supply that password. Here's the manu

Re: Parenthesis Inference

2009-12-18 Thread CuppoJava
In my personal experience, the fastest way to get accustomed to the parenthesis is to learn how to read the indentation. That was the biggest hurdle for me coming from reading C/Java code. Lisp indentation is quite expressive and a little more subtle (unlike the indent-two-spaces-for-a-loop scheme

Re: How to modify the last few elements of a vector

2009-12-16 Thread CuppoJava
Never mind, I realized that my solution doesn't quite answer your question. Here's another attempt. --Convenience Functions-- (defn indexed [coll] (map vector coll (iterate inc 0))) (defn between [n min max] (and (< n max) (>= n min))) --Your Specific Case-- (for [[e i] (indexed v)] (if (be

Re: How to modify the last few elements of a vector

2009-12-16 Thread CuppoJava
The basic abstraction that I see, is that you need a function that will replace a range within a collection with another collection. Here's a quick and dirty way of doing that: (defn assoc-range [v min max v2] (vec (concat (take min v) v2 (nthnext v (dec max) So

Re: Try/Catch & Recur

2009-12-15 Thread CuppoJava
That's very interesting. I haven't run into this issue before. One cleanish way to side-step it is to use (defn foo2 [] (try (println "body") (finally (doall (for [x (range 3)] (println x)) Which is perhaps a little cleaner in meaning to the original doseq than a reduce. -Patri

Re: Try/Catch & Recur

2009-12-14 Thread CuppoJava
I'm glad that everything works now Greg. Though I have to say that I'm a little suspicious of changing a "doseq" into a "for" to solve the problem. Off the top of my head, I can't think of any subtleties that can arise because of doseq and tail recursion. Is it possible to post a simplified versio

Re: Try/Catch & Recur

2009-12-14 Thread CuppoJava
I'm not quite sure about your specific case, but is it possible to just move the try-catch outside of the recursive function? Perhaps this is not possible for your specific case, but it seems like a clean way to handle it, so I would try and massage the problem into something that can be expressed

Re: How to internally refer to other keys in a hashmap?

2009-12-09 Thread CuppoJava
I've run into this problem before also actually. Basically from what I read, self-recursive data-structures are hard to do in an eager functional programming language. I think you have to resort to mutation to handle it nicely. But I would be very happy to be proven wrong. -Patrick -- You recei

Re: Is str supposed to be able to output lazy strings?

2009-12-06 Thread CuppoJava
This is expected behavior. eg. (str (map identity [1 2 3])) returns "clojure.lang.lazy...@7861" The way to think about it is, (str) asks for the string representation of an object. The string representation of a lazy sequence in this case is "clojure.lang.lazy...@7861". If you want the string re

Re: Remove Value From Vector at Given Index

2009-12-03 Thread CuppoJava
And here's yet another way: (for [[x b] (zip coll (cycle [true true false])) :when b] x) where zip is defined: (def zip (partial map vector)) -Patrick -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@go

Re: Creating a matrix mirrored around it's main diagonal

2009-12-03 Thread CuppoJava
Matrix arithmetic is one of those cases where I feel indexing is clearer than filter/map functions. However, if you're representing matrices as vectors as vectors, this will likely come with a little bit of extra overhead. That's not a problem usually because if you plan on doing any sort of heav

Re: Clojure as a first programming language?

2009-12-01 Thread CuppoJava
There are more qualified people than me on these boards, but I can offer my own personal experience, which is to say, as a first language I would still recommend going the C/Java/Basic/Assembly route first before going with a Lisp. Because simply, I couldn't appreciate functional programming until

Re: Iterative collections.

2009-11-09 Thread CuppoJava
That's also the idiom I use, which is why I have the following utility in my startup. (defn zip [& args] (apply map vector args)) -Patrick --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to t

Re: Is it possible to implement break or return in Lisp?

2009-11-02 Thread CuppoJava
Thanks Brian. For my own purposes, yes I have no need for a break or return statement. But I'm writing a DSL for others to use. People that don't have experience with functional programming, and for them it's easier to have a break/return. And for me, it's easier to implement break/return using

Re: Is it possible to implement break or return in Lisp?

2009-11-01 Thread CuppoJava
Thanks for the pointer! I haven't considered using Exceptions to influence the control-flow. This will work perfectly. -Patrick PS: I've always found it a little strange for exception-handling to be treated as a special case in language design. It seems like it ought able to be expressed in ter

Is it possible to implement break or return in Lisp?

2009-11-01 Thread CuppoJava
Hi, For the purposes of a DSL that I'm writing, it would be very convenient to have a break/return statement that early exits from a subroutine. Is it possible to implement this in Clojure? or any Lisp-like language? I've given it some thought and it seems it has to be a compiler level feature.

Re: How is Lisp compiled ahead of time?

2009-10-21 Thread CuppoJava
Of course! Thanks for that explanation Konrad Hinsen. I indeed was thinking about functions that return functions, and was attempting to reason about it with my C-compiler knowledge. It never occurred to me that closures are well defined statically. That's all that I needed to know. Thanks everyo

How is Lisp compiled ahead of time?

2009-10-21 Thread CuppoJava
Hi, Clojure started my interest in programming languages, and I'm wondering exactly how LISP-like languages get compiled ahead of time? A link to a tutorial would be much appreciated. The part that I'm having trouble understanding is the fact that functions can be defined at runtime. How do you c

Re: Linear Algebra Package

2009-10-06 Thread CuppoJava
Thanks for all the suggestions! I'm currently interested most in Parallel Colt as interfaced with Incanter, as it provides me a minimal barrier to entry to get some initial hacking done first. After that I might switch to Clojuratica when I need the additional functionality. Just a quick question

Re: Linear Algebra Package

2009-10-05 Thread CuppoJava
Thanks for the replies. Those are exactly what I need! -Patrick --~--~-~--~~~---~--~~ 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

Linear Algebra Package

2009-10-05 Thread CuppoJava
Hi, I need to do some high performance numerical data crunching and was wondering what libraries are popular. I have looked into Colt and JAMA, but neither have had much development recently (Colt hasn't had a release since 2004, and JAMA since 2005), and I'm not sure if they're still alive. Cloju

Re: Silly Convention Question

2009-09-18 Thread CuppoJava
John illustrates a common scenario in Clojure. Clojure's built-in functions are tersely and sensibly named. The problem is that there is indeed a finite number of terse and sensible names... which bites you when you need some of those names. Hence why in my code I have started to just capitalize v

Silly Convention Question

2009-09-18 Thread CuppoJava
Hi, After I shot myself in the foot again this morning by naming one of my variables "cond" and then wondering why Clojure was complaining about a simple cond form, I thought why don't we have capitalization conventions that differ between variables and functions? Everything in Clojure is lowerca

  1   2   3   4   >