(newbie) running clojure app without repl
Hi! I've had no experience in Lisp or clojure before. I've only worked with Java and Ruby, so this question may seem stupid. Is there any way to run a clojure app without REPL? For example something like: clojure my_app.clj I've read that you can compile clojure with the comile function, but this function must be called from a clojure application since it's a clojure function, am I right or wrong? Thanks, Linh --~--~-~--~~~---~--~~ 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 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: (newbie) running clojure app without repl
Thanks for the answers. I'm very excited about Clojure, it seems to have all the features I was missing from Java and Ruby. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
do-form swallows exception?
Hi, How come the following code does not throw an exception? (defn foo [] (do (map (fn [_] (throw (RuntimeException. "fail"))) [1 2]) "no exception")) this however does throw exception: (defn foo [] (map (fn [_] (throw (RuntimeException. "fail"))) [1 2])) Is this a bug or am I missing something? --~--~-~--~~~---~--~~ 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 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: do-form swallows exception?
Thank you for the quick answers. I'm new to clojure and functional programming so this "lazy"-stuff is new to me, but it makes sense and is really cool. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
(newbie) idiomatic way to update a vector/list
hello, what is the idiomatic way to do the following in clojure? # ruby pseudo arr = [3 9 4 5] arr[1] = 7 --~--~-~--~~~---~--~~ 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 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: (newbie) idiomatic way to update a vector/list
thanks, i thought (assoc map key val) only works for maps, but i should have read the doc more carefully. On Feb 18, 9:34 pm, James Reeves wrote: > On Feb 18, 8:25 pm, linh wrote: > > > hello, > > what is the idiomatic way to do the following in clojure? > > > # ruby pseudo > > arr = [3 9 4 5] > > arr[1] = 7 > > => (def arr [3 9 4 5]) > #'user/arr > => (assoc arr 1 7) > [3 7 4 5] > > Note that because Clojure data structures are immutable, assoc only > returns the changed value; it doesn't update arr. > > - James --~--~-~--~~~---~--~~ 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 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 can i do this in clojure
hi, how can i do this in clojure? # ruby code def foo(x, y) x + y end def bar [1, 2] end foo(*bar) # this is fine, the result will be 3 foo(bar) # this is not ok, will raise exception bar returns an array of size 2, but foo expects 2 parameters not an array. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
clojure class hierarchy
where can i find information about clojure's data-structure class hierarchy? i would like to know how seq, map, list, vector and set are related. i'm new to clojure and i don't always understand the api doc. a class hierarchy would make it easier for me to understand what functions can be appied to what data-structures. 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 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: Waterfront - The Clojure-based editor for Clojure
where can i read about "application context" pattern? i this the idiomatic way to write GUI in functional languages? i'm writing a small swing based app in clojure, and i have problems wirting the gui, because the gui code tends to be very imperative and messy. On 24 Feb, 15:04, Itay Maman wrote: > I've been silently following Clojure (and this group) for several > months now.Somewhere around December I started working on a Clojure > editor/REPL written in Clojure. This effort evolved into the > Waterfront project which is now available on sourceforge (http:// > sourceforge.net/project/showfiles.php?group_id=249246). > > Waterfront's Highlights: > > * CTRL+E: Eval current selection, or the whole file if the selection > is empty > * Edit -> Eval as you type: When turned on (default) periodically > evaluates your code. Boosts productivity as many errors are detected > on the spot. > * Eval-ed code can inspect/mutate Waterfront by accessing the *app* > variable. For instance, if you eval this expression, > ((*app* :change) :font-name "Arial"), you will choose "Arial" as the > UI font. > * Eval-ed code can inspect the currently edited Clojure program. For > instance, if you eval this expression, ((*app* :visit) #(when (= (str > (first %1)) "cons") (println %1))), the output window will show all > calls, made by your code, to the cons function. > * Syntax and Evaluation errors are displayed on: (1) The Problems > window; (2) The line-number panel, as red markers. > * Source -> Generate -> Proxy: Generates a proxy for the given list of > super-types, with stub implementations for all abstract methods. > * F1: Shows the doc (as per Clojure's (doc x) function) of the > identifier under the caret. > * Source -> Reflect: Shows the synopsis of a Java class when the caret > stands on a class symbol (e.g.: java.awt.Color). > * CTRL+Space: Token-based auto completion. > * Full parenthesis matching. > * An extensible plugin architecture. > * Other goodies such as undo/redo, toggle comment, recently opened > files, indent/unindent, Tab is *always* two spaces, ... > > In order to get started, you need to > (1) Download the waterfront zip file > from:http://sourceforge.net/project/showfiles.php?group_id=249246. > (2) Unpack it into a local directory. > (3) Edit wf.bat: fix the path to clojure.jar according to its > location on your machine. > > Personally, this effort was quite interesting. Writing GUI > applications in a functional language is sometimes a challenging task > (at least if you want your Clojure code not to be a transliteration of > Java code…). I used a pattern the "application context" pattern: an > immutable map describing the application's current state that is > passed around. This made it possible for most of Waterfront's code to > be purely functional. Consequently, plugins can accomplish a lot with > just a handful of lines. Many plugins span about 60 lines of code. > Vast majority of them are less than 200 LOC. The main module, ui.clj, > that implements the underlying engine is also less than 200 LOC. I > think this is a very good indication to Clojure's power. > > Hope you'll find it useful. I'd be happy if anyone would like to join > and contribute to Waterfront. Your feedback, either on-line or > offline, will be highly appreciated. > > -- > Itay Mamanhttp://javadots.blogspot.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 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: The Application Context Pattern
thanks, this will be very useful for me On 27 Feb, 09:05, Itay Maman wrote: > Some of the reaction for Waterfront was related to the Application > Context Pattern (ACP) - The pattern that allows most of Waterfront's > code to be purely functional. I'll try to explain the basics in this > post. Let me start with the motivation: the reason why FP is at odds > with GUI code. > > (Pure) Functional code has no side effects, which implies immutability > of state. There are no fields nor global variables that can be > assigned to. Thus, one function can affect the computation carried out > by another function only by the passing of parameters. Most GUI > systems are built around the notion of event handlers which are > invoked by a message processing loop. There is no chain of calls from > one event handler to another. > In particular, if handler "A" computed some new value it cannot pass > it on to handler "B" because the system will call "B" only after "A" > returns. That's the predicament. > > ACP overcomes this by capturing the applications current state in an > immutable map. All event handlers receive a single parameter which is > the "current" context and compute the "new" context. A typical handler > (henceforth: "context processing function") will carry out these > activities: (a) Examine the current context; (b) Perform some GUI > operations (setSize, setText, etc.); (c) Compute a new context based > on the current context and on information obtained from the GUI > (getText, etc.). The caller (henceforth: "dispatcher") takes the > returned context and will use it as the new current context, the next > time a context processing function is invoked. > > This means that when you register event handler with a Swing widget > the handler needs to to call the ACP dispatcher passing it a context > processing function. > > The net effect of this approach is that only the dispatcher has to > deal with mutable state. The context processors are functional: they > merely compute the new state from the current. > > application-context-pattern.clj (http://groups.google.com/group/ > clojure/web/application-context-pattern.clj) shows a concrete example. > It's about 140 LOC (ripped off from the real Waterfront codebase) > structured as follows: > Lines 1..40: General-purpose helpers. > Lines 40..90: The ACP infrastructure > Lines 90..140: A quick sample, built around ACP. > > The sample program opens a JFrame with two buttons: Input and Output. > A click on the input button will pop-up an input dialog box. A click > on the output button will pop-up a message box showing the last value > entered into the input box. There's also a JLabel showing the length > of the input, but let's ignore it for the moment. > > The entry point into the ACP world is the bootstrap function. It takes > two parameters: a context processing function and an initial context. > In the example, this is carried out at the bottom of the run-it > function: > > (defn run-it [] > (let [build-ui (fn [ctx] > (let [f (javax.swing.JFrame. "Frame") > b-in (javax.swing.JButton. "Input") > b-out (javax.swing.JButton. "Output")] > > (.addActionListener b-in (new-action-listener (fn [event] > ((ctx :dispatch) get-input > > (.addActionListener b-out (new-action-listener (fn [event] > ((ctx :dispatch) show-output > > (.setLayout f (java.awt.FlowLayout.)) > (doseq [x [b-in b-out]] > (.add f x) ) > > (doto f > (.setSize 500 300) > (.setDefaultCloseOperation javax.swing.JFrame/ > DISPOSE_ON_CLOSE) > (.setVisible true)) > > (assoc ctx :frame f) ))] > > (invoke-later #(bootstrap build-ui {})) )) > > invoke-later is a utility function that is mapped to SwingUtilities/ > invokeLater. > > Let's drill down into the build-ui function: It takes the current > context (ctx parameter). Then it creates the frame and the buttons. It > uses new-action-listener (another utility) to register an action > listener with the buttons. The first listener looks like this: > ((ctx :dispatch) get-input > > It uses (ctx :dispatch) to obtain the dispatcher from which ctx was > obtained, and evaluates it passing get-input as the context processing > function. The call to bootstrap initialized this dispatcher and added > the :dispatch mapping to the initial context. > > get-input looks like this: > (defn- get-input [ctx] > (let [reply (javax.swing.JOptionPane/showInputDialog nil "Type in > something")] > (assoc ctx :user-input reply) )) > > It pops-up an input box, and returns a new context which is the same > as the current context except that :user-input is now mapped to value > returned from the input box. > > show-output is the context processing function for the output button: > (defn- show-output [ctx] > (javax.swing.JOptionPane/showMessageDialog nil (ctx :user- > input)) ) > > Note that show-ou
functional programming idiom
hello, what's the common idiom in functional programming regarding checking the validity of arguments to functions. i think this is called defensive programming vs contract programming. for example: ;; this first version of foo checks the validity of arguments inside foo (defn foo [context arg] (if (arg-valid? arg) (change-context context arg) context)) ;; this version assumes that the caller of foo fulfills the preconditions of foo (defn foo "Precondition: (arg-valid? arg)" [context arg] (change context arg)) --~--~-~--~~~---~--~~ 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 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: functional programming idiom
thank you for the information On Mar 1, 5:09 pm, "Michel S." wrote: > On Mar 1, 11:02 am, "Michel S." wrote:> On Feb 28, > 6:16 pm, linh wrote:> hello, > > > what's the common idiom in functional programming regarding checking > > > the validity of arguments to functions. i think this is called > > > defensive programming vs contract programming. > > > Mostly defensive, I think. Some languages (e.g. PLT Scheme) have > > contracts:http://docs.plt-scheme.org/guide/contracts.html > > Also, constructs such as Haskell's Maybe monad (available in clojure- > contrib) simplifies doing defensive programming on a chain of > computation. > > Which reminds me. We have no error monad yet (not as important since > Clojure has Java exceptions, though). > > -- > Michel S. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
clojure macros
hello, there are lots of good examples of clojure macros on the web, but i miss a more detailed explanation. for example what do all these special characters used inside macros really mean ` ' @ ~ # ~...@. anyone know if there's a tutorial for clojure macros (not lisp)? macros are very exotic for us (the people comming from java) and most of us don't want to learn how to do it in lisp and then later re-learn to do it the clojure way. --~--~-~--~~~---~--~~ 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 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 macros
now i've found an interesting article that describes macros in more details http://www.ociweb.com/mark/clojure/article.html#Macros On 2 Mar, 10:27, linh wrote: > hello, > there are lots of good examples of clojure macros on the web, but i > miss a more detailed explanation. > for example what do all these special characters used inside macros > really mean ` ' @ ~ # ~...@. > anyone know if there's a tutorial for clojure macros (not lisp)? > macros are very exotic for us (the people comming from java) and most > of us don't want to learn how to do it in lisp and then later re-learn > to do it the clojure way. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
cells/add-watch question
I have a question about cells. I'm not sure how to explain my problem so maybe the easiest way is to show some code. Let's say I have this piece of code: (def my-atom (atom {... big map with many entries ...})) . (add-watch my-atom :update update-fn) . (swap! my-atom (some-fn ...)) When my-atom changes I want the update-fn to know what has been changed so that it won't have to compare the old my-atom with new my-atom to see the changes. This is beacuse my-atom contains a lot of data and I don't want to search for the change. Is there anyway I can do this? According to the API doc, add-watch must have 4 args: a key, a reference, its old-state and its new state. What I'm missing here is an addtional arg that can be passed in some way to update-fn so that update-fn knows what entries in my-atom has changed. Is there any way do this? --~--~-~--~~~---~--~~ 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 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: cells/add-watch question
Thanks Raffael, I'll try that On Mar 11, 6:42 pm, Raffael Cavallaro wrote: > On Mar 11, 1:24 pm, Raffael Cavallaro > wrote: > > > ;; this just makes a big map atom where integer keys are associated > > with integer values > > should rather be as follows to get integer keyword keys: > > (def my-atom > (atom (assoc (apply hash-map > (take 1000 > (interleave > (map #(keyword (str %)) > (iterate inc 0)) > (iterate inc 100 > :last-update nil))) --~--~-~--~~~---~--~~ 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 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: cells/add-watch question
i didn't think of that. if equality tests is instant, would finding out the difference also be instant? for example, is this instant: (difference new-set old-set) ? On Mar 11, 11:11 pm, Timothy Pratley wrote: > > This is beacuse my-atom contains a lot > > of data and I don't want to search for the change. > > Just curious, but shouldn't equality tests in Clojure always be > instant regardless of data size due to shared structure? I suppose I'm > curious what 'shared structure' gives and what it doesn't. --~--~-~--~~~---~--~~ 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 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: filter1 interesting?
I like that, that makes the code selfdescribing (is there such a word in english?) On Mar 14, 2:58 pm, Craig Andera wrote: > What about overloading first to accept a predicate? > > (first even? (iterate inc 1)) => 2 > > On Sat, Mar 14, 2009 at 8:58 AM, e wrote: > > >> Christophe Grand suggest (seek ...), which I personally like. > > > IMHO > > seek is pretty good for a number of reasons: short, implies first result. > > Minor objection would be that folks may not think it's what they want > > because of how it's used in C where they'd expect it to take a number of > > bytes and a block. (filter-one ...) or (find-first ...) are both ok to me > > ... and preferable to (first (filter ...)) the latter being an idiom you > > have to discover on your own. Another very minor problem with the idiom is > > that the docs say that filter returns a lazy sequence, but it doesn't say > > that the order has to be the same as how the original sequence would be > > consumed. Having an actual function makes the concept of "first" concrete. > > It unties it from filter having to be the implementation. > > > yeah (seek ...) is pretty good. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
reload modified java class
Hello, I want to use REPL to quickly test Java code. Is it possible to reload a modified Java class in REPL? I've searched this forum for answers but haven't found any. --~--~-~--~~~---~--~~ 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 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: reload modified java class
Well I was hoping that someone with more time and skills than me already did that. Thanks for the answers. On Mar 17, 8:14 pm, Stuart Sierra wrote: > On Mar 17, 4:46 am, linh wrote: > > > Is it possible to reload a modified Java class in REPL? > > You could write a custom ClassLoader to load (and then reload) your > Java classes. Not impossible, but not trivial. > > -Stuart Sierra --~--~-~--~~~---~--~~ 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 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: reload modified java class
Emacs and slime works fine for me, but I'm willing to try other alternatives. Thanks for the tip. On 17 Mar, 23:02, Laurent PETIT wrote: > If you don't have a preferred environment right now, or if your preferred > environment is already Eclipse, you could try installing clojuredev. > > It provides a REPL on the standard java process console. This console can be > started either in "Run" or "Debug" mode, so the reloading of java classes is > done by Eclipse as for any other java application (so expect the java class > reloading to behave no more no less than as usual with eclipse : that is, > changing internals of methods works OK, changing the shape of class - adding > methods, etc. - does not work each time, if at all). > > If you're interested, here's the quicklink to clojuredev installation page > (easy to setup since we provide an online update site) > :http://code.google.com/p/clojure-dev/wiki/Documentation > > The site referenced by Meikel seems very interesting for open source > projects, though (javarebel). > > HTH, > > -- > Laurent > > 2009/3/17 linh > > > > > Hello, > > I want to use REPL to quickly test Java code. > > Is it possible to reload a modified Java class in REPL? > > I've searched this forum for answers but haven't found any. --~--~-~--~~~---~--~~ 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 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: Proposed Change to str-utils
> Hi, > > I would generally agree with Stuart that wrapping Java functions is > not a good idea. > > However, string functions come up so often that I think that this is > one area where the rule should be broken, if only for readablility. > I agree, I use these string functions frequently. Maybe these String wrapper functions can be in their own namespace to make it explicit that these are wrapper functions. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---