Some basic guidance to designing functional vs. state parts of app
As a bit of a newbie to the functional + identity/state design space, I'm struggling a bit with where to use identity constructs (refs) and where to stay with pure functions, and could use some guidance. Pardon me if some of my terms are a bit off. Here is a simple hypothetical app for matching Applicants to Jobs. I have several Applicants, each with some set of Skills. There are several Jobs, each with some Requirements. There is some Match relation between Skills and the Jobs they can match. The set of Applicants, each of their skills, and the set of Jobs can change with time. There is a set of Jobs that each Applicant can fill, functionally computed from applicant skills & job requirements & Match. Ok, so jobs_that_an_applicant_can_fill is a pure function, I get that. Do I design a single "World" ref whose state changes with time to different worlds, so adding a new Applicant or even adding a new Skill to an existing Applicant results in a new World value? Or is it better to have an "Applicants" ref and a "Jobs" ref that refer to different sets of those er.. things? Can each Applicant have a "skills" ref, whose state changes to different sets of Skills? Should I design it this way? How do I choose? What are the trade-offs? Any and all guidance, insights, advice etc. welcome! 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 be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Some basic guidance to designing functional vs. state parts of app
Thank you all, the replies so far and the questions have already deepened my understanding considerably! Looking forward to more. I think a bit more discussion like this (not necessarily my quite skimpy example) would be quite valuable to many like me. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojure slides
Re: Emacs + Slime + paredit. I did not see Clojure listed as supported for Slime and paredit. Do you know if: - AquaEmacs (mac) is a shoe-in? - Can you do all Slime stuff in Clojure? evaluate, macro-expand, docs, etc? - Same for par-edit Thanks! On Mar 4, 1:56 pm, Baishampayan Ghose wrote: > Wilson MacGyver wrote: > > Looks like I'll be doing a talk on clojure next week at the local java > > user group. > > > Any recommendations on slides I can steal? :) > > Feel free to use mine > -http://www.slideshare.net/zaph0d/introduction-to-clojure > > Regards, > BG > > -- > Baishampayan Ghose > oCricket.com -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Benefit of declarative functional UI in Clojure?
Would a Clojure app benefit sigificantly from a declarative functional UI along the lines of Lunascript http://www.asana.com/luna or FlapJax http://www.flapjax-lang.org/ ? The results look quite impressive ... but I don't have much to compare to in Clojure. I am relatively new to both Clojure and the functional- reactive programming approach, so looking for some hints on whether it is worth exploring deeply. 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 be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: labrepl, making Clojure more accessible
Just tried this with NetBeans 6.7.1 on OSX 10.5.8. Got through all setup steps with no problem. When I try to start the project REPL, I get: "There did not appear to be both valid clojure and clojure-contrib jars present in the classpath... (some paths to ...1.2.0-master- SNAPSHOT.jar)" If I elect "Use the default platform Clojure-1.0.0", a REPL starts, then (require 'labrepl) gives FileNotFoundException for clojure/ contrib/logging__init.class & logging.clj HTH. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: Logic programming in Clojure
Really nice! Is it aware of all Clojure structures, including maps etc? -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Mutually-referencing structures
(deftype Account [owner balance]) (deftype Person [accounts]) joe has 1 account. How to I create / initialize joe & the account with mutual references? I'd rather not use refs. 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 be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Re: Mutually-referencing structures
Is this a Clojure restriction, or is it intrinsic to functional programming? If my app is essentially about a user creating and editing a graph structure (sometimes via crud-level interactions, other times by somewhat larger refactorings), is either Clojure or functional not a good match? Thanks for any advice! -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Re: Mutually-referencing structures
> It's a consequence of immutable data structures, which are an aspect of > functional programming. An immutable object can never be changed But single-assignment is a quite valid (and more flexible?) form of immutability. I'm not convinced cycles are intrinsically tied to it in any way. (In fact, I initially thought Clojure had an unambiguous sentinel value for "not initialized") I was hoping to develop (or find :) macros to automate the code for maintaining various kinds of 2-way pointers, rather than use separate ID fields or (essentially global) collections of pairs for relations. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Set as function
Why this behavior? user=> (#{5 nil} 5) 5 user=> (#{5 nil} 4) nil user=> (#{5 nil} nil) nil rather than the seemingly more informative: user=> (#{5 nil} 5) true user=> (#{5 nil} 4) false user=> (#{5 nil} nil) true user=> (#{5 false} true) false user=> (#{5 false} false) true i.e. set as characteristic function: element -> bool -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Re: Mutually-referencing structures
On Apr 6, 8:09 am, Christophe Grand wrote: > > Let say one can write: > (def john-doe {:name "John Doe" :email "j...@doe.com" :account {:owner > # :balance 1000}}) At this point the cyclic structure is a consistent value. As long as updates create new values that match the domain invariants, why should any subsequent "value" cause a problem? > Then you want to add 10$ to John's account: > (update-in john-doe [:account :balance] + 10) If that is what you update, then of course you will get ... > The resulting data structure is: > {:name "John Doe" :email "j...@doe.com" :account {:owner # to the OLD root map> :balance 1010}} But how is this unique to cyclic structures? I can always mistakenly create values and update them to end up with a structure that incorrectly combines old and new values. (def john-doe {zip-code: 12345 state: {name: "CA"}}) (update-in john-doe [:zip-code] + 5000) ;; new zip code, invalid old state Maintaining domain invariants is the programmers responsibility, whether or not there are cyclic references. Why wouldn't the same facility that lets you create consistent mutual references in the original John Doe value, also allow you to create consistent mutual references in a consistent new ("updated") John Doe value? -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
A syntax question: positional & keyword
Please don't misunderstand this post - it is not asking for a change of syntax, just trying to understand something. Clojure has chosen positional parameters (just like for Lisp, C, C++, Java, Ruby, Python, Prolog, ...) Smalltalk composes a full method name from a prefix-name + named parameters. [obj] prefix key1: x key2: y key3: z The [obj] part above is an artifact of the single-dispatch model, and is irrelevant to this discussion, so I'll leave it out from here on. Importantly, the method name here is a composite: #prefix:key1:key2:key3 This leads to remarkably readable function calls: 1. (schedule project: p1 after: p2 before: p3 priority: 7) ;; calls schedule:project:after:before:priority vs. 2. (schedule p1 p2 p3 7) Note that 1. in no way requires arbitrary ordering of keywords, maps, de-structuring, etc. The positions are still fixed, just keyword- prefixed. It's like taking the Clojure parameter list (defn schedule [project before after priority] ) and requiring those parameter names (or a formal version thereof which is meant to be part of the interface) at the calling sites. An only-slightly-strained analogy would be only allowing %1 %2 for formal parameters in all function bodies (defn schedule [%1 %2 %3] ( stuff with %1 %2 ...)) or (deftype Person [name age]) and then requiring (1 joe) instead of (:name joe) Just curious - what folks think of fixed-positional-keyword params - whether it was considered for Clojure 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 be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Re: Set as function
On Apr 6, 12:16 am, Alex Osborne wrote: > Calling the set as if it is a fn is a short-hand for "get", that is > retrieving an element from the set. Why would you want to do this, when > to look it up you need to know what element is? Sets are based on > value-equality not reference-equality. Thus you can have an object in > the set that is equal to your lookup key but not identical. Got it, 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 be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Re: A syntax question: positional & keyword
On Apr 6, 4:46 pm, Jarkko Oranen wrote: > problem is that they also make some very common functional patterns > cumbersome: most notably function application (ie. apply), > composition, and higher-order functions. I don't think it should be either-or (and positional would be needed anyway to call out to Java & friends). So your functional patterns could still be done positionally, since the first-class function arguments f & g are not named anyway: (let [f ..., g ..., x ...] (apply f g x) (comp f g)) The arg-lists in the defn would distinguish ;; positional-keyword calls needed ;; function name is a composite ;; one "defn" could create more than one function name (defn schedule [project: p before: b after: a priority: i] ...) from ;; existing defn & calling code could even be unchanged ;; no keywords (defn apply (f args* argseq) ...) -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Re: A syntax question: positional & keyword
On Apr 6, 5:23 pm, Stuart Halloway wrote: > Have you seen destructuring of rest args in the current master branch? > > (defn foo [& {:keys [a b c]}] [a b c]) > > (foo :a 1 :c 3) > => [1 nil 3] > > With this last bit of sugar in place I am extremely happy with > Clojure's arg handling. Hmmm. Looks nice, but if these are optional, any-order keys - is there a run-time cost to construct / deconstruct / lookup? - how do I use foo in apply, comp, and friends? 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 be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Re: A syntax question: positional & keyword
Don't you think - fixed-order named parameters could (should?) be a separate issue from - optional, any-order, named parameters ? ;; :x :y are fixed order, named, while :a :b are optional, named (defn foo [:x :y & {:keys [a b]] [x, y, a, b]) (foo :x 1 :y 2) => [1 2 nil nil] (foo :x 1 :a 2) => error (foo :x 1 :a 3 :y 2) => error (foo :x 1 :y 2 :b 3) => [1 2 nil 3] Note that (defn foo ([:x & {:keys [y]] [x nil]) ([:x :y][x y])) would create 2 function symbols e.g. foo:x and foo:x:y -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Re: Mutually-referencing structures
I would really love to see (clearly by someone much smarter than I :) an insightful summary of these kinds of concept-heavy discussions, "stickied" or "FAQd" or even "book'd" somewhere. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Re: A syntax question: positional & keyword
On Apr 6, 7:03 pm, ataggart wrote: > See: > > http://richhickey.github.com/clojure-contrib/def-api.html#clojure.con... Ah, thank you (all). Will this be in 1.2? Is run-time cost expected to be minor, and will passing unrecognized keys be an error? -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Re: A syntax question: positional & keyword
On Apr 7, 7:56 am, David Nolen wrote: > The runtime cost of destructuring is not worth getting worked up > about. It's easy to check this yourself with (time ...) Results below: user=> (defn fk [& {:keys [a b c]}] (+ a b c)) user=> (defn fp [a b c] (+ a b c)) user=> (time (dotimes [_ 100] (fk :a 2 :b 2 :c 2))) "Elapsed time: 1582.178 msecs" user=> (time (dotimes [_ 100] (fp 2 2 2))) "Elapsed time: 319.243 msecs" Not sure how significant that would be in user code, but I'd rather not have to choose less a less readable version because of the hit. Positional keywords would give the readable function calls without the run-time hit (and we could still use optional &keys if they were somehow distinguished in the function calls). -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: A syntax question: positional & keyword
On Apr 7, 12:37 pm, Armando Blancas wrote: > in other languages they'd be annotations and maybe perceived > as redundant, e.g. a call like: (circle x y radius) is readable Ah, but what about: (circle year population income) vs. (circle :x year :y population :r income) > In Smtalltalk a single-arg keyword message is readable because the > syntax gets the received out of the way to the left: 5.0 raisedTo: 3 > where #raisedTo: is both the selector and keyword. (raise base: 5 to: 3) ;; all keyword (raise 5 to: 3) ;; 1st positional + 2nd keyword Smalltalk may actually be the asymmetrical one here: truck moveX: 5 y: 6 vs. truck move x: 5 y: 6 ;; my "prefixed" version Smalltalk munges the root command name (move) with the keyword for the first argument (X), which is why I showed a prefixed version instead. In Clojure this might be: (move :obj truck :x 5 :y 6) ;; all keyword (move truck :x 5 :y 6) ;; combine position + keyword -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: A syntax question: positional & keyword
On Apr 8, 11:08 am, David Nolen wrote: > In my own code I only avoid the convenience of destructuring in the > rare tight loops such as calculations intended to drive animations. But when you write a function you would have to decide positional vs. keyword. Would you then take a guess about usage in tight loops vs. not? > I've found it to have little effect elsewhere on program performance. I suspect you are right. Anyway, I'm very glad to see the style supported, and hope the cleaner defnk version wins, with some ability to further destructure the keyworded arguments. (defnk f [a b :c 1 :d 2] [a b c d]) -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
How to hide data representation with keywords for deftype accessor?
(deftype A [x]) gives me an accessor (:x anA) Then I decide to change data representation of A without impacting client code, but I don't seem able to define a function (defn :x [anA] ...) Should I be doing something different? 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 be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using "remove me" as the subject.
Which version of Netbeans to use Compojure on OSX?
I see downloads named - Java SE (45MB) - Java FX (76MB) - Java (146MB) - apparently includes Sun Glassfish Server & what-not I'm using OSX 10.5.8, and just want to install the easiest Netbeans (with Enclojure) to for development with Compojure. Would I use Compojure with Jetty? Apache (built into OSX)? 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 be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: problem installing clojure/Enclojure with Netbeans
I had trouble with Enclojure 1.1.1 What worked for me: uninstall it and follow the Netbeans section at http://github.com/relevance/labrepl -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojure 1.2 seq fn enhancement FAQ
On Apr 29, 3:21 am, ataggart wrote: > Functions named contains-key? and contains-val? would make a lot more > sense to me than the current contains? and new seq-contains?. Amen. Even independent of any performance expectations. -- 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 your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en