Re: "I don't feel the absence of a debugger, because I've learnt enough that I don't ever need a debugger."

2013-05-28 Thread Warren Lynn
May I suggest that as useful as your strategies are, they cannot replace a debugger? Let's be clear about our logic before claiming "it is not much needed". Maybe YOU really don't need it, but that is different from claiming it is not needed. A debugger as good as it is cannot replace the 4 fi

Re: "I don't feel the absence of a debugger, because I've learnt enough that I don't ever need a debugger."

2013-05-28 Thread Warren Lynn
> Still miss the Elisp debugger, which is great. It's right there, in your > editing environment. It's good for debugging my own code. It's really > good for working out someone elses code. I wish I debug clojure in the > same way. It's not essential, of course. But nice. > > Phil > I miss

Re: "I don't feel the absence of a debugger, because I've learnt enough that I don't ever need a debugger."

2013-05-29 Thread Warren Lynn
I did not say that a debugger was not useful at all, I said that the > importance of having a > debugger is *overestimated* especially in an immutable world. > > Relying on a debugger as an important tool to support coding is like > admitting > the failure of your code before it runs. It's l

Re: Is it possible to set breakpoint using nrepl-ritz?

2013-03-15 Thread Warren Lynn
> It is using the latest development code (C-c C-x C-b on the line to > break at). A release should be out containing this in the next few > days. > > Hugo > I was eager to use the line debugging commands but had no success. After "M-x nrepl-ritz-jack-in", I loaded a clojure file (just the

Re: Is it possible to set breakpoint using nrepl-ritz?

2013-03-16 Thread Warren Lynn
> Could you create an issue for this. > > > Just did that. Even with "M-x nrepl-ritz-break-on-exception" (and adding an (throw ...) in the code), it still does not work for me. Just hangs. Also after "M-x nrepl-ritz-break-on-exception", my "ac-nrepl" does not work anymore, Whenever auto co

Re: ANN: Spyscope 0.1.3

2013-04-12 Thread Warren Lynn
I requested some of the features added in this release. Thanks a lot for the work. -- -- 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 - plea

Re: ritz-nrepl starts up slowly?

2013-05-13 Thread Warren Lynn
> > Is it normal to take this long to start the repl? > > > I don't know if it is normal. But I can confirm it takes much longer to start ritz-nrepl compared to nrepl only, which itself is already kind of slow. The slow speed really is killing a lot of fun here. -- -- You received this mes

Re: ritz-nrepl starts up slowly?

2013-05-16 Thread Warren Lynn
> The killing of the user process is currently not very reliable. > > > This might be an Emacs "bug" (at least on Windows). The problem is there even for nrepl without ritz (some java process will still dangle there after exiting nrepl). What I did to work around this is to add some code/advi

Avoid duplicate computation in commute?

2012-05-17 Thread Warren Lynn
Hi, The duplicate computation in "commute" seems to me quite a blemish on clojure's beauty. I even see somebody's code with comments "pre- compute x because otherwise commute will call it twice". So I need to keep that fact in the back of my mind when using it? That is not what I was hoping for.

Re: Avoid duplicate computation in commute?

2012-05-17 Thread Warren Lynn
Thanks and these are certainly workable solutions. But is there any particular reason why with commute the update function is ALWAYS called twice, even when no other thread changed the ref value at the commit time? That is what bothers me. On May 17, 5:46 pm, DAemon wrote: > Would some of this di

Re: Avoid duplicate computation in commute?

2012-05-17 Thread Warren Lynn
r as I know. Although I could be > wrong, *throws question to the Gods of clojure* > > > > > > > > On Fri, May 18, 2012 at 8:03 AM, Warren Lynn wrote: > > Thanks and these are certainly workable solutions. But is there any > > particular reason why with commute t

defrecord with "inheritance"

2012-05-20 Thread Warren Lynn
So from what I read the philosophy of Clojure discourages inheritance on concrete data types. However, maybe I am too entrenched in my OO thinking, how do I define a new record type that includes all the data members of another record type? I am thinking about the classic Employee/Person example.

Re: defrecord with "inheritance"

2012-05-20 Thread Warren Lynn
...)})) > > The problem is that you can't reuse methods defined inline, i.e. you can't > say "my record implements this protocol just like that other record". > > воскресенье, 20 мая 2012 г., 23:22:55 UTC+6 пользователь Warren Lynn > написал: > > > > &g

Re: defrecord with "inheritance"

2012-05-20 Thread Warren Lynn
;s life a little bit easier. On May 20, 4:55 pm, Kevin Downey wrote: > On Sun, May 20, 2012 at 1:50 PM, Warren Lynn wrote: > > Thanks. That will work. But I wish things can get more concise and > > elegant. > > > I like the Python idea of "make simple things easier a

Re: defrecord with "inheritance"

2012-05-20 Thread Warren Lynn
m, Kevin Downey wrote: > On Sun, May 20, 2012 at 10:22 AM, Warren Lynn wrote: > > So from what I read  the philosophy of Clojure discourages inheritance > > on concrete data types. However, maybe I am too entrenched in my OO > > thinking, how do I define a new record type tha

Re: defrecord with "inheritance"

2012-05-20 Thread Warren Lynn
Well, I don't want to be a beginner for too long, :-) On May 20, 5:19 pm, Kevin Downey wrote: > On Sun, May 20, 2012 at 2:13 PM, Warren Lynn wrote: > > Maybe for Person/Employee example with very simple functions do not > > need data types, but I don't think that

Re: defrecord with "inheritance"

2012-05-20 Thread Warren Lynn
objectives). Part of my learning here is to find out if the language is right for me. On May 20, 5:37 pm, Bill Caputo wrote: > On May 20, 2012, at 4:23 PM, Warren Lynn wrote: > > >> defrecord, deftype, and defprotocol provide extensible low level > >> abstractions li

Re: defrecord with "inheritance"

2012-05-20 Thread Warren Lynn
sure what > "natural" could possibly mean besides "familiar" which is a limited metric > in my opinion. > > David > > > > > > > > On Sun, May 20, 2012 at 6:17 PM, Warren Lynn wrote: > > Thanks for the suggestion. I understand par

Re: defrecord with "inheritance"

2012-05-20 Thread Warren Lynn
7;d argue with you over whether that is the whole point of high-level > languages.  I might say that high-level languages are there to make coding > more efficient and effective. > > > > > > > > On Sun, May 20, 2012 at 5:16 PM, Warren Lynn wrote: > > > I agree &

Re: defrecord with "inheritance"

2012-05-20 Thread Warren Lynn
nosky > > Sender: clojure@googlegroups.com > Date: Sun, 20 May 2012 17:42:10 > To: > Reply-To: clojure@googlegroups.com > Subject: Re: defrecord with "inheritance" > > I'd argue with you over whether that is the whole point of high-level > languages.  I

Re: defrecord with "inheritance"

2012-05-20 Thread Warren Lynn
cannot do anything on the computer without it. You never know. :-) On May 20, 9:44 pm, David Nolen wrote: > On Sun, May 20, 2012 at 9:35 PM, Warren Lynn wrote: > > I hope my original "feature > > request" at the beginning falls into such category. > > Don't hold y

Re: defrecord with "inheritance"

2012-05-21 Thread Warren Lynn
Sometimes it seems to me"OO" and "inheritance" have become some kind of taboos. I don't believe OO is all that wrong. To me Clojure seems to have good potential to harness the good part of OO without carrying into the bad parts. So I am hoping. :-) On May 21, 2:25 pm, "nicolas.o...@gmail.com" wro

Re: defrecord with "inheritance"

2012-05-22 Thread Warren Lynn
gt;   (age [this] (age (:person this))) > > > Arguably, if we were deferring to the current Java best practices and > > encapsulation, one should be creating interfaces of getters and setters > > rather than directly accessing instance variables anyway, making the extra > &

Re: defrecord with "inheritance"

2012-05-22 Thread Warren Lynn
Maybe some macros can help. But if it is a good and common pattern, then it should be included as part of the the language. One thing I am glad to see in Clojure is it absorbed some known good macros in Common Lisp (like "awhen" becomes "when-let") so people don't need to re- invent the wheels agai

user.clj not working with lein 2.0

2012-06-04 Thread Warren Lynn
Hi, I just started using lein version 2. Before (with lein 1.7), after running "lein swank" and connect with "slime-connect" in emacs, in my REPL i have clojure.repl included in "user" automatically namespace, because I have a file user.clj under ~/.lein with the following content: (use 'clojure.

Re: user.clj not working with lein 2.0

2012-06-04 Thread Warren Lynn
:injections works! slime works too (with slime-describe-symbol for doc). Thank you! On Jun 4, 11:05 pm, Phil Hagelberg wrote: > On Mon, Jun 4, 2012 at 5:55 PM, Warren Lynn wrote: > > (use 'clojure.repl) > > (use 'clojure.java.javadoc) > > > But now in

Exclude some dependencies with lein uberjar

2012-06-12 Thread Warren Lynn
Hi, As titled, I need to exclude certain dependencies from my final .jar file (because those dependencies will already be there in the final target Java environment). How can I do that? Thank you. PS: I am using Leinengen 2 -- You received this message because you are subscribed to the Google G

Re: Exclude some dependencies with lein uberjar

2012-06-12 Thread Warren Lynn
> As the name says uberjar is what you should be able to run with no > worries about the classpath - all deps are included in the final jar. > Since you asked to exclude some deps, you likely run the final jar in > a kind of managed environment. Why are there some deps not the others? > What

Re: Exclude some dependencies with lein uberjar

2012-06-12 Thread Warren Lynn
If you don't need AOT then you can include the common lib in > dependencies in the :dev profile. > > If you need AOT then you'll have to write a plugin that works like a > more selective variant of uberjar. > > -Phil > I do need AOT, and I am not ready yet to write any plugins. Maybe I can

Re: Exclude some dependencies with lein uberjar

2012-06-13 Thread Warren Lynn
> Why does AOT happen after exclusion? Shouldn't exclusion be the last > > step in the process which would hardly break anything and would > > eventually fix the issue? > > Oh, I meant this would be a problem if you used profiles for > separating dependencies. If you use :uberjar-exclusions y

Type hint for vector element?

2012-06-13 Thread Warren Lynn
It is very common for all elements in a vector to be always of the same type. Is there any way to hint the type to Clojure? Does such hint can even improve performance? Thank you. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group

Why is lein so slow?

2012-06-13 Thread Warren Lynn
I cannot help notice that leinengen seems quite slow. Even "lein help" takes 8 seconds to finish printing all the information. I am using version 2 on Windows 7(that .bat file). Can anyone explain what is going on? Or is it just me? Thank you. -- You received this message because you are subsc

Calling Clojure from Java and classloader

2012-06-13 Thread Warren Lynn
Ok, I hit a wall and really did not see this coming. Based on what I have read, its really easy for Clojure and Java to work together. So I wrote some test Clojure code with a very simple defrecord (say named as "testrec") and AOT compile it, create a jar file, and add it to a "HelloWorld" java pr

Re: Calling Clojure from Java and classloader

2012-06-15 Thread Warren Lynn
> It's not really a good idea to AOT your code and then directly try to > use it from java. The generated java bytecode isn't guaranteed to be > stable across versions of clojure, and you're depending on > implementation details. > > One way to use your clojure code from java is through RT

How to do aynchrounous producer/consumer

2012-06-15 Thread Warren Lynn
What I want to do is something I probably have done dozens of times in C++: two threads, one thread putting items in a queue, another taking it out (FIFO). How to do it in Clojure? I am at a loss. I thought about a few options: 1. "watches", but it cannot change the queue itself (can only watc

Re: How to do aynchrounous producer/consumer

2012-06-16 Thread Warren Lynn
On Saturday, June 16, 2012 12:47:03 AM UTC-4, Alan Malloy wrote: > > (map consume (seque (produce-lazily))) > > Thank you! This is not exactly what I want (my input data is pushed from an external Java framework), but I was not aware there is a "seque" function, which might be useful for my oth

Namespace loading with deftype/defrecord used from Java

2012-06-17 Thread Warren Lynn
Basically, the issue is: When a deftype/defrecord named class is used from Java, its containing namespace is not loaded automatically, so even calling a function in the same namespace will raise an exception like this: java.lang.IllegalStateException: Attempting to call unbound fn ... An example

Re: How to do aynchrounous producer/consumer

2012-06-17 Thread Warren Lynn
Thank you all for the suggestions. I decided to use Java as lamina seems an overkill for me and I may lose some control over things I want to have. I was wishing for a pure Clojure solution, but a wrapping layer over the Java works fine. On Sunday, June 17, 2012 4:43:17 AM UTC-4, Jeff Rose wr

General subsequence function

2012-06-27 Thread Warren Lynn
I am surprised that there seems to be no general sub-sequence function that will return a segment of a sequence without changing the underlying concrete type. I found "subvec", but it works only on vectors. "subseq" is not what I thought it is. Did I miss anything? Or is there a simple idiomati

Re: General subsequence function

2012-06-27 Thread Warren Lynn
You can combine 'drop and 'drop-last to get a seq version of subvec (but > lazy and O(n)). As for the issue of concrete types: in general, clojure's > sequence functions return seqs, not instances of whatever concrete type you > gave them. If you need a specific type, you normally just pour t

Re: General subsequence function

2012-06-27 Thread Warren Lynn
> > Ordering problem aside, I'd argue this is not an unreasonable amount of > code for what seems to me a pretty rare set of requirements. Most people > who want a same-type segment from the middle of an ordered collection > (which is already uncommon in my experience) are probably either usin

Re: General subsequence function

2012-06-27 Thread Warren Lynn
Thanks, but this does not keep the concrete type. On Wednesday, June 27, 2012 3:42:25 PM UTC-4, Ulises wrote: > > > I'd forgotten that 'into adds things in the "default" place for whatever > type you're using, hence the reversal on lists. I'm not sure if there's a > simple way to get the same ty

Re: General subsequence function

2012-06-27 Thread Warren Lynn
ns if and > when a need arises. This is neither simple nor pretty, but an advantage of > no-side-effects functional programming is that when you call a pure > function you don't need to worry about how simple or pretty might be its > internal details. > --Larry > > On 6/27

Re: General subsequence function

2012-06-27 Thread Warren Lynn
It seems the name "append" has not yet been taken. How about we do this with Clojure: 1. add a new function "append", which splices multiple ordered collection together and always returns the result in the concrete type of its first argument. So: (append [1] '(2 3)) => [1 2 3] (append '(1) [2

Re: General subsequence function

2012-06-28 Thread Warren Lynn
Some of my thoughts: 1. The argument that other languages do not have a similar thing is not valid. If that is valid, we don't need Clojure in the first place. 2. The argument that other people did not raise the issue before and not enough people support it so this is a non-issue is also not va

Re: General subsequence function

2012-06-28 Thread Warren Lynn
Here is "another language" elisp: Anybody who use Emacs can do this: (subseq (make-vector 5 10) 2 4) => [10 10] (subseq '(10 10 10 10 10) 2 4) => (10 10) As simple as that. Is that even worth the debate? :-) On Thursday, June 28, 2012 11:30:25 AM UTC-4, Warren Lynn

Re: General subsequence function

2012-06-28 Thread Warren Lynn
f (as you will be even slower to to have your own). On Thursday, June 28, 2012 2:52:54 PM UTC-4, Tassilo Horn wrote: > > Warren Lynn writes: > > Hi Warren, > > > 1. add a new function "append", which splices multiple ordered > collection > > together

Re: General subsequence function

2012-06-28 Thread Warren Lynn
ere is the option of trying to convince other people to > do one of the above. That can be anywhere on the scale of amazingly quick > & easy, to incredibly frustrating & hard, depending upon your ideas, how > persuasive you are, and who reads your arguments. > > Andy >

Re: General subsequence function

2012-06-28 Thread Warren Lynn
Is there any reason why "last" needs to be slow on vectors? Can it just do the right thing and be fast on it? On Thursday, June 28, 2012 4:28:30 PM UTC-4, Meikel Brandmeyer (kotarak) wrote: > > Hi, > > Am 28.06.2012 um 20:52 schrieb Tassilo Horn: > > > And yes, there are some counter examples

Why cannot "last" be fast on vector?

2012-06-28 Thread Warren Lynn
This is an off-shoot subject from my last post "General subsequence function". I found people had similar questions before (one year ago): http://groups.google.com/group/clojure/browse_thread/thread/712711f049507c63/aea7cf438aa22922 As of Clojure 1.4, seems nothing changed, as "source" show here

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
Tamreen: Thank you. Your posts really explained why it is so. I understand the reasons now, but I can hardly agree those reasons are good ones (not arguing with you, as you pointed out, the reasons are weak for this case). As I pointed out before in my other post ("General subsequence function

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
Sorry, I should have addressed my last post to "puzzler". On Friday, June 29, 2012 10:51:44 AM UTC-4, Warren Lynn wrote: > > > Tamreen: > > Thank you. Your posts really explained why it is so. I understand the > reasons now, but I can hardly agree those reasons are go

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
Surely nobody can restrict/enforce anything on anybody, and I can always have my own "mycore" ns. In theory, I could even create my own language without the need to persuade anybody (or just fork from Clojure and have my own private copy). That will be the ultimate "Libertarian", but some peopl

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
> The design choice has nothing to do with speed, it has nothing to do > with concrete types like lists and vectors either, no matter what > might have been said before by others. > > David > If the design choice has nothing to do with speed path, Could you let us know why we cannot get fre

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
their > own interrest. > > It is logical you ask for it, but there is no need to insist or maybe > be a little offensive if others don't share your views. > > Regards, > > Nicolas Bousquet. > > On 29 juin, 01:32, Warren Lynn wrote: > > This is an off-sho

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
eld wrote: > > On Fri, Jun 29, 2012 at 7:51 AM, Warren Lynn wrote: > > 1. Put good documentations on the functions, and the programmer needs to > > have some idea what data structure is fast/slow for what use. > > At the risk of continuing what is quickly becoming a rat

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
2012 4:41:59 PM UTC-4, David Nolen wrote: > > On Fri, Jun 29, 2012 at 4:25 PM, Warren Lynn wrote: > > My understanding here is "ISeq" is an INTERNAL, implementation level > > interface/abstraction, not the user/language level abstraction (which in > > this case sh

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
Although I have not yet looked at any of Clojure's internals yet, I suspect the change won't be too difficult (for the right person). So I hope/wish someone with enough knowledge, skills and influence will agree with me and advocate a review of the design ("last" may not be the only one with is

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
The same? If internally it can be faster, be faster. If not, don't change. On Friday, June 29, 2012 6:05:37 PM UTC-4, David Nolen wrote: > > On Fri, Jun 29, 2012 at 5:17 PM, Mark Engelberg > wrote: > > It is clear that some collections *could* support a more efficient last. > > Anything with

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
ed to use "peek" for vector and "last" for sequence. That defeats the very purpose of abstraction. On Friday, June 29, 2012 7:42:14 PM UTC-4, David Nolen wrote: > > On Fri, Jun 29, 2012 at 6:49 PM, Warren Lynn wrote: > > The same? If internally it can be faster, be f

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
Again, I don't know the internal details. If you are saying because of the current implementation, the change is difficult, then we will be talking about the implementation, not about the abstraction design. I have very little to say about that. On Friday, June 29, 2012 7:50:56 PM UTC-4, David

Re: Why cannot "last" be fast on vector?

2012-06-29 Thread Warren Lynn
gerous. So "last" isn't a function I would spend > alot of time trying to fix. > > There is historical precedent for Clojure's "last" function. For example, > see Haskell's "last" function in Data.List. Historical precedent doesn

Re: Why cannot "last" be fast on vector?

2012-06-30 Thread Warren Lynn
eality. On Saturday, June 30, 2012 3:47:58 AM UTC-4, Craig Brozefsky wrote: > > Warren Lynn writes: > > >Although I have not yet looked at any of Clojure's internals yet, I > >suspect the change won't be too difficult (for the right person). So > I >

Re: Why cannot "last" be fast on vector?

2012-06-30 Thread Warren Lynn
On Saturday, June 30, 2012 9:51:56 AM UTC-4, stuart@gmail.com wrote: > > Having separate "peek" and "last", with documented performance > characteristics, makes it straightforward to reason about how code is > likely to perform, a point that Mark made earlier. > > As I said before, I strongl

Re: Why cannot "last" be fast on vector?

2012-06-30 Thread Warren Lynn
e a better experience using it. That is my goal (obvious I hope). On Saturday, June 30, 2012 12:17:39 PM UTC-4, Craig Brozefsky wrote: > > Warren Lynn writes: > > >As I mentioned before, the issue here is not just a fast "last". The > >issue here is

Re: Why cannot "last" be fast on vector?

2012-06-30 Thread Warren Lynn
On Saturday, June 30, 2012 1:03:04 PM UTC-4, Las wrote: > > Warren, > > I think the issue is this: > > You claim there is sg. broken in clojure while admitting that you know > little about how the design decision was made. > > People that know clojure's implementation and the history of design

[ANN] clj-cc lib

2012-06-30 Thread Warren Lynn
Available here: https://github.com/wrn/clj-cc This is a very simple lib (for now only three functions) that I created in response to people's suggestions in the following two threads: 1. Why cannot "last" be fast on vector?

Re: Protocol as an abstract data type

2012-06-30 Thread Warren Lynn
implementation which only supports one abstract protocol!) I don't feel strongly about last specifically, but if people wanted it to behave polymorphically, I'd be happy to volunteer to write the code. Thanks a lot for the detailed analysis and volunteering to write the code. Not surprisingly

Clojure type of Java array

2012-07-01 Thread Warren Lynn
Somebody asks me to add handling of Java array in clj-cc/last. But I am confused what will be the type of Java array in Clojure. Fox example: (type (.toCharArray "Clojure")) => [C ;; Note: it looks like garbage. but that is what I actually got (isa? (type (.toCharArray "Clojure")) j

Re: Clojure type of Java array

2012-07-01 Thread Warren Lynn
So if I want to extend a protocol to all Java arrays, is there a single type I can use? Sounds like not. So I need to extend the protocols to char arrays, int arrays and etc? On Sunday, July 1, 2012 12:20:19 PM UTC-4, dennis wrote: > > (type (.toCharArray "Clojure")) is a class, [C means an a

Re: Clojure type of Java array

2012-07-01 Thread Warren Lynn
u encounter them at runtime. > > http://dosync.posterous.com/51626638 > > David > > On Sun, Jul 1, 2012 at 1:17 PM, Warren Lynn wrote: > > > > So if I want to extend a protocol to all Java arrays, is there a single > type > > I can use? Sounds like not.

'last' on empty collections

2012-07-01 Thread Warren Lynn
Right now (last []) => nil (last [nil]) => nil So there is no way to differentiate these two (except with some emptiness checking). In my opinion (last []) should throw an exception, because that's when last does not apply. From another point of view, there are two cases: 1. The local semantics

Re: Why cannot "last" be fast on vector?

2012-07-01 Thread Warren Lynn
I promised I won't post more on this thread. But Rich is here and I think I can grant myself an excuse to post just one more. End of it, I promise. :-) First, although Rich does not think so, I myself feel this topic is very important as it is not just about "last", It touches some fundamental

Re: 'last' on empty collections

2012-07-01 Thread Warren Lynn
On Sunday, July 1, 2012 4:21:02 PM UTC-4, Dennis Haupt wrote: > > i'd do (actually, i did) it like this: > (my-special-last coll) -> returns the last element or throws an > exception if there is none > (my-special-last coll if-empty) -> in case of an empty collections, > ifEmpty is returned >

Re: 'last' on empty collections

2012-07-01 Thread Warren Lynn
That would be horribly inconsistent with the rest of Clojure, IMO: Sure it will be. That is why I said this is an academic one, and I don't expect any change to current one. > Warren, this and some of your other issues with how Clojure works > makes me curious about your language background.

Protocol specific type hierarchy

2012-07-02 Thread Warren Lynn
When I re-read the thread "defrecord with inheritance" https://groups.google.com/forum/?fromgroups#!searchin/clojure/inherit/clojure/mr-o9sRyiZ0/oM4zRz4dXYsJ I am thinking: conceptually, for code reuse, is it a good idea to have protocol specific type hierarchy? I mean something like this: (defr

Re: Protocol specific type hierarchy

2012-07-03 Thread Warren Lynn
On Tuesday, July 3, 2012 4:18:44 AM UTC-4, Vinzent wrote: > > I believe the protocol's analogue for get-method would be enough. > > > If here you mean we just need to use get-method to directly reuse a protocol method anywhere, I think that is not adequate. We need to maintain the hierarchy s

Re: Protocol specific type hierarchy

2012-07-03 Thread Warren Lynn
On Tuesday, July 3, 2012 12:40:24 PM UTC-4, Vinzent wrote: > > Well, as far as I understand, protocols was made as they were on purpose, > so inability to create hierarchies is a "feature" (like it or not), while > the lack of `get-method`-like thing is clearly a defect (in my mind). > > Anyway

Understand extends? result

2012-07-03 Thread Warren Lynn
In the following example: (defprotocol testp (foo[this])) (extend-protocol testp clojure.lang.PersistentVector (foo [this] "PersistentVector impl")) (extend-protocol testp clojure.lang.Seqable (foo [this] "Seqable impl")) (foo []) => "PersistentVector impl" (foo '()) => "Seqable impl" (extends?

Re: Understand extends? result

2012-07-03 Thread Warren Lynn
On Tuesday, July 3, 2012 2:33:52 PM UTC-4, Ambrose Bonnaire-Sergeant wrote: > > Hi Warren, > > You could use "extenders" to get all Classes that extend to the protocol > and then iterate over them, testing with isa?. > > (some #(isa? MyClass %) (extenders MyProtocol)) > > Thanks, > Ambrose > > Th

Re: Understand extends? result

2012-07-03 Thread Warren Lynn
Is it possible that "satisfies?" is a better predicate to use than "extends?"? > > But it only works on instances, not types. -- 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 tha

Re: Protocol specific type hierarchy

2012-07-03 Thread Warren Lynn
hink > it'd > > be a good idea to implement proof-of-concept of what you have in mind > and > > publish it on Github, so people could try it and compare to what they > > already have. > > > > вторник, 3 июля 2012 г., 21:13:27 UTC

Re: Protocol specific type hierarchy

2012-07-05 Thread Warren Lynn
Ok, it seems I cannot make it work unless the "get-method" for protocol is available, The reason is, in the example by Michal, the return value from "(get-in IFoo [:impls user.Bar :foo])" is a Java function, not a true Clojure function with true dynamic typing. So, take the same example: (def

mutual reference in FP style

2012-07-06 Thread Warren Lynn
Can someone help me figure out how I can have two data structures to refer to each other in functional programing style? I mean something like double linked list, or in a tree where each node keeps a reference to its parent and children. What puzzles me is, as soon as you update the reference in

Re: mutual reference in FP style

2012-07-06 Thread Warren Lynn
Hi, Phil: Thanks for your detailed analysis. My use-case is I have a tree and want to walk over the tree and apply a function on the nodes. The operation of the function also depends on the parent and children of the node, so it will be nice if each node already contains the references to its

Re: mutual reference in FP style

2012-07-07 Thread Warren Lynn
r old value, 2+3 for children > :children ({:value 3, ;; 2 for old value, 1 for parent > :children ()} > {:value 8, ;; 3 for old value, 1 for parent, 4 for children > :children ({:value 7, ;; 4 for old value, 3 for parent > :children (

Re: mutual reference in FP style

2012-07-07 Thread Warren Lynn
On Saturday, July 7, 2012 3:42:58 AM UTC-4, Philip Potter wrote: > > Sounds like zippers may be able to help you here. When you use a zipper to > descend into a tree, it automatically generates a trail of breadcrumbs to > enable you to ascend back to the top, without needing backreferences in t

atom and lock

2012-07-17 Thread Warren Lynn
I have a hard time understanding why there is a need to retry when doing "swap!" on an atom. Why does not Clojure just lock the atom up-front and do the update? I have this question because I don't see any benefit of the current "just try and then re-try if needed" (STM?) approach for atom (may

Re: atom and lock

2012-07-17 Thread Warren Lynn
On Tuesday, July 17, 2012 7:50:10 PM UTC-4, red...@gmail.com wrote: > > if you do it as a lock, then readers must block writers (think it > through). Clojure's reference types + immutable datastructures and the > views on perception that underlay them are strongly opposed to readers > interfer

Re: atom and lock

2012-07-17 Thread Warren Lynn
> (def a (atom {})) > > (defn add-kv [k v] >(swap! assoc k v)) > > If I call add-kv from multiple threads, how can I assume that the map > won't be modified in the middle of the assoc? Sure, I could lock, but > read this article first: > http://en.wikipedia.org/wiki/Non-blocking_algorit

Re: atom and lock

2012-07-17 Thread Warren Lynn
> Finish the thought, what happens when there is "contention", a thread > reads then writes before you acquire the lock to commit. You can try > and making locking work, but you'll just up with CAS based on a lock > > > I am not saying to throw away the "swap!" syntax. "swap!" syntax guarantee

Re: atom and lock

2012-07-17 Thread Warren Lynn
For people who are interested, here is my own version of atom updating functions: ;; A wrapped up atom that can be used in those lock-* functions (deftype LockAtom [atom] clojure.lang.IDeref (deref [this] @(.atom this))) ;; (lock-atom (+ 4 5)) => # (defmacro lock-atom "Like ATOM, but

Re: atom and lock

2012-07-18 Thread Warren Lynn
Thanks for the discussion This is not a reply to any particular post. Here is my thinking on the various points raised. 1. The length of the critical section is irrelevant in this discussion. Even with locks, people agree that the critical section should be as short as possible. So the limiting

Re: atom and lock

2012-07-18 Thread Warren Lynn
It's not. Locks are created by using CAS, not the other way around. > On a x86 machine the swap basically compiles down to a single assembly > code instruction: > > http://jsimlo.sk/docs/cpu/index.php/cmpxchg.html > > On a normal x86 machine, every lock in the system will boil down to > usin

Prefix dot in protocol method

2012-07-22 Thread Warren Lynn
I found that if I define a protocol like this: (defprotocol IProc (procMethod [this] "some method")) I can invoke it on a type either (procMethod object) or (.procMethod object) Note the prefix dot in the second case. I like this "dot" version because that means I can replace a record field

Any downside of record compared to map

2012-07-22 Thread Warren Lynn
I plan to change all my major data structures to records instead of plain maps. Since record has everything a map provides, I figure there won't be any harm. But is that really so? Would appreciate the opinions from people who know better. -- You received this message because you are subscribe

Doc string for variables and record

2012-07-22 Thread Warren Lynn
In Elisp, with "defvar" I can specify a docstring for a variable. I could not find how to do that in Clojure with "def" and "defrecord". Can someone show me the way? Thank you. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group,

Re: Doc string for variables and record

2012-07-22 Thread Warren Lynn
http://clojure.org/special_forms > > (def sym "docstring" 'value) > > I don't think defrecord creates a Var so I don't think you can specify > a docstring for that? > > Thanks that works for symbols. I know derecord does not create a Var, but it would still be nice to be able to have a doc s

Re: Any downside of record compared to map

2012-07-22 Thread Warren Lynn
I don't think you're in the minority. I prefer regular maps to records > in general. struct-map was deprecated "a long time ago" (in Clojure > 1.2). clojure.java.jdbc stopped using struct-map a while back - at the > recommendation of Clojure/core - in favor of regular maps. > > Chas Emerick's

Re: Any downside of record compared to map

2012-07-23 Thread Warren Lynn
Thank everybody for the discussion. I am now aware of some pitfalls in using defrecord. For me, I like to have type information associated with my data. I still prefer defrecord over map in general, but I will proceed with more caution. I think some pitfalls here are not due to the greatness o

  1   2   >