Re: #{:eduction :performance} Trying to understand when to use eduction

2015-07-20 Thread Stuart Sierra
Thanks for the correction, Alex. On Sunday, July 19, 2015 at 12:34:37 PM UTC-4, Alex Miller wrote: > seqs on eductions *are* chunked - they will fall into this case during > seq: > https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L524-L525 > > which produces a chunk

Re: #{:eduction :performance} Trying to understand when to use eduction

2015-07-19 Thread Leon Grapenthin
Stuart and Alex, thank you for your replies and recommondations. I take it then that the problem is the seq casting performed in apply and in reduce1. For now the only way to avoid applys seq casting seems to be a hackish .doInvoke call. Kind regards, Leon. On Sunday, July 19, 2015 at 6:34

Re: #{:eduction :performance} Trying to understand when to use eduction

2015-07-19 Thread Alex Miller
On Sunday, July 19, 2015 at 10:53:25 AM UTC-5, Stuart Sierra wrote: > > Hi Leon, > > I think this is an edge case related to how varargs functions are > implemented in Clojure. > > The varargs arity of `max` is implemented with `reduce1`: core.clj line > 1088 >

Re: #{:eduction :performance} Trying to understand when to use eduction

2015-07-19 Thread Stuart Sierra
Hi Leon, I think this is an edge case related to how varargs functions are implemented in Clojure. The varargs arity of `max` is implemented with `reduce1`: core.clj line 1088 `red

#{:eduction :performance} Trying to understand when to use eduction

2015-07-18 Thread Leon Grapenthin
My understanding was that if I pass an eduction to a process using reduce, I can save the computer time and space because the per step overhead of lazy sequences is gone and also the entire sequence does not have to reside in memory at once. When I time the difference between (apply max (map in

Re: When to use metadata

2015-01-30 Thread adrian . medina
To be clear, I actually agree with Stuart. I would really like to dig into this topic and hear everyones thoughts on this; it's such a large piece of Clojure's private and public API. On Friday, January 30, 2015 at 1:53:37 PM UTC-5, adrian...@mail.yu.edu wrote: > > Metadata fields proliferate

Re: When to use metadata

2015-01-30 Thread adrian . medina
Metadata fields proliferate throughout the standard Clojure value and reference types. It seems odd that one would suggest that this seemingly well supported feature should not be taken advantage of except in very narrow circumstances. What is the rationale for such robust support for runtime m

Re: When to use metadata

2015-01-30 Thread Stuart Sierra
Almost never. Seriously, anything important enough to be included in your program's input or output is almost certainly important enough to be *data*, not metadata. And the non-equality-checking semantics of metadata are confusing. About the only place I've found metadata to be worthwhile is m

Re: When to use metadata

2015-01-29 Thread Jan Herich
Solussd is absolutely correct, but maybe even more simplistic (or easier to grasp) explanation would be to use metadata if you don't want the additional (meta)data to change the equality semantics of the map, for example: (def test-desc1 {:number-of-threads 10}) (def test-desc2 ^{:integration t

Re: When to use metadata

2015-01-29 Thread Joseph Smith
Yes- when the data you want to add shouldn't affect the value of the map. --- Joe R. Smith @solussd > On Jan 29, 2015, at 9:10 AM, Jonathon McKitrick wrote: > > Is there a rule of thumb or set of use cases when metadata is a more elegant > solution than simply adding more entries to a map or

When to use metadata

2015-01-29 Thread Jonathon McKitrick
Is there a rule of thumb or set of use cases when metadata is a more elegant solution than simply adding more entries to a map or record? -- 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 No

Re: When to use ! in function name

2014-07-11 Thread Softaddicts
You do not reuse log file output to propagate state changes. If you do I would like to know for what purpose... In my world the ultimate goal of log file output is human consumption with or without aggregation or alert filtering. It has nothing to do with your system internal state. It's merely

Re: When to use ! in function name

2014-07-11 Thread Cecil Westerhof
2014-07-11 14:28 GMT+02:00 Stefan Kamphausen : > On Friday, July 11, 2014 11:33:34 AM UTC+2, Cecil Westerhof wrote: >> >> 2014-07-10 19:10 GMT+02:00 Softaddicts : >> >> ​but as I understood from others it is not about side-effects, but global >> state. >> > > as James and I already pointed out, th

Re: When to use ! in function name

2014-07-11 Thread Cecil Westerhof
2014-07-11 14:19 GMT+02:00 Softaddicts : > I look at side effects this way, will it ever record some state change > that some > code in the universe will eventually rely on ? > > If no, then there's no state change/side effect to care about. > > Sending a message is a side effect (a pgm will event

Re: When to use ! in function name

2014-07-11 Thread Stefan Kamphausen
Hi, On Friday, July 11, 2014 11:33:34 AM UTC+2, Cecil Westerhof wrote: > > 2014-07-10 19:10 GMT+02:00 Softaddicts >: > ​but as I understood from others it is not about side-effects, but global > state. > as James and I already pointed out, that is not what it is about. The bang is about int

Re: When to use ! in function name

2014-07-11 Thread Softaddicts
I look at side effects this way, will it ever record some state change that some code in the universe will eventually rely on ? If no, then there's no state change/side effect to care about. Sending a message is a side effect (a pgm will eventually use it), writing to a database, ... qualify.

Re: When to use ! in function name

2014-07-11 Thread Cecil Westerhof
2014-07-11 11:28 GMT+02:00 Stefan Kamphausen : > On Friday, July 11, 2014 11:10:53 AM UTC+2, Cecil Westerhof wrote: >> >> 2014-07-10 18:34 GMT+02:00 Plínio Balduino : >> >> IMO, ! is used when change any global state. A side effect like print on >>> screen is not enough to cause a ! in the name. I

Re: When to use ! in function name

2014-07-11 Thread Cecil Westerhof
2014-07-10 19:10 GMT+02:00 Softaddicts : > The fn that does the display is the one having side effects. > Now if your look fn creates the side effect, it should reflect that in its > name. > ​Look discribes the current location. So it has a side-effect, but as I understood from others it is not a

Re: When to use ! in function name

2014-07-11 Thread Stefan Kamphausen
Hi, On Friday, July 11, 2014 11:10:53 AM UTC+2, Cecil Westerhof wrote: > > 2014-07-10 18:34 GMT+02:00 Plínio Balduino >: > >> IMO, ! is used when change any global state. A side effect like print on >> screen is not enough to cause a ! in the name. I think that's why the >> functions print/prin

Re: When to use ! in function name

2014-07-11 Thread Cecil Westerhof
2014-07-10 18:46 GMT+02:00 Stefan Kamphausen : > On Thursday, July 10, 2014 5:28:26 PM UTC+2, Cecil Westerhof wrote: >> >> When a function returns a true/false value you should end it with a '?'. >> >> Clojure Programming says that with side effects you should end the >> function name with a '!'.

Re: When to use ! in function name

2014-07-11 Thread Cecil Westerhof
2014-07-10 18:34 GMT+02:00 Plínio Balduino : > IMO, ! is used when change any global state. A side effect like print on > screen is not enough to cause a ! in the name. I think that's why the > functions print/println don't have ! =) > ​Than I did it in the 'right' way. In the book the where talk

Re: When to use ! in function name

2014-07-10 Thread Softaddicts
The fn that does the display is the one having side effects. Now if your look fn creates the side effect, it should reflect that in its name. But... I wonder why it does so. Looking at something does not change state. You may be better splitting the side effect away from it or change the name. Lo

Re: When to use ! in function name

2014-07-10 Thread James Reeves
In clojure.core, an ending "!" indicates a function that is unsafe for STM, rather than one with side effects. For instance, alter and send are functions with side effects, but have no ending "!" because they're safe to use in a dosync block. In other words, an ending "!" indicates a function has

Re: When to use ! in function name

2014-07-10 Thread Stefan Kamphausen
On Thursday, July 10, 2014 5:28:26 PM UTC+2, Cecil Westerhof wrote: > > When a function returns a true/false value you should end it with a '?'. > > Clojure Programming says that with side effects you should end the > function name with a '!'. > "Use the bang! only for things not safe in an STM

Re: When to use ! in function name

2014-07-10 Thread Plínio Balduino
IMO, ! is used when change any global state. A side effect like print on screen is not enough to cause a ! in the name. I think that's why the functions print/println don't have ! =) Plínio On Thu, Jul 10, 2014 at 12:28 PM, Cecil Westerhof wrote: > When a function returns a true/false value yo

When to use ! in function name

2014-07-10 Thread Cecil Westerhof
When a function returns a true/false value you should end it with a '?'. Clojure Programming says that with side effects you should end the function name with a '!'. I have functions reset-game! and walk!. But what about a function like look? It does not change state, but it displays where you ar

Re: When to use (ensue) ?

2014-06-26 Thread Linus Ericsson
See points 2, 3 and 8 at http://clojure.org/refs It is just a way to obtain the "change lock" of the ref in the dosync transaction, without rewriting it. The alternative would be to explicitly modify it to the same value as it was before, which is potentially wasteful. One possible case where thi

Re: When to use (ensue) ?

2014-06-19 Thread juan.facorro
Hi Hussein, Maybe this StackOverflow Q&A can help in understanding when to use *ensure* : Clojure STM ambiguity factor <http://stackoverflow.com/a/17197281/519383>. HTH, Juan On Thursday, June 19, 2014 10:35:24 AM UTC-3, Hussein B. wrote: > > Hi, > > When dealing with C

When to use (ensue) ?

2014-06-19 Thread Patrick Kristiansen
I believe it is to avoid write skew. Check this Wikipedia page: http://en.m.wikipedia.org/wiki/Snapshot_isolation -- 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 m

When to use (ensue) ?

2014-06-19 Thread Hussein B.
Hi, When dealing with Clojure ref types, when to use (ensure) ? Thanks. -- 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

Re: When to use mutable state

2011-10-14 Thread Michael Gardner
On Oct 14, 2011, at 8:48 AM, Timothy Baldridge wrote: > On Fri, Oct 14, 2011 at 7:58 AM, pistacchio wrote: >> I'm implementing a litte "game" thing in Clojure. So far I'm passing >> around a "world status" object among functions. It is very >> "functional" and I can simulate any moment of the gam

Re: When to use mutable state

2011-10-14 Thread Timothy Baldridge
On Fri, Oct 14, 2011 at 7:58 AM, pistacchio wrote: > I'm implementing a litte "game" thing in Clojure. So far I'm passing > around a "world status" object among functions. It is very > "functional" and I can simulate any moment of the game my simply > feeding the system with a made-up world state.

When to use mutable state

2011-10-14 Thread pistacchio
I'm implementing a litte "game" thing in Clojure. So far I'm passing around a "world status" object among functions. It is very "functional" and I can simulate any moment of the game my simply feeding the system with a made-up world state. Since Clojure has a very sophisticate system for managing

Re: When to use #'

2011-01-13 Thread Laurent PETIT
e reader macro #'x expands to (var x). >> >> from: >> >> http://clojure.org/special_forms#var >> >> On Wed, Jan 12, 2011 at 9:11 PM, Alex Baranosky >> wrote: >> > Hi, I find it extremely hard to google this to learn more! I'd like

Re: When to use #'

2011-01-12 Thread rob levy
'x expands to (var x). > > from: > > http://clojure.org/special_forms#var > > On Wed, Jan 12, 2011 at 9:11 PM, Alex Baranosky > wrote: > > Hi, I find it extremely hard to google this to learn more! I'd like to > > know some good sources of further information

Re: When to use #'

2011-01-12 Thread gaz jones
nosky wrote: > Hi,  I find it extremely hard to google this to learn more!  I'd like to > know some good sources of further information on when to use #' .  It is a > bit mysterious to me at this point. > > -- > You received this message because you are subscribed to the Goog

When to use #'

2011-01-12 Thread Alex Baranosky
Hi, I find it extremely hard to google this to learn more! I'd like to know some good sources of further information on when to use #' . It is a bit mysterious to me at this point. -- You received this message because you are subscribed to the Google Groups "Clojure" gr

Re: Question about when to use protocol+record and compilation warnings

2010-12-28 Thread Damon Snyder
This worked as expected. I just replaced defrecord with deftype here https://github.com/drsnyder/beanstalk/blob/82f301f1f825bb05aa14d85a220ec57c1dea61b2/src/beanstalk/core.clj#L117 and re-ran my tests. The suggestion from Baishampayan to add (:refer-clojure :exclude [read peek use]) also worked. I

Re: Question about when to use protocol+record and compilation warnings

2010-12-28 Thread Damon Snyder
Thanks everyone for all of the feedback. I think I have a solution to the warnings and if I understand deftype/defrecord, I should be able to replace defrecord with deftype in my implementation. I'll give it a try and report back when I have a chance. Thanks, Damon On Dec 26, 7:31 pm, David Nolen

Re: Question about when to use protocol+record and compilation warnings

2010-12-26 Thread David Nolen
On Sun, Dec 26, 2010 at 9:00 PM, Ken Wesson wrote: > On Sun, Dec 26, 2010 at 9:25 PM, Alex Osborne wrote: > > Ken Wesson writes: > > > >>> Actually you don't need to AOT compile records or types. They work fine > >>> for interactive development. > >> > >> Eh. That's not what I saw written elsew

Re: Question about when to use protocol+record and compilation warnings

2010-12-26 Thread Ken Wesson
On Sun, Dec 26, 2010 at 10:00 PM, Ken Wesson wrote: > On Sun, Dec 26, 2010 at 9:25 PM, Alex Osborne wrote: >> Ken Wesson writes: >> Actually you don't need to AOT compile records or types. They work fine for interactive development. >>> >>> Eh. That's not what I saw written elsewhere.

Re: Question about when to use protocol+record and compilation warnings

2010-12-26 Thread Ken Wesson
On Sun, Dec 26, 2010 at 9:25 PM, Alex Osborne wrote: > Ken Wesson writes: > >>> Actually you don't need to AOT compile records or types. They work fine >>> for interactive development. >> >> Eh. That's not what I saw written elsewhere. Or is it just protocols? >> Though usually those are used han

Re: Question about when to use protocol+record and compilation warnings

2010-12-26 Thread Alex Osborne
Ken Wesson writes: >> Actually you don't need to AOT compile records or types. They work fine >> for interactive development. > > Eh. That's not what I saw written elsewhere. Or is it just protocols? > Though usually those are used hand-in-hand with records. Perhaps you're thinking of gen-class?

Re: Question about when to use protocol+record and compilation warnings

2010-12-26 Thread Ken Wesson
On Sun, Dec 26, 2010 at 8:20 PM, Alex Osborne wrote: > Ken Wesson writes: > >> On Sun, Dec 26, 2010 at 7:18 PM, Alex Osborne wrote: > >>> Struct maps were in the language for a long time before defrecord was >>> added.  Records are supposed to replace them for most purposes.  So if >>> in doubt

Re: Question about when to use protocol+record and compilation warnings

2010-12-26 Thread Alex Osborne
Ken Wesson writes: > On Sun, Dec 26, 2010 at 7:18 PM, Alex Osborne wrote: >> Struct maps were in the language for a long time before defrecord was >> added.  Records are supposed to replace them for most purposes.  So if >> in doubt between the two use a defrecord. > > Isn't one advantage of st

Re: Question about when to use protocol+record and compilation warnings

2010-12-26 Thread Ken Wesson
On Sun, Dec 26, 2010 at 7:18 PM, Alex Osborne wrote: > Damon Snyder writes: > >> One of the decisions I wasn't sure about was whether to use a protocol >> or a struct map for the (socket, reader, writer) tuple. I started >> using a struct-map and then switched over to defprotocol/defrecord. >> Se

Re: Question about when to use protocol+record and compilation warnings

2010-12-26 Thread Alex Osborne
Damon Snyder writes: > One of the decisions I wasn't sure about was whether to use a protocol > or a struct map for the (socket, reader, writer) tuple. I started > using a struct-map and then switched over to defprotocol/defrecord. > See > https://github.com/drsnyder/beanstalk/blob/82f301f1f825b

Re: Question about when to use protocol+record and compilation warnings

2010-12-26 Thread Baishampayan Ghose
> But one issue I encountered with defprotocol is that there appears to > be a possible symbol table/space issue. When I compile, I get warnings > like the following: > > Warning: protocol #'beanstalk.core/BeanstalkObject is overwriting > function read > Warning: protocol #'beanstalk.core/Beanstalk

Question about when to use protocol+record and compilation warnings

2010-12-26 Thread Damon Snyder
Hello, In an effort to learn a little more about clojure (and possibly introduce it at work) I decided to write a native client for the Beanstalk work queue. See http://kr.github.com/beanstalkd/ for more information about the queue and https://github.com/drsnyder/beanstalk for the client. One of t

Re: when to use io! macro?

2010-12-04 Thread Baishampayan Ghose
> I've recently discovered the io! macro.  Is this something to try to use all > the time.. or only in certain situations? It's useful when you are exposing some sort of an API (internal & external) and want to prohibit the use of certain functions inside transactions. Regards, BG -- Baishampay

Re: when to use io! macro?

2010-12-03 Thread Sunil S Nandihalli
What I said is purely from reading the documentation .. I have never ever used it. Take it with a pinch of salt! On Sat, Dec 4, 2010 at 8:40 AM, Sunil S Nandihalli < sunil.nandiha...@gmail.com> wrote: > It gives a convenience macro which checks if there is a transaction running > when the followi

Re: when to use io! macro?

2010-12-03 Thread Sunil S Nandihalli
It gives a convenience macro which checks if there is a transaction running when the following code block is called. The idea is that since the code in a transaction could be called a multiple times, you should not do things like sending things on to the network or writing to a file during a transa

Re: when to use io! macro?

2010-12-03 Thread ka
This is a good question and I'm not sure of the right answer or if there is one. Personally, if I were exposing an API I would use the io! macro for sure. Even otherwise its a good convention to follow. On Nov 30, 9:06 am, Alex Baranosky wrote: > Hi guys, > > I've recently discovered the io! macr

when to use io! macro?

2010-11-29 Thread Alex Baranosky
Hi guys, I've recently discovered the io! macro. Is this something to try to use all the time.. or only in certain situations? Alex -- 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 t

Re: When to use loop recur / seq functions?

2010-02-16 Thread Jeff Rose
I think it's preferable to use the sequence functions when possible. This way you get laziness without having to construct lazy-seqs by hand, you get automatic chunking for better performance, and you create code that is easier for other Clojure users to parse. On the other hand, if you find yours

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

When to use loop recur / seq functions?

2010-02-15 Thread stefanmuenchow
Hello, I'm new to clojure and have a question concerning recur and lazy seqs. I implemented a function to calculate the perimeter of a polygon. As I'm used to Java and imperative programming, my first approach was to use loop/recur ('euclidean-distance' is a helper-function that calculates the dis

Re: When to use macros

2009-08-30 Thread ronen
Cool, I guess that there is no "one" correct answer but more a question of style & experience, the separation of logic & code mangling into two parts makes the most sense to me. Ill continue to sharp my macro foo ;) On Aug 30, 8:16 pm, Vagif Verdi wrote: > I would argue that macros always shou

Re: When to use macros

2009-08-30 Thread Vagif Verdi
I would argue that macros always should be syntax wrappers for functions. Coding the logic into a macro in most cases is a mistake. So first write the function that does the work. Then write a macro that simplifies a syntax to call that function. --~--~-~--~~~---~--~--

Re: When to use macros

2009-08-30 Thread Jonathan Smith
On Aug 29, 3:48 pm, ronen wrote: > In a lot of cases its seems that macros are used even when a function > can do the same task, > Macros seems to be less readable than their functional counterparts & > more complex to write (to me at least). > > Its clear that there are special cases in which

Re: When to use macros

2009-08-30 Thread Meikel Brandmeyer
Hi, Am 29.08.2009 um 21:48 schrieb ronen: In a lot of cases its seems that macros are used even when a function can do the same task, Macros seems to be less readable than their functional counterparts & more complex to write (to me at least). Its clear that there are special cases in which ma

When to use macros

2009-08-29 Thread ronen
In a lot of cases its seems that macros are used even when a function can do the same task, Macros seems to be less readable than their functional counterparts & more complex to write (to me at least). Its clear that there are special cases in which macros are the perfect solution (like partial e