Search Results

Search found 365 results on 15 pages for 'clojure'.

Page 11/15 | < Previous Page | 7 8 9 10 11 12 13 14 15  | Next Page >

  • How can I mix optional keyword arguments with the & rest stuff?

    - by Rayne
    I have a macro that takes a body: (defmacro blah [& body] (dostuffwithbody)) But I'd like to add an optional keyword argument to it as well, so when called it could look like either of these: (blah :specialthingy 0 body morebody lotsofbody) (blah body morebody lotsofboy) How can I do that? Note that I'm using Clojure 1.2, so I'm also using the new optional keyword argument destructuring stuff. I naively tried to do this: (defmacro blah [& {specialthingy :specialthingy} & body]) But obviously that didn't work out well. How can I accomplish this or something similar?

    Read the article

  • function to efficiently check a change of value in a nested hashmap

    - by zcaudate
    the motivation is for checking what has changed in a deeply nest map, kind of like a reverse of update-in. This is a simple example: (def p1 {:a {:a1 :1 :a2 :2} :b {:b1 :1 :b2 :2}}) (def p2 (update-in p1 [:a :a1] (constantly :updated)) ;; => {:a {:a1 :updated :a2 :2} ;; :b {:b1 :1 :b2 :2}} (what-changed? p1 p2) ;; => {:keys [:a :a1] :value :updated) (what-changed? p2 p1) ;; => {:keys [:a :a1] :value :2) I'm hoping that because clojure maps are persistent data-structures, there may be a smart algorithm to figure this out by looking at the underlying structure as opposed to walking through the nested maps and comparing the difference.

    Read the article

  • How to write this kind of java source in clojure. [closed]

    - by tikky
    I want to know how to write a clojure code by looking at a java code like this. import xxxxxx import com.vaadin.terminal.gwt.server.AbstractApplicationServlet; public class Clojure4Vaadin extends AbstractApplicationServlet { @Override protected Class <? extends Application > getApplicationClass() throws ClassNotFoundException { return Application.class; } @Override protected Application getNewApplication(HttpServletRequest request) throws ServletException { try { RT.load(getServletConfig().getInitParameter("script-name"), true); //run Lisp function return (Application)RT.var(getServletConfig().getInitParameter("package-name"),getServletConfig().getInitParameter("function-name")).invoke(new String[0]); } catch (Exception e) { throw new ServletException(e); } } } I need to write a code clojure code which can do the sane thing that this java code can do.

    Read the article

  • Yet another Haskell vs. Scala question

    - by Travis Brown
    I've been using Haskell for several months, and I love it—it's gradually become my tool of choice for everything from one-off file renaming scripts to larger XML processing programs. I'm definitely still a beginner, but I'm starting to feel comfortable with the language and the basics of the theory behind it. I'm a lowly graduate student in the humanities, so I'm not under a lot of institutional or administrative pressure to use specific tools for my work. It would be convenient for me in many ways, however, to switch to Scala (or Clojure). Most of the NLP and machine learning libraries that I work with on a daily basis (and that I've written in the past) are Java-based, and the primary project I'm working for uses a Java application server. I've been mostly disappointed by my initial interactions with Scala. Many aspects of the syntax (partial application, for example) still feel clunky to me compared to Haskell, and I miss libraries like Parsec and HXT and QuickCheck. I'm familiar with the advantages of the JVM platform, so practical questions like this one don't really help me. What I'm looking for is a motivational argument for moving to Scala. What does it do (that Haskell doesn't) that's really cool? What makes it fun or challenging or life-changing? Why should I get excited about writing it?

    Read the article

  • How to map a test onto a list of numbers

    - by Arthur Ulfeldt
    I have a function with a bug: user> (-> 42 int-to-bytes bytes-to-int) 42 user> (-> 128 int-to-bytes bytes-to-int) -128 user> looks like I need to handle overflow when converting back... Better write a test to make sure this never happens again. This project is using clojure.contrib.test-is so i write: (deftest int-to-bytes-to-int (let [lots-of-big-numbers (big-test-numbers)] (map #(is (= (-> % int-to-bytes bytes-to-int) %)) lots-of-big-numbers))) This should be testing converting to a seq of bytes and back again produces the origional result on a list of 10000 random numbers. Looks OK in theory? except none of the tests ever run. Testing com.cryptovide.miscTest Ran 23 tests containing 34 assertions. 0 failures, 0 errors. why don't the tests run? what can I do to make them run?

    Read the article

  • Should I use Java for a custom Swing component designed for a clojure app?

    - by nansen
    I want a simple timeline component (like in video editing software) for a clojure/seesaw app and I am wondering if it is a good approach to implement this directly with clojure and seesaw or if I should write it in java and make my clojure wrapper around it. Or more generally: is a functional programming language optimal for writing UI widgets? I cannot imagine doing that without a lot of state involved. And wasn't OO invented for UI-development in the first place?

    Read the article

  • Calculating rgb vals for BufferedImage

    - by Hamza Yerlikaya
    I am using following snippet to build a 32 bit integer to use with setRGB of BufferedImage (bit-or (bit-shift-left a 24) (bit-or (bit-shift-left r 16) (bit-or (bit-shift-left g 8) b))) after writing colors reading them back reveals wrong colors is there a fault in my logic?

    Read the article

  • Could not locate compojure in classpath

    - by Xian
    I am trying the various Getting started examples and I can get a basic hello world example working with basic HTML in the route as such (ns hello-world (:use compojure.core ring.adapter.jetty) (:require [compojure.route :as route])) (defroutes example (GET "/" [] "<h1>Hello World Wide Web!</h1>")) (run-jetty example {:port 8080}) But when I attempt to use the html helpers like so (ns hello-world (:use compojure ring.adapter.jetty) (:require [compojure.route :as route])) (defroutes example (GET "/" (html [:h1 "Hello World"]))) (run-jetty example {:port 8080}) Then I get the following error [null] Exception in thread "main" java.io.FileNotFoundException: Could not locate compojure__init.class or compojure.clj on classpath: (core.clj:1)

    Read the article

  • How to bundle a native library and a JNI library inside a JAR?

    - by Alex B
    The library in question is Tokyo Cabinet. I want is to have the native library, JNI library, and all Java API classes in one JAR file to avoid redistribution headaches. There seems to be an attempt at this at GitHub, but It does not include the actual native library, only JNI library. It doesn't work (for me): when I use this JAR, the JVM does not even seem to find the JNI library which is packaged inside the JAR: java.lang.UnsatisfiedLinkError: no jtokyocabinet in java.library.path (tokyo_cabinet.clj:19)

    Read the article

  • How do I authenticate to a Proxy Server from clj-apache-http?

    - by erikcw
    I'm trying to get up an running using http://github.com/rnewman/clj-apache-http (http/get (java.net.URI. url) :headers {"User-Agent" user-agent} :parameters (http/map->params {:default-proxy (http/http-host :host "localhost" :port 8888)}) :as :string) Problem is, my proxy (squid) requires authentication. How do I "feed" my username/password into this library? Thanks!

    Read the article

  • How would the 'Model' in a Rails-type webapp be implemented in a functional programming langauge?

    - by ceptorial
    In MVC web development frameworks such as Ruby on Rails, Django, and CakePHP, HTTP requests are routed to controllers, which fetch objects which are usually persisted to a backend database store. These objects represent things like users, blog posts, etc., and often contain logic within their methods for permissions, fetching and/or mutating other objects, validation, etc. These frameworks are all very much object oriented. I've been reading up recently on functional programming and it seems to tout tremendous benefits such as testability, conciseness, modularity, etc. However most of the examples I've seen for functional programming implement trivial functionality like quicksort or the fibonnacci sequence, not complex webapps. I've looked at a few 'functional' web frameworks, and they all seem to implement the view and controller just fine, but largely skip over the whole 'model' and 'persistence' part. (I'm talking more about frameworks like Compojure which are supposed to be purely functional, versus something Lift which conveniently seems to use the OO part of Scala for the model -- but correct me if I'm wrong here.) I haven't seen a good explanation of how functional programming can be used to provide the metaphor that OO programming provides, i.e. tables map to objects, and objects can have methods which provide powerful, encapsulated logic such as permissioning and validation. Also the whole concept of using SQL queries to persist data seems to violate the whole 'side effects' concept. Could someone provide an explanation of how the 'model' layer would be implemented in a functionally programmed web framework?

    Read the article

  • How to select nth element of particular type in enlive?

    - by Mad Wombat
    I am trying to scrape some data from a page with a table based layout. So, to get some of the data I need to get something like 3rd table inside 2nd table inside 5th table inside 1st table inside body. I am trying to use enlive, but cannot figure out how to use nth-of-type and other selector steps. To make matters worse, the page in question has a single top level table inside the body, but (select data [:body : :table]) returns 6 results for some reason. What the hell am I doing wrong?

    Read the article

  • Lazy Sequences that "Look Ahead" for Project Euler Problem 14

    - by ivar
    I'm trying to solve Project Euler Problem 14 in a lazy way. Unfortunately, I may be trying to do the impossible: create a lazy sequence that is both lazy, yet also somehow 'looks ahead' for values it hasn't computed yet. The non-lazy version I wrote to test correctness was: (defn chain-length [num] (loop [len 1 n num] (cond (= n 1) len (odd? n) (recur (inc len) (+ 1 (* 3 n))) true (recur (inc len) (/ n 2))))) Which works, but is really slow. Of course I could memoize that: (def memoized-chain (memoize (fn [n] (cond (= n 1) 1 (odd? n) (+ 1 (memoized-chain (+ 1 (* 3 n)))) true (+ 1 (memoized-chain (/ n 2))))))) However, what I really wanted to do was scratch my itch for understanding the limits of lazy sequences, and write a function like this: (def lazy-chain (letfn [(chain [n] (lazy-seq (cons (if (odd? n) (+ 1 (nth lazy-chain (dec (+ 1 (* 3 n))))) (+ 1 (nth lazy-chain (dec (/ n 2))))) (chain (+ n 1)))))] (chain 1))) Pulling elements from this will cause a stack overflow for n2, which is understandable if you think about why it needs to look 'into the future' at n=3 to know the value of the tenth element in the lazy list because (+ 1 (* 3 n)) = 10. Since lazy lists have much less overhead than memoization, I would like to know if this kind of thing is possible somehow via even more delayed evaluation or queuing?

    Read the article

  • load-views when running multiple noir servers

    - by Roth Michaels
    I'm experimenting with using noir to start three servers (each to handle a different aspect of the application). I am trying to do this so that I can run all three servers within one application while developing and easily decouple the project into three different applications for deployment. It is no problem to use noir.server/start and noir.server/stop to run the jetty servers I need. What I'm trying to figure out is some way to call load-views (or something like that) with a different set views for each server so that URI conflicts are handled by the correct defpage.

    Read the article

  • Mapping over sequence with a constant

    - by Hendekagon
    If I need to provide a constant value to a function which I am mapping to the items of a sequence, is there a better way than what I'm doing at present: (map my-function my-sequence (cycle [my-constant-value])) where my-constant-value is a constant in the sense that it's going to be the same for the mappings over my-sequence, although it may be itself a result of some function further out. I get the feeling that later I'll look at what I'm asking here and think it's a silly question because if I structured my code differently it wouldn't be a problem, but well there it is!

    Read the article

  • Managing log4j.properties with lein

    - by erikcw
    I'm trying to figure out how I can manage my log4j.properties file with leiningen. I'd like to be able to automatically include the file in the jars that lein creates as well as have the properties file be accessible to "lein swank" (and lein repl). Right now I have the file in my project "root", but I get this error when I using logging from swank [null] log4j:WARN No appenders could be found for logger (com.dev). [null] log4j:WARN Please initialize the log4j system properly. Thanks!

    Read the article

  • is this a simple monad example?

    - by zcaudate
    This is my attempt to grok monadic functions after watching http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-Dont-fear-the-Monads. h uses bind to compose together two arbitrary functions f and g. What is the unit operator in this case? ;; f :: int - [str] ;; g :: str = [keyword] ;; bind :: [str] - (str - [keyword]) - [keyword] ;; h :: int - [keyword] (defn f [v] (map str (range v))) (defn g [s] (map keyword (repeat 4 s))) (defn bind [l f] (flatten (map f l))) (f 8) ;; = (0 1 2 3 4 5 6 7) (g "s") ;; = (:s :s :s :s) (defn h [v] (bind (f v) g)) (h 9) ;; = (:0 :0 :0 :0 :1 :1 :1 :1 :2 :2 :2 :2 :3 :3 :3 :3 :4 :4 :4 :4 :5 :5 :5 :5)

    Read the article

  • why can't I call .update on a MessageDigest instance

    - by Arthur Ulfeldt
    when i run this from the repl: (def md (MessageDigest/getInstance "SHA-1")) (. md update (into-array [(byte 1) (byte 2) (byte 3)])) I get: No matching method found: update for class java.security.MessageDigest$Delegate the Java 6 docs for MessageDigest show: update(byte[] input) Updates the digest using the specified array of bytes. and the class of (class (into-array [(byte 1) (byte 2) (byte 3)])) is [Ljava.lang.Byte; Am I missing something in the definition of update? Not creating the class I think I am? Not passing it the type I think I am?

    Read the article

  • Updating an atom with a single value

    - by mikera
    I have a number of atoms in my code where a common requirement is to update them to a new value, regardless of the current value. I therefore find myself writing something like this: (swap! atom-name (fn [_] (identity new-value))) This works but seems pretty ugly and presumably incurs a performance penalty for constructing the anonymous closure. Is there a better way?

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15  | Next Page >