Re: Newbie question

2016-09-05 Thread Andy Fingerhut
On Mon, Sep 5, 2016 at 9:25 AM, hiskennyness wrote: > > In other languages you might see: > > (defn himom [] ..) > (defn himom [x] ...) > (defn himom [x y z] ...) > > > Come to think of it, maybe Clojure does that, too, (nooby myself) but the > Clojure syntax for overloading I know puts each defi

Re: Newbie question

2016-09-05 Thread hiskennyness
On Sunday, September 4, 2016 at 4:58:34 PM UTC-4, Charlie wrote: > > I'm going through the Do Things: A Clojure Crash Course, and the following > example (in REPL) is presented: > > (defn recursive-printer > ([] > (recursive-printer 0)) > ([iteration] > (println iteration) > (

Re: Newbie question

2016-09-04 Thread Charlie
Thanx Colin & James - got it now - Charlie On Sunday, September 4, 2016 at 5:31:40 PM UTC-4, Colin Yates wrote: > > This form allows the fn to have multiple arities. So if I call > (recursive-printer) it will 'invoke' ([] (recursive-printer 0)). If I call > (recursive-printer 1) then it will 'in

Re: Newbie question

2016-09-04 Thread Colin Yates
This form allows the fn to have multiple arities. So if I call (recursive- printer) it will 'invoke' ([] (recursive-printer 0)). If I call (recursive- printer 1) then it will 'invoke' ([iteration] ...). HTH -- Colin Yates colin.ya...@gmail.com On Sun, 4 Sep 2016, at 09:54 PM, Charlie wrote

Re: Newbie question

2016-09-04 Thread James Reeves
Functions in Clojure can behave differently depending on the number of arguments they receive (their "arity"). A function can be written: (defn foo [x] (str "foo" x)) But you can also write: (defn foo ([] "empty foo") ([x] (str "foo" x)) This will do different things d

Newbie question

2016-09-04 Thread Charlie
I'm going through the Do Things: A Clojure Crash Course, and the following example (in REPL) is presented: (defn recursive-printer ([] (recursive-printer 0)) ([iteration] (println iteration) (if (> iteration 3) (println "Goodbye!") (recursive-printer (inc iteratio

Re: Newbie Question: Why is "reduced?" used in the reductions function?

2015-10-17 Thread Alex Eberts
Ah, that makes total sense. Thanks for the assistance! best, Alex On Saturday, October 17, 2015 at 7:35:00 AM UTC-4, Nicola Mometto wrote: > > > The `reduced?` check is there in case somebody returns a `reduced` as > acc value from the reducing function, as a way to terminate the > reduction ea

Re: Newbie Question: Why is "reduced?" used in the reductions function?

2015-10-17 Thread Nicola Mometto
The `reduced?` check is there in case somebody returns a `reduced` as acc value from the reducing function, as a way to terminate the reduction early: user=> (reductions (fn [_ x] (if (= 10 x) (reduced x) x)) (range)) (0 1 2 3 4 5 6 7 8 9 10) deref is the way to retrieve the value of a reduced o

Newbie Question: Why is "reduced?" used in the reductions function?

2015-10-17 Thread Alex Eberts
Hi All, Could someone please explain why reduced? is being used in the reductions function (below)? From what I understand reduced? checks if there has been a call to reduced and I don't see where that might be happening. Also, why is the deref macro being used with init? thanks, Alex (defn

Re: newbie question: how to selectively iterate through a tree of directories ?

2015-10-03 Thread Gary Verhaegen
I'm on Windows at the moment, so I can't test, but I think you can filter on isFile: (for [file (file-seq dir) :where (.isFile file)] (.getName file)) should work, I think. On 3 October 2015 at 07:36, wrote: > Under linux, I have a tree of directories like this: > > /path/top > > /path

newbie question: how to selectively iterate through a tree of directories ?

2015-10-03 Thread hpwei01
Under linux, I have a tree of directories like this: /path/top /path/top/dir1 (in here there are two files f1, f2) /path/top/dir2 -> /another-path/dir2 (a symbolic link) and under /another-path/dir2 there are two files g1, g2 If I use below code, I would get a list of file

Re: newbie question on agent/transaction

2015-07-15 Thread William la Forge
Or perhaps find a way to extend agents. hm? On Wednesday, July 15, 2015 at 9:45:29 AM UTC-4, William la Forge wrote: > > Thanks, Ragnar. > > My reason for asking is that I've implemented a robust form of actor in > Java https://github.com/laforge49/JActor2 and want to play with a > simplified ve

Re: newbie question on agent/transaction

2015-07-15 Thread William la Forge
Thanks, Ragnar. My reason for asking is that I've implemented a robust form of actor in Java https://github.com/laforge49/JActor2 and want to play with a simplified version in Clojure as a first project in the language. But I'm just hardly getting started. I've only been looking at Clojure for

Re: newbie question on agent/transaction

2015-07-15 Thread Ragnar Dahlén
You can check with `(clojure.lang.LockingTransaction/isRunning)` (the io! macro does this) but I'm not sure if it's considered a public API. https://github.com/clojure/clojure/blob/f6a90ff2931cec35cca0ca7cf7afe90ab99e3161/src/clj/clojure/core.clj#L2390 On Wednesday, 15 July 2015 13:53:11 UTC+1,

Re: newbie question on agent/transaction

2015-07-15 Thread Ragnar Dahlén
Hi Bill, You are correct in that this involves close integration with the STM. The agent implementation is aware of transactions and if a transaction is running when dispatching an action, it will be enqneued in a special agent action queue that STM implementation respects. AFAIK there is no p

newbie question on agent/transaction

2015-07-15 Thread William la Forge
On this page http://clojure.org/agents I read the following: "Agents are integrated with the STM - any dispatches made in a transaction are held until it commits, and are discarded if it is retried or aborted." So there must be a way to tell if a dispatch is made from within a transaction.

Re: Newbie question about filtrering defrecord

2015-04-04 Thread Paul L. Snyder
On Sun, 05 Apr 2015, Michael Blume wrote: > your list doesn't contain the records, your list contains the symbols 'a1 > and 'a2. You can't make a list the way you're trying to. To be specific, you're quoting the list in your def, so the a1 and a2 symbols are not evaluated. user=> (defrecord A

Re: Newbie question about filtrering defrecord

2015-04-04 Thread Michael Blume
your list doesn't contain the records, your list contains the symbols 'a1 and 'a2. You can't make a list the way you're trying to. On Sat, Apr 4, 2015 at 5:14 PM Luc Préfontaine wrote: > You mean the a1 record no ? > > > > Hi! > > > > I'm new to clojure, and have problem understanding how to fil

Re: Newbie question about filtrering defrecord

2015-04-04 Thread Luc Préfontaine
You mean the a1 record no ? > Hi! > > I'm new to clojure, and have problem understanding how to filter a list of > defrecords. > I have tried different variations on the following: > > (defrecord Ape [fname lname]) > (def a1 (->Ape "test1" "test2")) > (def a2 (->Ape "test3" "test4")) > (def a

Newbie question about filtrering defrecord

2015-04-04 Thread Magnus Javerberg
Hi! I'm new to clojure, and have problem understanding how to filter a list of defrecords. I have tried different variations on the following: (defrecord Ape [fname lname]) (def a1 (->Ape "test1" "test2")) (def a2 (->Ape "test3" "test4")) (def alist '(a1 a2)) (filter #(= "test1" (:fname %)) al

Re: A newbie question with using parkour

2015-02-22 Thread Sunil S Nandihalli
Thanks Jeremy for the response. I was using clojure-1.7.0-alpha5 , parkour 6.2that looked was the original problem. After I changed the version to clojure-1.6.0 I got past that problem and hit a new set of problems. Marshall suggested that the issue could be because of mismatched hadoop-versions. I

Re: A newbie question with using parkour

2015-02-22 Thread Jeremy Heiler
What version of parkour are you using? That will help us match line numbers in the stracktrace with the code. -- 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 membe

A newbie question with using parkour

2015-02-22 Thread Sunil S Nandihalli
Hi Everybody, I am complete newbie to using parkour. I am having trouble just reading in data. Can somebody help me figure out the problem. The code I am using is here.. https://gist.github.com/52f4298e5b6ca6a46699 I agree that there is no other stage apart from the input. I had all other stage

Re: pigpen newbie question

2014-09-15 Thread Sunil S Nandihalli
Thanks Matt for the response. Like you said, I don't really need to be using 1.7.0 I am doing quiet ok with 1.6.0 Thanks, Sunil. On Tue, Sep 16, 2014 at 9:28 AM, 'Matt Bossenbroek' via Clojure < clojure@googlegroups.com> wrote: > Sunil, > > I tried upgrading PigPen to Instaparse 1.3.4, but that p

Re: pigpen newbie question

2014-09-15 Thread 'Matt Bossenbroek' via Clojure
Sunil, I tried upgrading PigPen to Instaparse 1.3.4, but that pulled in Clojure 1.6.0 & now I'm running into some build/jar/versioning issues. I don't think I'll be able to get the update out as soon as promised, but it sounds like not using 1.7.0 will work for you in the meantime. -Matt On

Re: pigpen newbie question

2014-09-11 Thread Sunil S Nandihalli
Thanks Mark and Matt, changing the version back to clojure version 1.6.0 fixed it. Sunil On Fri, Sep 12, 2014 at 7:05 AM, 'Matt Bossenbroek' via Clojure < clojure@googlegroups.com> wrote: > Just saw this response - disregard the questions I asked you on the > pigpen support DL. > > I'll pull in

Re: pigpen newbie question

2014-09-11 Thread Sunil S Nandihalli
Thanks Mark for the response. That was very quick. Let me see if moving to clojure 1.6.0 fixes the issues. Sunil. On Fri, Sep 12, 2014 at 6:58 AM, Mark Engelberg wrote: > You're probably using Clojure 1.7.0 alpha 2, which introduced a new > function called "cat" into the core namespace, which ov

Re: pigpen newbie question

2014-09-11 Thread 'Matt Bossenbroek' via Clojure
Just saw this response - disregard the questions I asked you on the pigpen support DL. I'll pull in the new instaparse & get a new PigPen build out soonish (within a day or two). -Matt On Thursday, September 11, 2014 at 6:28 PM, Mark Engelberg wrote: > You're probably using Clojure 1.7.0 a

Re: pigpen newbie question

2014-09-11 Thread mbossenbroek via Clojure
That's a weird one :) Couple of questions... What version of pigpen are you using? What are you using to compile & produce that output? It doesn't look like lein or gradle output. What OS are you using? Do you have a full sample project to repro? Does your project have any other references? Some

Re: pigpen newbie question

2014-09-11 Thread Mark Engelberg
You're probably using Clojure 1.7.0 alpha 2, which introduced a new function called "cat" into the core namespace, which overlaps with a function in instaparse. A couple nights ago, I updated instaparse to version 1.3.4, with an update to deal with this change in alpha 2, but pigpen has not yet be

pigpen newbie question

2014-09-11 Thread Sunil S Nandihalli
Hi , I am trying to compile a simple clj file which does nothing apart from requiring the pigpen name-space and it fails to compile with the following error. Can anybody help? Attempting to call unbound fn: #'instaparse.combinators-source/cat the full stack trace is here. https://gist.github.com

Re: newbie question: how to include external libraries from Leiningen REPL

2013-11-07 Thread Qiu Xiafei
you may have a look at alembic: https://github.com/pallet/alembic -- -- 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

Re: newbie question: how to include external libraries from Leiningen REPL

2013-11-07 Thread Sean Corfield
On Thu, Nov 7, 2013 at 5:18 AM, Starry SHI wrote: > Hi, I am new to clojure and I find lein REPL very convenient to use. But I > have one question: in REPL, how to include functions defined in other > libraries and call them in my clojure code? As Marshall indicated, you need to edit your project

Re: newbie question: how to include external libraries from Leiningen REPL

2013-11-07 Thread Mars0i
I'm pretty new, also. The Leiningen documentation that's easy to find has all of the information you need ... but it's not easy to sort out at first. Cedric Greevey gives the answer for standard libraries that usually come with Clojure. For others, I suggest: Find the library name and versio

Re: newbie question: how to include external libraries from Leiningen REPL

2013-11-07 Thread Cedric Greevey
Assuming the Java or Clojure library is on your classpath, it *should* be usable from the REPL. (import '[java.library SomeClass]) (.foo (SomeClass. 42)) (require '[clojure.contrib.math :as m]) (m/sqrt 42.0) or whatever. (Didn't this exact question just get asked by someone five minutes ago?

newbie question: how to include external libraries from Leiningen REPL

2013-11-07 Thread Starry SHI
Hi, I am new to clojure and I find lein REPL very convenient to use. But I have one question: in REPL, how to include functions defined in other libraries and call them in my clojure code? For example, my code need to call square root function defined in clojure.contrib.math (included in clojur

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-21 Thread Christopher Bird
Laurent, that is outstanding. Thank you so much. Yup, I am working from the particular to the general here, so having a working example really makes a big difference. I must say that this is a really helpful community. Thanks evryone Chris On Monday, October 21, 2013 7:15:38 AM UTC-5, Laurent P

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-21 Thread Laurent PETIT
Hello Christopher, I will try to address exactly your example, with Counterclockwise, and hopefully you'll get the general view of how to do things on the go. So you want to instanciate a new namespace like this : (ns play.xml-example (:require [clojure.zip :as zip] [clojure.data.zip :as zf] [cl

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-19 Thread John Mastro
> John, thanks. Not a stupid question at all. When learning a new language, a > new environment, and using an unfamiliar OS, there are so many moving parts > that it is sometimes hard to know where to begin when tracking stuff down. My > old and favorite line here is that "signposts are generall

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-19 Thread Christopher Bird
John, thanks. Not a stupid question at all. When learning a new language, a new environment, and using an unfamiliar OS, there are so many moving parts that it is sometimes hard to know where to begin when tracking stuff down. My old and favorite line here is that "signposts are generally made b

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-18 Thread John Mastro
> So, clearly I need to get the libs onto the classpath. The questions are > what libs, where and how? Forgive me if this is a stupid question, but have you already listed the dependency coordinates under the :dependencies key of your project.clj? Leiningen has a sample project.clj here: http

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-18 Thread Josh Kamau
Install counterclockwise plugin on your eclipse. Then import your project into eclipse. There right click the project and there is something like "Convert to leiningen project" . Hope that helps. Josh. On Fri, Oct 18, 2013 at 5:41 PM, Christopher Bird wrote: > Josh, thanks for replying. The cod

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-18 Thread Christopher Bird
Josh, thanks for replying. The code sample was from my batch lein and not the counterclockwise version. So I am clearly still totally messed up[! C On Friday, October 18, 2013 9:11:54 AM UTC-5, Josh Kamau wrote: > > I find it easier to let leiningen handle the dependencies. Eclipse via > count

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-18 Thread Josh Kamau
I find it easier to let leiningen handle the dependencies. Eclipse via counterclockwise plugin adds dependencies declared in project.clj to the classpath. Josh On Fri, Oct 18, 2013 at 4:42 PM, Christopher Bird wrote: > I know this is a pretty old thread, but my questions are quite > similar/re

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-18 Thread Christopher Bird
I know this is a pretty old thread, but my questions are quite similar/related, so I figured here would be a good place for them. I am seriously struggling with both the Eclipse/Kepler-CounterClockwise version in general and the command prompt versions of lein. My major issue is how to tell the

Re: newbie question about symbols

2013-05-30 Thread Brian Craft
ah, thanks. On Thursday, May 30, 2013 2:48:00 PM UTC-7, cjeris wrote: > > Commas are whitespace in Clojure. If you are looking for the unquote > operator, it is ~. > > user=> (first `(~+ 5)) > # > > peace, Chris > > > On Thu, May 30, 2013 at 5:42 PM, Brian Craft > > wrote: > >> What's up with t

Re: newbie question about symbols

2013-05-30 Thread Chris Jeris
Commas are whitespace in Clojure. If you are looking for the unquote operator, it is ~. user=> (first `(~+ 5)) # peace, Chris On Thu, May 30, 2013 at 5:42 PM, Brian Craft wrote: > What's up with the 3rd result here? > > user=> (symbol? +) > false > user=> (symbol? clojure.core/+) > false > u

newbie question about symbols

2013-05-30 Thread Brian Craft
What's up with the 3rd result here? user=> (symbol? +) false user=> (symbol? clojure.core/+) false user=> (symbol? (first `(,+ 5))) true user=> (first `(,+ 5)) clojure.core/+ -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group,

Re: Reducers newbie question

2013-04-27 Thread Stanislav Yurin
Indeed, that was my really bad example with 100. On Saturday, April 27, 2013 4:19:07 PM UTC+3, Alan Busby wrote: > > > On Sat, Apr 27, 2013 at 10:01 PM, Stanislav Yurin > > > wrote: > >> By the way, fold function has [n combinef reducef coll] implementation, >> where n is number of elements col

Re: Reducers newbie question

2013-04-27 Thread Alan Busby
On Sat, Apr 27, 2013 at 10:01 PM, Stanislav Yurin wrote: > By the way, fold function has [n combinef reducef coll] implementation, > where n is number of elements collection is folded by. 512 is just the > default. > Yep I misspoke there, but it is still one of the tricks to be aware of. Lots o

Re: Reducers newbie question

2013-04-27 Thread Stanislav Yurin
Thanks Alan, looking into it. By the way, fold function has [n combinef reducef coll] implementation, where n is number of elements collection is folded by. 512 is just the default. On Saturday, April 27, 2013 3:51:39 PM UTC+3, Alan Busby wrote: > > On Sat, Apr 27, 2013 at 7:35 PM, Stanislav Yur

Re: Reducers newbie question

2013-04-27 Thread Alan Busby
On Sat, Apr 27, 2013 at 7:35 PM, Stanislav Yurin wrote: > Actually, what I was trying to do, is to prototype multithreaded i/o > operation via reducers. And then use fold to regulate number of concurrent > operations. > But now something tells me I am doing not very clever thing. > I'm not entir

Re: Reducers newbie question

2013-04-27 Thread Stanislav Yurin
Yep, thanks, my bad. I got the point. Actually, what I was trying to do, is to prototype multithreaded i/o operation via reducers. And then use fold to regulate number of concurrent operations. But now something tells me I am doing not very clever thing. On Friday, April 26, 2013 5:27:46 PM UTC

Re: Reducers newbie question

2013-04-26 Thread Jim - FooBar();
+1 ! I use 'fold-into-vec' regularly :) Jim On 26/04/13 18:07, Alan Busby wrote: Some additional pointers here (this is a little old though); http://www.thebusby.com/2012/07/tips-tricks-with-clojure-reducers.html On Fri, Apr 26, 2013 at 11:51 PM, László Török >

Re: Reducers newbie question

2013-04-26 Thread Alan Busby
Some additional pointers here (this is a little old though); http://www.thebusby.com/2012/07/tips-tricks-with-clojure-reducers.html On Fri, Apr 26, 2013 at 11:51 PM, László Török wrote: > Hi, > > Not sure what you are trying to do, but xxx is a lazy seq, thus it can > only be consumed sequentia

Re: Reducers newbie question

2013-04-26 Thread László Török
Hi, Not sure what you are trying to do, but xxx is a lazy seq, thus it can only be consumed sequentially and fold falls back to reduce You need a vector. Las Sent from my phone On Apr 26, 2013 4:46 PM, "Stanislav Yurin" wrote: > I was assuming that following code will fold in parallel, but it

Reducers newbie question

2013-04-26 Thread Stanislav Yurin
I was assuming that following code will fold in parallel, but it is reduced sequentially (require '[clojure.core.reducers :as r]) (defn test1 [x] (Thread/sleep 1000) (println (str "Finished:" x)) x) (def xxx (r/map test1 (range 100))) (r/fold + xxx) What am I doing wrong? Thanks. -- -- You

Re: newbie question regarding maps

2012-09-27 Thread Mond Ray
Thanks for the support and especially the examples. I will be back when I bump into the next level of complexity ;-) On Monday, 24 September 2012 12:04:42 UTC+2, Mond Ray wrote: > > I am playing around with maps and using wish lists as a learning tool. I > have a list of items in wish lists lik

Re: newbie question regarding maps

2012-09-26 Thread Timo Mihaljov
On 24.09.2012 13:04, Mond Ray wrote: > user=> wish-lists > [{:name "WL1", :items [{:name "Item 1", :cost 20.0} {:name "Item 2", > :cost 40.0}]} {:name "WL2", :items [{:name "Wiggle 1", :cost 20.0} > {:name "Wiggle 2", :cost 40.0} [:name "Item 3" :cost 10.0]]}] > user=> (assoc-in wish-lists [:name

Re: newbie question regarding maps

2012-09-26 Thread vxm
(defn new-item-ks [wlists wlist-name] (first (keep-indexed #(when (= (:name %2) wlist-name) [%1 :items (count (:items %2))]) wlists))) (assoc-in wish-lists (new-item-ks wish-lists "WL2") {:name "Item 3" :cost 10.0}) On Monday, September 24, 201

Re: newbie question regarding maps

2012-09-25 Thread George Oliver
On Monday, September 24, 2012 3:04:42 AM UTC-7, Mond Ray wrote: > > > As you can see the REPL gives me an error stating that the keys must be > Integers. Is that right? Or is my call process faulty? > > I think the problem is that wish-lists is a vector, so you need a key for the vector first

newbie question regarding maps

2012-09-25 Thread Mond Ray
I am playing around with maps and using wish lists as a learning tool. I have a list of items in wish lists like this: user=> items [{:name "Item 1", :cost 20.0} {:name "Item 2", :cost 40.0}] user=> wiggle-items [{:name "Wiggle 1", :cost 20.0} {:name "Wiggle 2", :cost 40.0} [:name "Item 3" :cos

Re: newbie question on namespaces and reference resources

2012-08-17 Thread Hugo Estrada
Thanks for answering both questions. I believe I saw some musical package, so maybe I will look at that code. Thanks so much :) On Fri, Aug 17, 2012 at 7:20 PM, Stephen Compall wrote: > On Sun, 2012-08-12 at 19:55 -0700, Hugo Estrada wrote: > > 1. What is the best practice with namespaces? Should

Re: newbie question on namespaces and reference resources

2012-08-17 Thread Stephen Compall
On Sun, 2012-08-12 at 19:55 -0700, Hugo Estrada wrote: > 1. What is the best practice with namespaces? Should I follow > java-style namespacing names, or does clojure has its own favored > style? Most packages simply have a prefix matching the name of the package, without domain. This isn't unive

newbie question on namespaces and reference resources

2012-08-15 Thread Hugo Estrada
Hi, there, I have a practical questioned followed by a general questions. 1. What is the best practice with namespaces? Should I follow java-style namespacing names, or does clojure has its own favored style? 2. Is there a reference somewhere out there where I could consult these kinds of ques

Re: a newbie question

2012-07-06 Thread Like The Color
I am also a newbie at clojure and wanted to share that I have found the http://www.4clojure.com/ site to be helpful. You are presented with a problem set for which you provide a solution. If you get it wrong it tells you and you try again. If you get it right you move on to another set. The

Re: newbie question about the difference of proxy [Runnable] and fn

2012-07-06 Thread Moritz Ulrich
On Fri, Jul 6, 2012 at 5:22 PM, grahamke wrote: > (.start (Thread. (println "I ran!") "tName")) You're missing a # here. You create a new thread object passing two args to the Thread constructor: The return value of (println ...) and "tName". println returns nil, so you effectively do (Thread. ni

newbie question about the difference of proxy [Runnable] and fn

2012-07-06 Thread grahamke
Hi, I was experimenting with examples from Stu's Programming Clojure book and I'm puzzled why these two function behave differently when run in the repl: (.start (Thread. (println "I ran!") "tName")) (.start (Thread. (proxy [Runnable] [] (run [] (println "I ran!"))) "tName")) The fi

Re: a newbie question

2012-07-04 Thread Michał Marczyk
Note that subvec as currently implemented does not return a first class vector; it prevents the original vector from being garbage collected, because it delegates all basic operations to it, and it does not support some less-basic operations (you cannot make a transient out of a subvec-created vect

Re: a newbie question

2012-07-04 Thread Jay Fields
I think subvec is likely what you're looking for, but I also wanted to mention take-last for the sake of completeness. On Wed, Jul 4, 2012 at 2:16 PM, Tassilo Horn wrote: > John Holland writes: > > Hi John, > >> If I want to get the last n elements of a list or vector I am doing >> the following

Re: a newbie question

2012-07-04 Thread John Holland
Thanks everybody On Wed, Jul 4, 2012 at 2:16 PM, Tassilo Horn wrote: > John Holland writes: > > Hi John, > > > If I want to get the last n elements of a list or vector I am doing > > the following: > > > > (reverse (take n (reverse thelist))) > > > > Is there a better way to do this? > > For ve

Re: a newbie question

2012-07-04 Thread Tassilo Horn
John Holland writes: Hi John, > If I want to get the last n elements of a list or vector I am doing > the following: > > (reverse (take n (reverse thelist))) > > Is there a better way to do this? For vectors, you can do that much more efficiently using subvec: (subvec my-vec (- (count vec) n

Re: a newbie question

2012-07-04 Thread Timothy Baldridge
> Is there a better way to do this? Use subvec for vectors. For lists, look at take and but-last. Timothy -- 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

Re: a newbie question

2012-07-04 Thread Steven E. Harris
John Holland writes: > Is there a better way to do this? See `take-last'¹ and, specifically for vectors where you can calculate the start index of the suffix, `subvec'². Note that even though Clojure has a `last' function with the same name as Common Lisp's `last'³, the former lacks the optiona

a newbie question

2012-07-04 Thread John Holland
If I want to get the last n elements of a list or vector I am doing the following: (reverse (take n (reverse thelist))) Is there a better way to do this? I'm going through some basic coding exercises which were meant for Java but I'm finding them educational to get started with Clojure. -- Yo

Re: Newbie question about rebinding local variables

2012-04-22 Thread Tim Cross
On Saturday, April 21, 2012 12:26:30 AM UTC+10, Craig Ching wrote: > > > > On Friday, April 20, 2012 9:07:49 AM UTC-5, Walter van der Laan wrote: >> >> You could start with pure functions to handle the game logic, e.g.: >> >> (defn new-game [] >> [[\- \- \-] >>[\- \- \-] >>[\- \- \-]])

Re: Newbie question about rebinding local variables

2012-04-22 Thread Tim Cross
On Friday, April 20, 2012 8:21:56 AM UTC+10, Craig Ching wrote: > > Ok, I've read that what I want to do is a no no. But this is the sort of > thing I did in Scheme about 20 years ago (and because of that I'm probably > misremembering ;-)). > > Basically I'm learning clojure and thought I'd wr

Re: Newbie question about rebinding local variables

2012-04-21 Thread Alex Baranosky
Another non-standard solution you could try is to use the state monad from the monad library. On Apr 21, 2012 3:22 PM, "Sergey Didenko" wrote: > There is also a non-idiomatic way - transform your code to use a > native Java data structure like ArrayList or primitive array. > > You may want it for

Re: Newbie question about rebinding local variables

2012-04-21 Thread Sergey Didenko
There is also a non-idiomatic way - transform your code to use a native Java data structure like ArrayList or primitive array. You may want it for the speed or if the mutable algorithm is more readable. Anyway isolation of the mutable code is always a good advice. (defn new-game [] (let [board

Re: Newbie question about rebinding local variables

2012-04-20 Thread Craig Ching
On Friday, April 20, 2012 1:15:11 PM UTC-5, kurtharriger wrote: > > > Game state does not have to be a map, it could be any datastructure > you want, perhaps a protocol that is implemented by a concrete class > in another JVM language. However, I avoid encapsulation unless there > is a compel

Re: Newbie question about rebinding local variables

2012-04-20 Thread kurtharriger
On Apr 20, 9:43 am, Craig Ching wrote: > Thanks for your input, I appreciate it. > > On Friday, April 20, 2012 10:16:51 AM UTC-5, kurtharriger wrote: > > > And you just need to keep the resulting state, no need to reapply the > > moves. > > Your main method might use a reduce or loop recur. > >

Re: Newbie question about rebinding local variables

2012-04-20 Thread nicolas.o...@gmail.com
This is not the idiomatic way but you can stay quite close from your code by: (defn game [ board ] (fn [n i] (cond (= n :x) (game (assoc board i 'x)) ( = n :o) (game (assoc board i 'o)) (= n :print) (println board (defn (new-game (game (in

Re: Newbie question about rebinding local variables

2012-04-20 Thread Walter van der Laan
You can save state in an atom like this: (def state (atom (new-game))) ; initial state (swap! state move \x [1 1]) ; make a move -- 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 po

Re: Newbie question about rebinding local variables

2012-04-20 Thread Phil Hagelberg
On Fri, Apr 20, 2012 at 7:07 AM, Walter van der Laan wrote: > You could start with pure functions to handle the game logic, e.g.: We did this during swarm coding at ClojureWest on the game of Go, but you could apply the same logic to any board game: https://github.com/technomancy/swarm-go/blob/m

Re: Newbie question about rebinding local variables

2012-04-20 Thread Craig Ching
Thanks for your input, I appreciate it. On Friday, April 20, 2012 10:16:51 AM UTC-5, kurtharriger wrote: > > And you just need to keep the resulting state, no need to reapply the > moves. > Your main method might use a reduce or loop recur. > > (loop [game (new-game)] > (if-not (complete? gam

Re: Newbie question about rebinding local variables

2012-04-20 Thread kurtharriger
And you just need to keep the resulting state, no need to reapply the moves. Your main method might use a reduce or loop recur. (loop [game (new-game)] (if-not (complete? game) (recur (make-random-move game))) -- You received this message because you are subscribed to the Google Groups

Re: Newbie question about rebinding local variables

2012-04-20 Thread kurtharriger
By creating new game objects rather than mutating existing ones you could do things you wouldnt otherwise be able to do. Perhaps you have different solver strategies that you want to apply in parallel. Provided you can give each solver its own copy this is trivial, but if your datastructures req

Re: Newbie question about rebinding local variables

2012-04-20 Thread Craig Ching
On Friday, April 20, 2012 9:07:49 AM UTC-5, Walter van der Laan wrote: > > You could start with pure functions to handle the game logic, e.g.: > > (defn new-game [] > [[\- \- \-] >[\- \- \-] >[\- \- \-]]) > > (defn print-game [game] > (doseq [row game] > (println (apply str row)))

Re: Newbie question about rebinding local variables

2012-04-20 Thread Walter van der Laan
You could start with pure functions to handle the game logic, e.g.: (defn new-game [] [[\- \- \-] [\- \- \-] [\- \- \-]]) (defn print-game [game] (doseq [row game] (println (apply str row (defn move [game mark pos] (assoc-in game pos mark)) (print-game (new-game)) (print-gam

Re: Newbie question about rebinding local variables

2012-04-20 Thread Craig Ching
Thanks for the help to both of you! Question, does it seem heavy handed to do it this way? I mean, atoms are more for thread-safety, aren't they? I don't have threads so it seems a bit much to use atoms for this. Am I better off using recur and trying to loop? Or is this considered an idio

Re: Newbie question about rebinding local variables

2012-04-19 Thread gaz jones
to answer your question directly, you would need to do something like this to make it work the way your example is set up: (defn new-game [] (let [board (atom (into [] (repeat 9 nil)))] (fn [n & [i]] (cond (= n :x) (swap! board assoc i 'x) (= n :o) (swap! board assoc i 'o

Re: Newbie question about rebinding local variables

2012-04-19 Thread Armando Blancas
You could keep the board in an atom so it can mutate; then try to find maybe two good places for mutation to happen, your move and the program's. With the rest being functional you'll avoid the problems of global state while not being forced to fit your logic into a loop of some re-binding that

Newbie question about rebinding local variables

2012-04-19 Thread Craig Ching
Ok, I've read that what I want to do is a no no. But this is the sort of thing I did in Scheme about 20 years ago (and because of that I'm probably misremembering ;-)). Basically I'm learning clojure and thought I'd write a tic tac toe game. But not any tic tac toe, I want to write one where

Re: Sorry Don't understand "for macro", a bug or a newbie-question??

2012-01-20 Thread aschoerk
Ah, thank you, so a newbie question. But helped me a lot. Andreas On Jan 18, 10:26 pm, Jack Moffitt wrote: > > doesn't show any effect of the for. > > The only difference is the additional statement at the end. > > I can not imagine how this statement sequential

Re: Sorry Don't understand "for macro", a bug or a newbie-question??

2012-01-18 Thread dennis zhuang
for returns a lazy sequence.You may prefer doseq: (defn fortest2 [] (doseq [a (range 2 10) b (range 2 10)] (do (println "x: " a " b:" b) (list a b))) (println "ende") ) (fortest2) doseq will be forced for side-effects. 2012/1/19 Jack Moffitt > > doesn't show any effect of t

Re: Sorry Don't understand "for macro", a bug or a newbie-question??

2012-01-18 Thread Jack Moffitt
> doesn't show any effect of the for. > The only difference is the additional statement at the end. > I can not imagine how this statement sequentially behind can influence > the for. for returns a lazy sequence. In the first case, in printing out the result to the REPL, the lazy sequence is reali

Sorry Don't understand "for macro", a bug or a newbie-question??

2012-01-18 Thread aschoerk
Hello, I am quite puzzled: (defn fortest1 [] (for [a (range 2 10) b (range 2 10)] (do (println "x: " a " b:" b) (list a b))) ) (fortest1) Shows the running "for macro" (defn fortest2 [] (for [a (range 2 10) b (range 2 10)] (do (println "x: " a " b:"

Re: Another newbie question

2011-11-08 Thread Sean Corfield
On Tue, Nov 8, 2011 at 4:09 PM, pron wrote: > Yes, but it lacks cross-referencing and linking from within the docstrings > themselves (like Javadoc's @See). You can use :see-also metadata to cause autodoc to generate cross-references with links... I think it would be pretty easy to extend autodoc

Re: Another newbie question

2011-11-08 Thread pron
On Tuesday, November 8, 2011 8:42:13 PM UTC+2, Sean Corfield wrote: > > Have you looked at autodoc? > Yes, but it lacks cross-referencing and linking from within the docstrings themselves (like Javadoc's @See). I would like to suggest tagging in order to compensate for the lack of Javadoc's

Re: Another newbie question

2011-11-08 Thread Sean Corfield
On Tue, Nov 8, 2011 at 3:14 AM, pron wrote: > Yeah, sure, but docstrings aren't linkable. It's interesting that Java, with > all its faults, has an incredible documentation system. Have you looked at autodoc? It's responsible for generating stuff like this: http://clojure.github.com/java.jdbc/

  1   2   3   4   5   >