Re: getting started with clojure

2010-10-21 Thread Meikel Brandmeyer
Hi,

On 21 Okt., 00:04, Eric Lavigne lavigne.e...@gmail.com wrote:

 I hope you are enjoying Clojure. Don't let all of this talk about
 compiling distract you from the fun part: writing code.

Especially since compilation is not necessarily necessary and in most
of the cases even counter-productive. Unless you use gen-class, you
shouldn't worry about compilation at all.

Sincerely
Meikel

-- 
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


Trying to Load An Alias from Another Namespace into The Current Namespace

2010-10-21 Thread Stefan Rohlfing
Dear Clojure group,

The library clj-record requires to add a source file for every table
in a given database.

This can lead to a lot of files whose namespaces have to be imported
wherever you want to work on the tables.

In order to avoid having to write the whole namespace declaration
every time, I decided put it into a file on its own and load this
namespace via (ns :use...).

The problem is I also have to be able to use an alias with each of the
table files like this:

Table file 1: src/active-record/user.clj

---

Table file 2: src/active-record/charge.clj

---

File to hold load and alias the namespaces of the table files:
src/active-record/tns.clj

 (ns active-record.tns
   (:require [active-record.user :as user])
   (:require [active-record.charge :as charge]))

---

Clojure core file: src/active-record/program/core.clj

(ns active-record.program.core
  (:use active-record.tns))

;; Evaluation returns nil


(user/create
 {:login my-login
   :first_name Jonas
   :last_name Rohl
   :password secret
   :email_address jo...@example.com})

;; Evaluation throws an exception:
;; No such var: user/create
;;  [Thrown class java.lang.Exception]


(charge/create
 {:user_id 10,
  :amount_dollars 244
  :amount_cents 91
  :category meals
  :vendor_name Metro
  :date 2010-01-15})

;; Evaluation throws an exception:
;; No such namespace: charge
;;  [Thrown class java.lang.Exception]

---


I restarted Emacs and tried again but got the same error messages.

Maybe I messed up the namespace declarations again but it could also
be that referring to an alias that was created in another namespace
might not be possible.

Does anybody know which one is the case?

Stefan

-- 
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


meta bytecode redundancy?

2010-10-21 Thread Arthur Edelstein
Hi Everyone,

I have a question about an apparent redundancy in clojure's generated
class files. Out of curiosity I was inspecting the core class files
using the Java Decompiler JD-GUI. For example, here is the decompiled
version of core$dec.class (the implementation of the dec function):

package clojure;

import clojure.lang.AFunction;
import clojure.lang.IObj;
import clojure.lang.IPersistentMap;
import clojure.lang.Numbers;

public final class core$dec extends AFunction
{
  final IPersistentMap __meta;

  public core$dec(IPersistentMap paramIPersistentMap)
  {
this.__meta = paramIPersistentMap; }
  public core$dec() { this(null); }
  public IPersistentMap meta() { return this.__meta; }
  public IObj withMeta(IPersistentMap paramIPersistentMap) { return
new dec(paramIPersistentMap); }
  public Object invoke(Object x) throws Exception { x = null; return
Numbers.dec(x);
  }
}

I noticed that every class file, corresponding to a function in the
core, contains many of these same lines for implementing metadata
storage, namely:

import clojure.lang.IObj;
import clojure.lang.IPersistentMap;

  final IPersistentMap __meta;
  public core$FUNCTIONNAME(IPersistentMap paramIPersistentMap)
  {
this.__meta = paramIPersistentMap; }
  public core$FUNCTIONNAME() { this(null); }
  public IPersistentMap meta() { return this.__meta; }
  public IObj withMeta(IPersistentMap paramIPersistentMap) { return
new FUNCTIONNAME(paramIPersistentMap); }

It seems to me that this metadata storage functionality could be
absorbed into the relevant abstract class(es), perhaps AFn.

Could this change increase performance and cut down on the size of the
bytecode?

Best regards,
Arthur

-- 
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


First function

2010-10-21 Thread Brody Berg
Hey,

Not sure if this is the right place for this - but I just wrote my
first function in Clojure and wanted to make sure I am on the right
track idiomatically and making full use of the language etc. I have
been able to build/run and unit test this so that's all fine. Take a
look at the below and let me know if you have any suggestions.

Thanks in advance!

Brody

(defn binary-search
Search sorted list for target using binary search technique
([m_list target]
(if (empty? m_list)
false
(binary-search m_list 0 (- (count m_list) 1) target))
)
([m_list m_left m_right target]
(let [gap (- m_right m_left)]
(if (= 0 gap)
(if (== (nth m_list m_left) target)
(nth m_list m_left)
false
)
(let [middle (+ m_left (quot gap 2))]
(if (== (nth m_list middle) target)
(nth m_list middle)
(if ( target (nth m_list middle))
(recur m_list m_left (- middle 1) target)
(recur m_list (+ middle 1) m_right target)
)
)
)
)
)
)
)

-- 
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: First function

2010-10-21 Thread Michael Gardner
On Oct 21, 2010, at 3:28 AM, Brody Berg wrote:

(if (empty? m_list)
false
(binary-search m_list 0 (- (count m_list) 1) target))

Assuming that returning nil is OK in case of the target not being present, you 
can replace this with (when (seq m_list) (binary-search ...)).

(if (== (nth m_list m_left) target)
(nth m_list m_left)
false

Can similarly replace with (when (== (nth m_list m_left) target) target). But 
why are you returning the target value on success? Presumably the caller knows 
what that value is, and it makes your function awkward to use if target is 
false or nil. Why not return either the target's index, or just 'true' if you 
don't need that?

Also, can you assume m_list is a vector, or if not, make it into one in your 
helper body? That would let you write (m-list n) instead of (nth m-list n), and 
would guarantee constant-time performance when you do it.

 (- middle 1)
 (+ middle 1)

Can replace with (dec middle) and (inc middle), respectively.

Lastly, as a matter of style: Lisp users generally hate trailing parentheses. 
It's extremely common to simply collapse them onto the previous line. Your 
editor should be able to do the grunt-work of helping you balance them, and 
they pretty much disappear after a while.

-- 
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: First function

2010-10-21 Thread Michael Gardner
On Oct 21, 2010, at 3:28 AM, Brody Berg wrote:

(if (== (nth m_list m_left) target)

Forgot to mention: you should use = instead of == unless you're sure you will 
only ever get numeric arguments *and* profiling tells you that = is a 
performance bottleneck.

-- 
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: Trying to Load An Alias from Another Namespace into The Current Namespace

2010-10-21 Thread Meikel Brandmeyer
Hi,

you can't transfer aliases from one namespace to another. But as a
workaround, you can create a file which contains the necessary
commands:

active-record/tables.clj:
(require '[active-record.user :as user])
(require '[active-record.charge :as charge])

And then just load the file in the namespaces you want to use the
tables.

(ns active-record.program.core
  (:load tables))
...
---
(ns active-record.program.different-namespace
  (:load tables))
...

(You might have to use active-record/tables. Haven't used load in a
while. But without .clj extension!)

Sincerely
Meikel

-- 
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: Improving Contrib

2010-10-21 Thread Stuart Halloway
As the start of this thread mentioned, we are moving to a new infrastructure 
around Confluence and JIRA, which should be (1) easier to use and in and of 
itself, and (2) allow a chance to improve documentation and streamline every 
aspect of contributing to Clojure. I am hoping we can roll onto JIRA as soon as 
next week.

I am excited by this thread and hope that the energy being shown here will 
translate into specific efforts to improve the colaboration process for 
everyone.

Stu

 On Wed, 20 Oct 2010 09:59:26 -0600
 Eric Schulte schulte.e...@gmail.com wrote:
 
 Mike Meyer mwm-keyword-googlegroups.620...@mired.org writes:
 
 It was also more work than submitting patches looks to be for apache,
 django, gnu
 
 FWIW in gnu projects if your patch is 10 lines long then they do
 require you to go through a fairly lengthy attribution process.
 
 http://www.gnu.org/prep/maintain/html_node/Copyright-Papers.html
 
 Two things. First, the limit is around 15 lines of code, excluding
 repeated changes, and it applies over all patches, not just one:
 http://www.gnu.org/prep/maintain/html_node/Legally-Significant.html
 
 More importantly, this doesn't happen until *after* the patch has been
 submitted and a contributor decides it should be included. Putting
 roadblocks in front of people who want to submit patches or bugs - and
 not being able to update the bug database qualifies, since you can't
 report on the results of suggested fixes or at the very least add
 another case to the existing ticket without a developer having to
 notice the duplicate and flag it - is a bad idea.
 
 Again, maybe it's possible to submit bugs to assembla without the CA;
 but finding the assembla tickets list itself requires wading past the
 verbiage about the CA. If bug reports (with or without patches)
 doesn't require a CA, then it should be a lot easier to find.
 
   mike
 -- 
 Mike Meyer m...@mired.org   http://www.mired.org/consulting.html
 Independent Network/Unix/Perforce consultant, email for more information.
 
 O ascii ribbon campaign - stop html mail - www.asciiribbon.org
 
 -- 
 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

-- 
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: Sandbar Dependencies Problem

2010-10-21 Thread nickikt
I can find  [sandbar.core 0.3.1], [sandbar/sandbar-session 0.2.5]
and other on clojars. I would rather work with the new versions (not
start a poject with outdated dependencies). Witch of the jars do I
need to do something like your defform example in the new version?

On Oct 21, 2:23 am, Brenton bashw...@gmail.com wrote:
 Nickikt ,

 All of the stuff covered in that blog post is in Sandbar 0.3.0-
 SNAPSHOT. You will need to add [sandbar 0.3.0-SNAPSHOT] as a
 dependency.

 There are also lots of working examples in the project on GitHub.

 http://github.com/brentonashworth/sandbar/tree/master/src/sandbar/exa...

 Specifically, here is one for creating forms with defform:

 http://github.com/brentonashworth/sandbar/blob/master/src/sandbar/exa...

 Hope this helps,

 Brenton

 On Oct 20, 3:38 pm, nickikt nick...@gmail.com wrote:

  I want to make a little Webstuff with Clojure. Wanted to use Sandbar
  formes and looked at the 
  blogposthttp://formpluslogic.blogspot.com/2010/09/taming-html-forms-with-cloj

  There is kind of a mismatch between blog, implementation and
  documentation.

  For the Blogpost i need something like this.

  (ns TimeParser.core
    (:use [compojure.core :only [defroutes GET]]
              [sandbar.core]
              [sandbar.stateful-session :only [wrap-stateful-session
                                                                   set-
  flash-value!]]
          [sandbar.validation :only [build-validator
                                                   non-empty-string
                                                   add-validation-
  error]])
    (:require [compojure.route :as route]
                   [appengine-magic.core :as ae]
                   [sandbar.forms :as forms]))

  Here is my project.clj:

  (defproject TimeParser 1.0.0 Snapshot
    :description A simple website that parses a SAP file
    :dependencies [[org.clojure/clojure 1.2.0]
                               [org.clojure/clojure-contrib 1.2.0]
                               [compojure 0.5.2]
                               [hiccup 0.2.6]
                               [sandbar/sandbar-core 0.3.1]
                               [sandbar/sandbar-session 0.2.5]] ;(i
  didn't find anymore sandbar stuff on clojars)
    :dev-dependencies [[appengine-magic 0.2.0]
                                       [swank-clojure 1.2.1]
                                       [clj-stacktrace 0.2.0]])

  Does somebody know how the project.clj needs to look like (or if I
  need to change the ns stuff)

  Thx Nickikt

-- 
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: First function

2010-10-21 Thread songoku
You should close the parenthesis all in one line:

(defn binary-search
Search sorted list for target using binary search technique
([m_list target]
(if (empty? m_list)
false
(binary-search m_list 0 (- (count m_list) 1) target)))
([m_list m_left m_right target]
(let [gap (- m_right m_left)]
(if (= 0 gap)
(if (== (nth m_list m_left) target)
(nth m_list m_left)
false)
(let [middle (+ m_left (quot gap 2))]
(if (== (nth m_list middle) target)
(nth m_list middle)
(if ( target (nth m_list middle))
(recur m_list m_left (- middle 1) target)
(recur m_list (+ middle 1) m_right
target

It safes some space ;)

-- 
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


Leiningen 1.3 question

2010-10-21 Thread hsarvell
I'm trying to compile my project with Leiningen 1.3.1, the compile
fails but that is another story. My main problem right now is that the
lib folder disappears. I'd like to be able to do lein jar (or try)
without it disappearing.

My project.clj looks like this:

(defproject project 0.1
:description project description
:javac-fork true
:repositories [[clojars http://clojars.org/repo;]]
:dependencies [[org.clojure/clojure 1.1.0]
 [org.clojure/clojure-contrib 1.1.0]
 [ring/ring-core 0.2.0]
 [ring/ring-jetty-adapter 0.2.0]
 [compojure 0.4.0-SNAPSHOT]
 [hiccup 0.2.5]
 [clojure-http-client 1.0.0]
 [sandbar/sandbar 0.2.3]]
:dev-dependencies [[ring/ring-devel 0.2.0]]
:namespaces [project.index])

-- 
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: Transient maps do not work?

2010-10-21 Thread Jürgen Hötzel
2010/10/21 andrei andrei.zhabin...@gmail.com:

 (defn test []
  (let [transient-map (transient {})]
      (doseq [i (range 100)]
          (conj! transient-map {i (str i)} ))
      (persistent! transient-map)))

 I expect that it will produce:

 { 0 0, 1 1, 2 2, ..., 99 99}

 but it gives only

 {0 0, 1 1, ..., 7 7}

 i.e. only first 8 elements.
 Is it a bug or I do something wrong?


See: http://clojure.org/transients

...Note in particular that transients are not designed to be bashed
in-place. You must capture and use the return value in the next call.

Also consider using assoc! and recursion:

(defn test []
  (loop [transient-map (transient {})
 i 0]
(if ( i 100)
  (recur (assoc! transient-map i (str i)) (inc i))
  (persistent! transient-map

Jürgen

-- 
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: Transient maps do not work?

2010-10-21 Thread andrei
Oh, I didn't understand this line before. Now I see my error, thank
you.

On Oct 21, 6:27 pm, Jürgen Hötzel juer...@hoetzel.info wrote:
 2010/10/21 andrei andrei.zhabin...@gmail.com:





  (defn test []
   (let [transient-map (transient {})]
       (doseq [i (range 100)]
           (conj! transient-map {i (str i)} ))
       (persistent! transient-map)))

  I expect that it will produce:

  { 0 0, 1 1, 2 2, ..., 99 99}

  but it gives only

  {0 0, 1 1, ..., 7 7}

  i.e. only first 8 elements.
  Is it a bug or I do something wrong?

 See:http://clojure.org/transients

 ...Note in particular that transients are not designed to be bashed
 in-place. You must capture and use the return value in the next call.

 Also consider using assoc! and recursion:

 (defn test []
   (loop [transient-map (transient {})
          i 0]
     (if ( i 100)
       (recur (assoc! transient-map i (str i)) (inc i))
       (persistent! transient-map

 Jürgen

-- 
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: Leiningen 1.3 question

2010-10-21 Thread Brendan Ribera
'lein deps' deletes the lib directiory whenever it runs, and this is the
expected behavior. 'lein jar' runs deps first, so that's why lib is
disappearing. This shouldn't be a problem if all of your dependencies are
specified in project.clj; deps should just repopulate a fresh lib directory.
If you have dependencies not listed in project.clj, the README FAQ section
entitled What if my project depends on jars that aren't in any repository?
will be of interest to you.

Feel free to post on leinin...@googlegroups.com if you still need some help.
*
*
On Thu, Oct 21, 2010 at 7:46 AM, hsarvell hsarv...@gmail.com wrote:

 I'm trying to compile my project with Leiningen 1.3.1, the compile
 fails but that is another story. My main problem right now is that the
 lib folder disappears. I'd like to be able to do lein jar (or try)
 without it disappearing.

 My project.clj looks like this:

 (defproject project 0.1
:description project description
:javac-fork true
:repositories [[clojars http://clojars.org/repo;]]
:dependencies [[org.clojure/clojure 1.1.0]
 [org.clojure/clojure-contrib 1.1.0]
 [ring/ring-core 0.2.0]
 [ring/ring-jetty-adapter 0.2.0]
 [compojure 0.4.0-SNAPSHOT]
 [hiccup 0.2.5]
 [clojure-http-client 1.0.0]
 [sandbar/sandbar 0.2.3]]
:dev-dependencies [[ring/ring-devel 0.2.0]]
:namespaces [project.index])

 --
 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.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
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: First function

2010-10-21 Thread Alan
To expand on this:

1. It's better to use when (or when-not) if one branch of your if is
just a false value. E.g. you could replace (if (empty? x) false
(whatever)) with (when-not (empty? x)). However...

2. Don't use empty? if you can help it! The idiomatic way to test
whether a collection has any items in it is to use (seq coll), which
returns nil if coll is empty, or a seq of the collection otherwise. So
then your if reduces to the very common (when (seq x) (whatever))

3. Lisp paren style is very different from C-like brace style. There
are a few rebels out there who do things differently, and if you're
the only one using the code, feel free. However, you'll get better at
reading and writing Lisp code if you let the indentation be your
guide. Parentheses are just there for the compiler; indentation is so
*you* know what's going on. There should never (I'm sure someone can
think of an exception) be whitespace of any kind immediately preceding
a closing bracket. Songoku's sample uses them in the traditional
style.

4. The usual indentation is two spaces, not four.

5. This last one you might already know, but it's hard to tell because
you used indents of four. Typically you indent flow control sorts of
statements with the standard indent, like:

(when (seq x)
  (whatever))

But other sorts of multi-form constructs you usually line the
arguments up with each other: this helps a lot with tip (3), because
it means you don't need the parens to see what's up. Like so (don't
worry about what the functions do, it's just an indentation example):

(map #(+ %2 (/ 2 %1))
 (filter even?
 (range 4 99))
 (drop-while #( 1000)
 (range)))

This way you can tell at a glance what forms fit where, even in my
nonsensical example where it's not clear what the overall purpose is.

On Oct 21, 4:12 am, Michael Gardner gardne...@gmail.com wrote:
 On Oct 21, 2010, at 3:28 AM, Brody Berg wrote:

         (if (empty? m_list)
             false
             (binary-search m_list 0 (- (count m_list) 1) target))

 Assuming that returning nil is OK in case of the target not being present, 
 you can replace this with (when (seq m_list) (binary-search ...)).

                 (if (== (nth m_list m_left) target)
                     (nth m_list m_left)
                     false

 Can similarly replace with (when (== (nth m_list m_left) target) target). But 
 why are you returning the target value on success? Presumably the caller 
 knows what that value is, and it makes your function awkward to use if target 
 is false or nil. Why not return either the target's index, or just 'true' if 
 you don't need that?

 Also, can you assume m_list is a vector, or if not, make it into one in your 
 helper body? That would let you write (m-list n) instead of (nth m-list n), 
 and would guarantee constant-time performance when you do it.

  (- middle 1)
  (+ middle 1)

 Can replace with (dec middle) and (inc middle), respectively.

 Lastly, as a matter of style: Lisp users generally hate trailing parentheses. 
 It's extremely common to simply collapse them onto the previous line. Your 
 editor should be able to do the grunt-work of helping you balance them, and 
 they pretty much disappear after a while.

-- 
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: Need some help with static files and ring...

2010-10-21 Thread Luc
Hi,

I do have the web-content key. I had to postpone work on this issue
(I'm waiting for my flight
right now to get the ClojureConj). They were too many items in the
checklist before I could leave..

I'll resume on this either while in Raleigh or upon my return. Right
now I feel a bit stunned by the
meal I ate at the airport... A bit of sleep on the plane will fix this
however.

I really have to straightened up routes somehow. The differences
between using jetty and a tomcat
deployment are not yet carved in my brains... a bit more work on this
issue should fix this.

See you at the Conj maybe.

Luc P.

On Oct 18, 3:20 pm, David Jagoe davidja...@gmail.com wrote:
 Hey Luc,

 Are you deploying to Tomcat using a war file? Are you perhaps missing
 the :web-content key in your project.clj file (I presume you're using
 Leiningen + leiningen-war)

 (defproject myproject 0.0.1
   :description 
   :dependencies [[org.clojure/clojure 1.2.0]
                           ... ]
   :dev-dependencies [...
                      [uk.org.alienscience/leiningen-war 0.0.8]]
   ;; Used by leiningen-war to deploy static resources
   :web-content public
   :aot [myproject.servlet])

 In your case public would be stylesheets.

 Is this the approach you're taking? Ultimately it is probably a best
 to let nginx or apache serve up static files (rather than tomcat/ring)
 but at the moment I am actually just serving up static content
 directly from Tomcat which works fine. I have one servlet handling the
 application and a default servlet on the same Tomcat instance serving
 up the static files. So I only use the file middleware in development:

            (wrap-if development? wrap-file public)
            (wrap-if development? wrap-file-info)

 Not sure if that addresses your problem?

 Cheers,
 David

 On 18 October 2010 20:06,  lprefonta...@softaddicts.ca wrote:

  Hi everyone,

  I have been banging my head on the walls for a few hours now and really 
  cannot
  figure out the proper way to serve static files in a Compojure application
  deployed on Tomcat or Glassfish...

  Feeling pretty dumb in fact...

  I tried to configure the default servlet to catch up requests but I feel
  that I cannot escape the Ring routes so this never worked.

  The static files reside in the folder stylesheets at the very top of the
  application folder. The application path is IDEMDossierPatient.

  The HTML link references stylesheets/...

  I get the following stack trace:

  SEVERE: Allocate exception for servlet IDEMDossierPatient
  java.lang.Exception: Directory does not exist: stylesheets
     at ring.middleware.file$ensure_dir.invoke(file.clj:13)
     at ring.middleware.file$wrap_file.doInvoke(file.clj:23)
     at clojure.lang.RestFn.invoke(RestFn.java:426)
     at ring.middleware.static$wrap_static.invoke(static.clj:13)
     at 
  idem.mr.clinic.webaccess.medicalrecord$eval1206.invoke(medicalrecord.clj:52)
  ...

  The routes are the following (after several attempts with the file wrapper):

  (defroutes app-routes
    (GET /patient [patient-id]
      (render-page Dossier médical) (render-page (load-patient-mr 
  patient-id)))
   (GET /req req (str req))
   (GET /file [] (doto (java.io.File. .) (.getAbsolutePath)))
   (GET / [] (render-page Saisie du # de patient patient-form))
   (route/not-found Page inconnue)
  )

  (wrap! app-routes :stacktrace)
  (wrap! app-routes (:static stylesheets [stylesheets]))

  Any ideas where I am going with this aside from a dead end ?
  Is there another way to specify the folder for static file ?
  Should I specify an absolute path (ugly but given where I am right
  now I would not care...) ?
  Should I move the folder elsewhere ?

  Blblblblblblbl...

  Thank you,

  Luc

  --
  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

-- 
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: First function

2010-10-21 Thread Jürgen Hötzel
2010/10/21 Brody Berg brodyb...@gmail.com:
 (defn binary-search
    Search sorted list for target using binary search technique

Binary search is only useful on indexed data types like Clojure Vectors.

    ([m_list target]
        (if (empty? m_list)
            false
            (binary-search m_list 0 (- (count m_list) 1) target))
        )
    ([m_list m_left m_right target]

Because  Vectors are persistent you can create Sub-Vectors instead of
keeping tracking offsets.

        (let [gap (- m_right m_left)]
            (if (= 0 gap)
                (if (== (nth m_list m_left) target)
                    (nth m_list m_left)
                    false

No need for explicit false.

Using case/compare you can also replace multiple tests by a single
comparison and constant time lookup:

(defn binary-search [v x]
  (if (seq v)
(let [half (quot (count v) 2)
  middle (v half)]
  (case (compare middle x)
-1 (recur (subvec v (inc half)) x)
1 (recur (subvec v 0 half) x)
true

Jürgen

-- 
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


*assert* and assert

2010-10-21 Thread Shantanu Kumar
When I runs this using Clojure 1.2.0:

(binding [*assert* false] (assert false))

I get

java.lang.AssertionError: Assert failed: false

Can somebody please help me understand how to use *assert* for
conditional assertions?

Regards,
Shantanu

-- 
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: *assert* and assert

2010-10-21 Thread Meikel Brandmeyer
Hi,

On 22 Okt., 07:48, Shantanu Kumar kumar.shant...@gmail.com wrote:

 When I runs this using Clojure 1.2.0:

 (binding [*assert* false] (assert false))

 I get

 java.lang.AssertionError: Assert failed: false

 Can somebody please help me understand how to use *assert* for
 conditional assertions?

The assert above will be expanded when the binding form is compiled.
Since *assert* during expansion time it cannot see the binding. Put
the assert in a file and try something like (binding [*assert* false]
(load-file the-file.clj)). Then you should see the desired
behaviour.

Sincerely
Meikel

-- 
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