Re: style question on tightly coupled functions

2014-11-20 Thread Alex Baranosky
Sean James, yes of course there are times that it is _needed_. Agreed. I just would never opt for using tools like declare and letfn as the _go to tool_. I think of cyclic dependencies as less simple, harder to grok etc. When you need it, by all means have the power to do so, but when you don't n

Re: style question on tightly coupled functions

2014-11-20 Thread James Reeves
On 20 November 2014 19:33, Alex Baranosky wrote: > Imo, that makes the let version even better. The Clojure compiler doesn't > to allow circular dependencies, so I would consider the letfn behavior as > "surprising" and therefore unideal. > It does, via declare. This is often necessary in parser

Re: style question on tightly coupled functions

2014-11-20 Thread Sean Corfield
On Nov 20, 2014, at 11:33 AM, Alex Baranosky wrote: > Imo, that makes the let version even better. The Clojure compiler doesn't to > allow circular dependencies, so I would consider the letfn behavior as > "surprising" and therefore unideal. Mutual recursion is a useful technique in some situa

Re: style question on tightly coupled functions

2014-11-20 Thread Alex Baranosky
Imo, that makes the let version even better. The Clojure compiler doesn't to allow circular dependencies, so I would consider the letfn behavior as "surprising" and therefore unideal. On Thu, Nov 20, 2014 at 2:21 PM, Dan Girellini wrote: > Using letfn allows the local functions to reference each

Re: style question on tightly coupled functions

2014-11-20 Thread Dan Girellini
Using letfn allows the local functions to reference each other arbitrarily. In your example, f2 can call f1 but not vice versa. On Thu, Nov 20, 2014 at 11:08 AM, Alex Baranosky < alexander.barano...@gmail.com> wrote: > letfn has no value imo. It is an unwritten stylistic rule I have to never > us

Re: style question on tightly coupled functions

2014-11-20 Thread Alex Baranosky
letfn has no value imo. It is an unwritten stylistic rule I have to never use it. Why introduce a new macro syntax for something that could just as easily be written as?: (let [f1 (fn [] ...) f2 (fn [] ...)] (+ (f1) (f2))) On Thu, Nov 20, 2014 at 12:41 PM, henry w wrote: > I never he

Re: style question on tightly coupled functions

2014-11-20 Thread henry w
I never heard of letfn before. that looks like a clear way to do what i need. just found this stackoverflow thread which is relevant: http://stackoverflow.com/questions/23255798/clojure-style-defn-vs-letfn On Thu, Nov 20, 2014 at 3:34 PM, Alex Baranosky < alexander.barano...@gmail.com> wrote: >

Re: style question on tightly coupled functions

2014-11-20 Thread Alex Baranosky
I'd structure my app like this. Say there's one "pages" ns with code for different webpages pages/index is a pretty short function pages/dashboard is a more elaborate function and has two subcomponents: ->analytics, and ->user-info pages.analytics/->analytics pages.user-info/->user-info On Thu,

Re: style question on tightly coupled functions

2014-11-20 Thread Tassilo Horn
henry w writes: > you have understood my arguments pretty much. again the thing that > bothers me is that f and g are logically part of x only, but are > visible from y and z (even if and and y are declared higher up, the > same problem applies to their own related, private fns and x). Then decl

Re: style question on tightly coupled functions

2014-11-20 Thread henry w
ok thanks for those thoughts. you have understood my arguments pretty much. again the thing that bothers me is that f and g are logically part of x only, but are visible from y and z (even if and and y are declared higher up, the same problem applies to their own related, private fns and x).

Re: style question on tightly coupled functions

2014-11-20 Thread Gary Verhaegen
I'm not sure I understand your tidiness argument. If x uses g and f, and g and f are private, that's plenty related enough for me to put them in the same namespace, preferably right before x. If f and g are meant to be private, the only reason I would see to put them in a separate namespace is if

Re: style question on tightly coupled functions

2014-11-20 Thread dm3
I guess the question is - why do the extracted functions look ugly or lack cohesion if they still accomplish part of the task previously done by `x`? If they are very general - you can consider moving them somewhere else and making them public, otherwise they should stay in the same namespace, j

style question on tightly coupled functions

2014-11-19 Thread henry w
imagine in a namespace you have functions x, y, and z which are public. function x grows a bit big, so is broken out so that it calls 2 other functions, f and g. now, imagine with all the clean code and refactoring in the world, still f and g have nothing to do with y and z - but are declared

Re: Style-question: self-named attribute getters?

2014-06-26 Thread Alex Miller
This answer says everything I would want to say better than I would say it. Second! Alex On Wednesday, June 25, 2014 9:12:01 PM UTC-5, Ryan Schmitt wrote: > > In object-oriented programming, encapsulation is always and everywhere > regarded as a highly significant design virtue, but the Clojure

Re: Style-question: self-named attribute getters?

2014-06-26 Thread Ryan Schmitt
Most Clojure libraries I've seen only give you a handful of namespaces. I would expect a moderately large Clojure library to expose, say, half a dozen at most. Remember that Clojure has no concept of star imports, even for Java classes, and imports will generally be qualified somehow (e.g. cloj

Re: Style-question: self-named attribute getters?

2014-06-26 Thread Mark P
Thanks Ryan and James - that gives me a few more ideas on how to think about things. Hopefully some of the links Ryan posted will clarify things for me also. Ryan - yes my question about namespaces was to do with understanding the ideal granularity of namespaces. And more specifically, whethe

Re: Style-question: self-named attribute getters?

2014-06-26 Thread James Reeves
It sounds like you're building an API to provide documentation, but instead why not just document the data structure directly? Once you have your data structure design, add functions for non-trivial tasks. So something like "red?" seems a little too trivial and specific. The raw s-expression, (= (

Re: Style-question: self-named attribute getters?

2014-06-25 Thread Ryan Schmitt
The question of how to specify the "shape" of your data is an important one, and I think one of the contributions of Clojure is the way it isolates that problem, instead of complecting it with object-oriented design or static type checking. You might look at Prismatic Schema, a library that off

Re: Style-question: self-named attribute getters?

2014-06-25 Thread Mark P
Thanks Ryan, Mike and James for your comments and info. Ryan I will follow up the links you posted. In the meantime, a request for some clarification... I have read / watched clojure stuff along these lines... ie that data hiding (in an immutable data context) is bad. I thought my approach wa

Re: Style-question: self-named attribute getters?

2014-06-25 Thread James Reeves
OOP places a strong emphasis on information hiding, particularly by wrapping data structures in APIs. Developers with a strong background in OOP tend to try to replicate this style of programming in Clojure. However, idiomatic Clojure emphasises exactly the opposite of this. In Clojure, a bare dat

Re: Style-question: self-named attribute getters?

2014-06-25 Thread Ryan Schmitt
In object-oriented programming, encapsulation is always and everywhere regarded as a highly significant design virtue, but the Clojure people have a bit of a different assessment, particularly when it comes to information. In one talk, Rich Hickey pointed out that encapsulation is for hiding im

Style-question: self-named attribute getters?

2014-06-25 Thread Mike Fikes
I'm curious about this stuff too. (I'm very new to Clojure.) I wouldn't be surprised if the general sentiment is: “Don't.” The argument goes along these lines: By encapsulating, you have introduced a tiny new little API that clients need to learn the semantics of. Additionally, that API is like

Style-question: self-named attribute getters?

2014-06-25 Thread Mark P
I've only recently started real clojure development, so very much still learning what styles work and what don't. I have a question about naming attribute getters... Suppose I want to model "fruit" entities. I will use a hash-map to represent the data for each such entity, and will defn a "ma

Re: Style question (predicates)

2014-04-17 Thread Leif
My personal preference is that fns ending in ? return a strict boolean, to be consistent with clojure.core. If I need the value I create another fn. So I would have nsf-code? *and* get-nsf-code. Plus for more complicated values, if you change their representation you don't have to change the

Re: Style question (predicates)

2014-04-17 Thread Zach Oakes
This is a bit tangential, but your function "is-nsf-code?" brings up another style question. Is it really necessary to use the "is-" prefix? I used to do this too, but I realized recently that it is a Java-ism and seems out of place in Clojure. Clojure's boolean fun

Re: Style question (predicates)

2014-04-17 Thread Mars0i
While *every?* and *not-any?* return true or false, *some* returns the first truthy value in a sequence, or nil if there are none. Similarly, *empty?* returns true or false, while *empty* and *not-empty*return a collection or nil. However, it seems as if* some*, *empty*, and *not-empty *are int

Re: Style question (predicates)

2014-04-17 Thread John Wiseman
In the Common Lisp world it's common for predicates to return a useful value instead of T, when applicable. It seems possible the same principle could apply to clojure. >From CLtL2 : Often a predicate will return nil if it ``fails'' and

Re: Style question (predicates)

2014-04-17 Thread Colin Yates
My 2p - I interpret the contract as being boolean. Truthy values are 'polymorphically' equivalent*1 so sure. The concern would be people relying on the implementation and treating the values as none-truthy (i.e. in your example relying on the fact it is a string being returned, so (= "someStr

Style question (predicates)

2014-04-17 Thread Sean Corfield
The library coding standards[1] say: * Use '?' suffix for predicates. - N.B. - predicates return booleans and the community Clojure style guide[2] says: * The names of predicate methods (methods that return a boolean value) should end in a question mark. (i.e.even?). Both of these imply that

Re: Red Tape Form Validation - a style question

2013-11-24 Thread Mimmo Cosenza
Nice lib. I didn't know about it. Personally I use https://github.com/cemerick/valip for form validation because it allows me to share the validation rules (and unit tests too) between clojure and clojurescript (by adding clojurescript.test, clix and cljsbuild crossovers setting) and still be a

Red Tape Form Validation - a style question

2013-11-24 Thread David Simmons
Hi Folks I've been looking at the red-tape form validation library and really like it (especially coming from a Django background). The one thing that makes me nervous is that the when validating data it uses exceptions if the data is invalid. I'd read somewhere that you should only use except

Re: Style Question

2010-10-10 Thread Stephen C. Gilardi
I think I see the goal now: to allow calling with either a map or sequential key-value pairs. What you have appears correct and minimal for that purpose. For a function taking a sequence, you can accomplish something similar without a second arity by choosing to call directly or call using appl

Re: Style Question

2010-10-10 Thread Stephen C. Gilardi
The answer depends on what you're trying to accomplish. Does this simpler definition allow you to call blah in the ways you want to? (defn blah [& {:as blah-map}] ;; do stuff with blah-map) --Steve On Oct 10, 2010, at 12:39 AM, Grayswx wrote: > Recently, I've been coding functions that ta

Style Question

2010-10-10 Thread Grayswx
Recently, I've been coding functions that take a map as follows. I feel like it is slightly messy, though, and was wondering if any one else could think of a reason not to do it: (defn blah ([blah-map] ;; do stuff with blah-map) ([key val & {:as blah-map}] (blah (assoc blah-map key va

Re: Newbie style question - implementing binary search

2010-07-28 Thread Dave Snowdon
Thanks. That does look clearer. Dave On Jul 27, 4:15 pm, Joost wrote: > > I think the main thing that's confusing here is that you're messing > with offsets and split collections at once. At least is was confusing > to me. :) > > I think for binary search (which implies random lookup is ~ O(n) >

Re: Newbie style question - implementing binary search

2010-07-27 Thread Joost
Dave Snowdon wrote: > ; helper function that splits a collection into halves > (defn halve [coll] > (let [len (count coll), hl (- len (/ len 2))] > [(take hl coll) (drop hl coll)] > ) > ) > > ; takes a value and an ordered sequence and returns the index of the value > or -1 > (defn chop

Newbie style question - implementing binary search

2010-07-27 Thread Dave Snowdon
Hi folks I've just started teaching myself clojure and for lack of a "real" project to use it on I've been using the "code kata" on pragprog.com as example problems to solve. I've implemented the binary search as described here: http://codekata.pragprog.com/2007/01/kata_two_karate.html however I'm

Re: Simlpe style question

2010-05-21 Thread edlich
Dear freinds, > I would be interested in your feedback now that you've read all the > different proposed alternatives ? Thanks a lot for all these fruitful answers! I am very grateful. Especially the examples of Laurent and Islon where very impressive. I think this should be a major aspect in bo

Re: Simlpe style question

2010-05-20 Thread Laurent PETIT
edlich, I would be interested in your feedback now that you've read all the different proposed alternatives ? -- 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

Re: Simlpe style question

2010-05-19 Thread islon
You can write this function in clojure in the same style: (defn move2ascii [move] (let [f1 (/ move 100) f2 (mod move 100) row1 (int (inc (/ f1 8))) row2 (int (inc (/ f2 8))) col1 (char (+ (mod f1 8) 97)) col2 (char (+ (mod f2 8) 97))] (str col1 row1 co

Re: Simlpe style question

2010-05-19 Thread carlitos
Hello, On May 19, 4:47 pm, Jay Fields wrote: > I'm not sure what the output should look like, The fact that it is not obvious what the original code was supposed to do indicates that it was not very readable... Something like this would be much easier to understand (not very compact, though):

Re: Simlpe style question

2010-05-19 Thread Jay Fields
Stefan, I'm not sure what the output should look like, so it's hard for me to create a tested version. However, I came up with the following code that is similar to what you've written. (defn move2ascii [i] (let [x (/ i 100) y (mod i 100)] (letfn [(row [i] (-> i (/ 8) (+ 1))) (col [i] (-> i

Re: Simlpe style question

2010-05-19 Thread Laurent PETIT
Hello, don't let anybody convince you that clojure code should be both compact and unreadable for common mortals to deserve the right to be called idiomatic ! The first example which you consider "clojure style" is unredeable ! I tried several variations of coding this in clojure (not tested) h

Simlpe style question

2010-05-19 Thread edlich
Dear Community, I have one question about readability. As I am not yet deep into Clojure I can only post scala but I am sure you will get my point. Recently I wrote the following dump function in Scala: // convert 1228 to "e2e4" def move2ascii(move: Int): String = { // Clojure Style (((mo

Re: Clojure style question, mutable global data structures using Java?

2009-01-16 Thread Christophe Grand
BerlinBrown a écrit : > > On Jan 16, 12:47 pm, Christophe Grand wrote: > >> BerlinBrown a écrit : >> >> >>> Thanks all, this is what I ended up with: >>> For noobs like myself, I am using this code to monitor files and >>> refresh it when the file gets modified. I used 'ref' and 'agent'

Re: Clojure style question, mutable global data structures using Java?

2009-01-16 Thread Mark Volkmann
On Fri, Jan 16, 2009 at 12:13 PM, BerlinBrown wrote: > > On Jan 16, 12:47 pm, Christophe Grand wrote: >> BerlinBrown a écrit : >> >> > Thanks all, this is what I ended up with: >> > For noobs like myself, I am using this code to monitor files and >> > refresh it when the file gets modified. I

Re: Clojure style question, mutable global data structures using Java?

2009-01-16 Thread BerlinBrown
On Jan 16, 12:47 pm, Christophe Grand wrote: > BerlinBrown a écrit : > > > Thanks all, this is what I ended up with: > > For noobs like myself, I am using this code to monitor files and > > refresh it when the file gets modified. I used 'ref' and 'agent'. > > > (def file-monitor-agent (agent

Re: Clojure style question, mutable global data structures using Java?

2009-01-16 Thread Christophe Grand
BerlinBrown a écrit : > Thanks all, this is what I ended up with: > For noobs like myself, I am using this code to monitor files and > refresh it when the file gets modified. I used 'ref' and 'agent'. > > (def file-monitor-agent (agent false)) > (def file-state (ref {:open-state false})) > (de

Re: Clojure style question, mutable global data structures using Java?

2009-01-16 Thread BerlinBrown
On Jan 16, 11:49 am, Christophe Grand wrote: > BerlinBrown a écrit : > > > On Jan 16, 11:10 am, BerlinBrown wrote: > > >> I am working on this GUI tool and want to keep 'global' data > >> structures in memory. For example, lets say I have a checkbox and > >> want to be able to keep and access

Re: Clojure style question, mutable global data structures using Java?

2009-01-16 Thread Christophe Grand
BerlinBrown a écrit : > > On Jan 16, 11:10 am, BerlinBrown wrote: > >> I am working on this GUI tool and want to keep 'global' data >> structures in memory. For example, lets say I have a checkbox and >> want to be able to keep and access the state of that checkbox at any >> time. Right now,

Re: Clojure style question, mutable global data structures using Java?

2009-01-16 Thread Stuart Halloway
Hi Berlin, Probably ref, if the state must be coordinate with other state, or atom, if it is totally independent. But you might be able to avoid using mutable state at all. We would need a larger example to tell. Stuart > On Jan 16, 11:10 am, BerlinBrown wrote: >> I am working on this GUI

Re: Clojure style question, mutable global data structures using Java?

2009-01-16 Thread BerlinBrown
On Jan 16, 11:10 am, BerlinBrown wrote: > I am working on this GUI tool and want to keep 'global' data > structures in memory. For example, lets say I have a checkbox and > want to be able to keep and access the state of that checkbox at any > time. Right now, I am thinking the easiest thing

Clojure style question, mutable global data structures using Java?

2009-01-16 Thread BerlinBrown
I am working on this GUI tool and want to keep 'global' data structures in memory. For example, lets say I have a checkbox and want to be able to keep and access the state of that checkbox at any time. Right now, I am thinking the easiest thing to do is using a Java hashmap and change the state

Re: Macro Style Question: Expanding to Multiple (def ...) Forms

2008-12-15 Thread Michael Wood
On Mon, Dec 15, 2008 at 4:52 PM, Randall R Schulz wrote: > > Hi, > > I'm wondering whether it's a good idea to create a defsomething -style > macro that establishes multiple root bindings? In other one, a macro > that expands to multiple (def ...) forms? Well that sounds quite like declare: use

Re: Macro Style Question: Expanding to Multiple (def ...) Forms

2008-12-15 Thread Michael Reid
Hi Randall, Seems the general consensus is that there is nothing inherently bad with such a design. The idea of macros is to give you the power to generate code from commonly occurring templates. Emitting multiple def forms certainly falls under this umbrella. /mike. On Mon, Dec 15, 2008 at

Macro Style Question: Expanding to Multiple (def ...) Forms

2008-12-15 Thread Randall R Schulz
Hi, I'm wondering whether it's a good idea to create a defsomething -style macro that establishes multiple root bindings? In other one, a macro that expands to multiple (def ...) forms? The first thing I noticed when I did this is that (barring further machinations within the macro) it evalua

Re: sequence question and style question

2008-11-05 Thread Graham Fawcett
On Wed, Nov 5, 2008 at 2:00 PM, Stuart Halloway <[EMAIL PROTECTED]> wrote: > > Duh. Thanks, and I will be adding that to the sequences chapter. :-/ > > Stuart You're welcome -- looking forward to the book! Best, Graham > >> >> On Wed, Nov 5, 2008 at 12:56 PM, Stuart Halloway >> <[EMAIL PROTECT

Re: sequence question and style question

2008-11-05 Thread Stuart Halloway
Duh. Thanks, and I will be adding that to the sequences chapter. :-/ Stuart > > On Wed, Nov 5, 2008 at 12:56 PM, Stuart Halloway > <[EMAIL PROTECTED]> wrote: >> >> (1) Is there a simpler way to define pairwise, which takes an >> existing >> sequence and then returns its items a pair at a time?

Re: sequence question and style question

2008-11-05 Thread Graham Fawcett
On Wed, Nov 5, 2008 at 12:56 PM, Stuart Halloway <[EMAIL PROTECTED]> wrote: > > (1) Is there a simpler way to define pairwise, which takes an existing > sequence and then returns its items a pair at a time? > > (defn pairwise [& seq] > (map vector (take-nth 2 seq) (take-nth 2 (rest seq The b

sequence question and style question

2008-11-05 Thread Stuart Halloway
(1) Is there a simpler way to define pairwise, which takes an existing sequence and then returns its items a pair at a time? (defn pairwise [& seq] (map vector (take-nth 2 seq) (take-nth 2 (rest seq (2) When writing a function like pairwise, are there any bright-line rules about whethe

Re: Style question

2008-10-16 Thread Meikel Brandmeyer
Hi, Am 16.10.2008 um 23:36 schrieb Tom Emerson: I'd like to solicit comments on better ways I could have written it: (defn- split-line [line] (let [parts (seq (.split line ":"))] (loop [mills (drop 1 parts) result (list (first parts))] (if (nil? mills) (reverse result)

Re: Style question

2008-10-16 Thread Tom Emerson
Meikel, Many thanks: I *knew* there had to be a more succinct way to do it... think I need to stare at the Clojure API documentation a bit more. :) Kind regards, -tree On Thu, Oct 16, 2008 at 5:48 PM, Meikel Brandmeyer <[EMAIL PROTECTED]> wrote: > Hi, > > Am 16.10.2008 um 23:36 schrieb Tom

Re: Style question

2008-10-16 Thread Rich Hickey
On Oct 16, 5:36 pm, "Tom Emerson" <[EMAIL PROTECTED]> wrote: > Hello all, > > I wrote a function that behaves as: > > user> (split-line "785:3:39334:1:43103") > ("785" ("3" "39334") ("1" "43103")) > > I'd like to solicit comments on better ways I could have written it: > > (defn- split-line >

Style question

2008-10-16 Thread Tom Emerson
Hello all, I wrote a function that behaves as: user> (split-line "785:3:39334:1:43103") ("785" ("3" "39334") ("1" "43103")) I'd like to solicit comments on better ways I could have written it: (defn- split-line [line] (let [parts (seq (.split line ":"))] (loop [mills (drop 1 parts)