Re: Can Simple be done with Static Typing?

2011-10-24 Thread ngocdaothanh
More about Scala:
http://www.slideshare.net/El_Picador/scala-vs-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
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: aquamacs, slime and clojure on OS X

2011-09-25 Thread ngocdaothanh
Coming from Eclipse, I can't live without the file browser.
I'm having this problem with ECB, please help:
http://stackoverflow.com/questions/7541693/ecb-context-menu-in-aquamacs

Thanks,
Ngoc

-- 
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: How often do you use REPL?

2010-09-27 Thread ngocdaothanh
cake (http://github.com/ninjudd/cake) has the "tab completion"
feature.

Because this is very useful, I wonder if this feature should be added
to leiningen or Clojure itself.

-- 
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: Feature idea: meta-macros

2010-09-15 Thread ngocdaothanh
> consider using or writing a preprocessor like m4

Could you elaborate on that?

-- 
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: Docstrings in Clojure?

2010-08-19 Thread ngocdaothanh
> (defn foo
>    "..."
>    ([a] ...)
>    ([a b] ...))

Is there any way to add docstring for each case? (One for summary, one
for [a], and one for [a b].)

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


FSM

2010-08-15 Thread ngocdaothanh
I have used Erlang's gen_fsm and like it very much:
http://erlang.org/doc/design_principles/fsm.html

I want to write a game in Clojure and I need a FSM library (best if it
supports timeout event). I would like to ask if there is any Java (or
Clojure?) FSM library that works well with 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


Re: chinese character in hiccup

2010-08-13 Thread ngocdaothanh
> Perhaps Jetty add a charset of iso-8859-1 if there isn't one in response

I think this behavior is specified in the servlet spec: "If no charset
is specified, ISO-8859-1 will be used"
http://download.oracle.com/docs/cd/E17802_01/products/products/servlet/2.5/docs/servlet-2_5-mr2/javax/servlet/ServletResponse.html

-- 
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: why the def of run-jetty looks like "defn #^Server run-jetty"

2010-08-10 Thread ngocdaothanh
> The main usage (at least for me) is avoiding reflection in the context
> of direct call to a Java method.
>
> if you write:
> (defn foo [x]
>   (.clone x))

Thank you for the insightful explanation.

-- 
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: looking for a simpler implementation of a function I'm using

2010-08-10 Thread ngocdaothanh
> What I'm looking for is a natural, conceptually clean approach.

Erlang programmers do version 2 all the time and it can be call
"Erlang-style". You should be confident with version 2.

Version 2 is cleaner if you write the inner loop as a separate
function.

-- 
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: Today is "Get Your App on Clojure 1.2" Day

2010-07-30 Thread ngocdaothanh
My project.clj:

(defproject maho "0.1-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.2.0-RC1"]
 [org.clojure/clojure-contrib "1.2.0-RC1"]
 [ring"0.2.5"]
 [clout   "0.2.0"]

 [clj-record "1.0-SNAPSHOT"]
 [c3p0   "0.9.1"]
 [postgresql "8.4-701.jdbc4"]])

Running with (set! *warn-on-reflection* true) gives the below warning.
Would Clojure be improved to remove the warnings?

Thanks.

Reflection warning, clojure/contrib/str_utils.clj:46 - call to
subSequence can't be resolved.
Reflection warning, clojure/contrib/str_utils.clj:49 - reference to
field length can't be resolved.
Reflection warning, clojure/contrib/str_utils.clj:50 - reference to
field length can't be resolved.
Reflection warning, clojure/contrib/str_utils.clj:50 - call to
subSequence can't be resolved.
Reflection warning, clojure/contrib/java_utils.clj:209 - call to
getDeclaredMethod can't be resolved.
Reflection warning, clojure/contrib/java_utils.clj:210 - call to
setAccessible can't be resolved.
Reflection warning, clojure/contrib/java_utils.clj:211 - call to
invoke can't be resolved.
Reflection warning, clojure/contrib/java_utils.clj:217 - call to
getDeclaredField can't be resolved.
Reflection warning, clojure/contrib/java_utils.clj:218 - call to
setAccessible can't be resolved.
Reflection warning, clojure/contrib/java_utils.clj:219 - call to get
can't be resolved.
Reflection warning, clojure/contrib/except.clj:90 - reference to field
getClassName can't be resolved.
Reflection warning, clojure/contrib/except.clj:90 - call to startsWith
can't be resolved.
Reflection warning, clojure/contrib/except.clj:91 - reference to field
getStackTrace can't be resolved.
Reflection warning, clojure/contrib/except.clj:94 - call to
setStackTrace can't be resolved.
Reflection warning, ring/util/response.clj:42 - reference to field
isDirectory can't be resolved.
Reflection warning, ring/util/response.clj:44 - reference to field
exists can't be resolved.
Reflection warning, ring/middleware/file.clj:24 - call to substring
can't be resolved.
Reflection warning, ring/middleware/file_info.clj:87 - call to parse
can't be resolved.
Reflection warning, ring/middleware/file_info.clj:108 - call to format
can't be resolved.
Reflection warning, clout/core.clj:36 - call to group can't be
resolved.
Reflection warning, clout/core.clj:36 - call to group can't be
resolved.
Reflection warning, clout/core.clj:35 - reference to field groupCount
can't be resolved.
Reflection warning, clout/core.clj:48 - call to substring can't be
resolved.
Reflection warning, clout/core.clj:91 - call to group can't be
resolved.
Reflection warning, clout/core.clj:101 - reference to field group
can't be resolved.
Reflection warning, clojure/contrib/io.clj:336 - call to write can't
be resolved.
Reflection warning, clojure/contrib/io.clj:343 - call to write can't
be resolved.
Reflection warning, clojure/contrib/seq.clj:156 - call to
java.util.ArrayList ctor can't be resolved.
Reflection warning, clojure/contrib/seq.clj:198 - call to
java.util.concurrent.LinkedBlockingQueue ctor can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:87 - call to
getConnection can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:89 - reference to
field getConnection can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:91 - call to
java.util.Hashtable ctor can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:93 - call to
lookup can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:94 - reference to
field getConnection can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:102 - reference
to field close can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:117 - reference
to field getMessage can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:118 - reference
to field getSQLState can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:119 - reference
to field getErrorCode can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:110 - call to
println can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:127 - reference
to field getNextException can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:132 - call to
println can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:133 - reference
to field getUpdateCounts can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:134 - call to
println can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:134 - call to
println can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:142 - reference
to field getMessage can't be resolved.
Reflection warning, clojure/contrib/sql/internal.clj:156 - reference
to field getAutoCommit can't be resolved.
Reflection war

Re: Clojure 1.2 RC1

2010-07-30 Thread ngocdaothanh
>          :dependencies [[org.clojure/clojure "1.2.0-RC"]

[org.clojure/clojure "1.2.0-RC"]  did not work for me. Changing to
[org.clojure/clojure "1.2.0-RC1"] works.

-- 
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: Log SQL in clojure.contrib.sql

2010-07-28 Thread ngocdaothanh
I found:
http://code.google.com/p/log4jdbc/


On Jul 27, 11:31 pm, ngocdaothanh  wrote:
> Hi,
>
> I would like to ask if there is a way to log SQL generated by
> clojure.contrib.sql to console for inspection.
>
> 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


Log SQL in clojure.contrib.sql

2010-07-27 Thread ngocdaothanh
Hi,

I would like to ask if there is a way to log SQL generated by
clojure.contrib.sql to console for inspection.

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: Clojure 1.2 Beta 1

2010-07-14 Thread ngocdaothanh
Report:
There is still "call to contains can't be resolved" for defrecord.
After googling for this message, I see that it has been discussed (and
can be easily fixed?).

-- 
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 DSL for writing scripts which have restricted memory and cpu usage

2010-07-12 Thread ngocdaothanh
> Are there any ways to restrict how many resources a user has access to?

If you use Linux, you see /etc/security/limits.conf.

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

2010-07-12 Thread ngocdaothanh
This is not Clojure:
http://github.com/rvirding/lfe

> Are there any works or current attempts currently available?

-- 
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: Recent builds have failed on http://build.clojure.org

2010-07-10 Thread ngocdaothanh
I think it is because the last commit of the master branch is on June
24, 2010:
http://github.com/richhickey/clojure/commits/master


On Jul 10, 12:24 pm, Dmitry Kakurin  wrote:
> The last successful build was on June 23rd.
>
> - Dmitry

-- 
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: ANN: Aleph, an asynchronous web server

2010-07-07 Thread ngocdaothanh
> For some reason I couldn't get 3.2.1.Final to come in via maven.

I think you need to add this to project.clj:
:repositories [["jboss" "http://repository.jboss.org/nexus/content/
groups/public/"]]

> What qualities is it missing that make the bang misleading?

I thinks ! means something dangerous is about to happen.

-- 
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: ANN: Aleph, an asynchronous web server

2010-07-07 Thread ngocdaothanh
> [org.jboss.netty/netty "3.2.0.BETA1"]

Netty 3.2.1.Final has been released.

I think the ! mark in "respond!" is kind of misleading. Why not change
it to "arespond"?

-- 
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: Unicode string length bug?

2010-07-03 Thread ngocdaothanh
Adding Dfile.encoding=UTF-8 solves the problem:
java -Dfile.encoding=UTF-8 -cp clojure-1.2.0-
master-20100623.220259-87.jar clojure.main

I think it is because when Java reads the input, it does not know the
correct encoding.

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


Link to API document in the cheat sheet

2010-07-03 Thread ngocdaothanh
Hi,

This is my nth attempt to learn Clojure.

I think it will be an improvement if there are links to API document
for functions in the cheat sheet (http://clojure.org/cheatsheet).
Clicking a function name will jump right to the description for the
function is very convenient for newbies.

-- 
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: Unicode string length bug?

2010-07-01 Thread ngocdaothanh
I'm on Snow Leopard. I think there's something wrong with Terminal

-
$ java -cp clojure-1.2.0-master-20100623.220259-87.jar clojure.main
Clojure 1.2.0-master-SNAPSHOT
user=> (def t "車馬象士將士象馬車")
#'user/t
user=> t
"車馬象士將士象馬車"
user=> (count t)
27
user=> (.length t)
27
-

But if I save to a file and run that file, then the result is correct.


On Jul 2, 1:59 am, Stuart Halloway  wrote:
> I see 9 on 1.2 as well. The call to .length is a Java interop form, so it is 
> very difficult to imagine how this might change.
>
> Stu
>
>
>
> > With 1.2-master-SNAPSHOT:
>
> > (def t "車馬象士將士象馬車")
> > (count t)  ; => 27
> > (.length t)  ; => 27
>
> > With 1.1, the result is 9.
>
> > --
> > 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


Clojure 1.2: Unicode string length bug?

2010-07-01 Thread ngocdaothanh
With 1.2-master-SNAPSHOT:

(def t "車馬象士將士象馬車")
(count t)  ; => 27
(.length t)  ; => 27

With 1.1, the result is 9.

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


Lift equivalent

2010-01-02 Thread ngocdaothanh
Scala has Lift with many advanced features:
http://blog.lostlake.org/index.php?/archives/16-Web-Framework-Manifesto.html
http://blog.lostlake.org/index.php?/archives/25-Why-the-world-needs-another-web-framework.html

If a similar (or better) web framework is written in Clojure, how will
it be implemented? Which existing Java libraries can be used to save
time?

-- 
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.1 release

2010-01-02 Thread ngocdaothanh
If http://build.clojure.org/snapshots is official, I think it is great
to add a link to it to the homepage of Clojure.


On Jan 2, 3:01 pm, Phil Hagelberg  wrote:
> Howard Lewis Ship  writes:
>
> > Is this available via a Maven repo yet and, if so, what version of
> > clojure-contrib is compatible (and stable?).
>
> I just added the 1.1.x branch to build.clojure.org, so you can 
> usehttp://build.clojure.org/snapshotsto get it. It looks like contrib has
> finally had its version number bumped, though it hasn't had an official
> release, so 1.1.0-master-SNAPSHOT works for it.
>
> -Phil

-- 
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: Language similarities

2009-12-28 Thread ngocdaothanh
I don't know Algol, but I think you're correct:
http://www.paulgraham.com/diff.html


On Dec 29, 1:14 pm, jim  wrote:
> Had an interesting conversation with a programmer friend of mine. He's
> skeptical of my Lisp leanings and mostly sticks to the 'normal'
> languages; C++, Java, etc.
>
> I made that comment that pretty much all the languages derived from
> Algol like the C family, Java, Pascal, etc. were pretty much the same.
> He looked at me like I was insane. :) :)
>
> I guess when you're looking back on the world from the vantage point
> of s-expressions, they do look the same. IMHO. :) Erlang and Haskell
> would have a similar effect, I would suspect.
>
> Jim

-- 
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: Parenthesis Inference

2009-12-20 Thread ngocdaothanh
I have been studying Clojure for 3 months. My experience:
* After knowing about Lisp coding style and indents: parens
disappeared
* After knowing about reading from inside to outside: Clojure code is
more understandable (http://groups.google.com/group/clojure/
browse_thread/thread/144142dcb5586292/a3df3bb6741b1a56)
* The problem is not parens, the problem is *nested* parens. The 2
tips above + adding intermediate meaningful immutables using "let"
help a lot.


> Hmm.  Have we solved anything?  Will this just make the complaints go
>
> (from (too (many (parens
>
> to
>   too
>     many
>       nesting
>         levels?

-- 
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: Code arrangement for understandability

2009-12-11 Thread ngocdaothanh
Below is a snippet from Rich's presentation at QCon 2009 (http://
qconlondon.com/london-2009/file?path=/qcon-london-2009/slides/
RichHickey_Clojure.pdf):

(reduce (fn [model f] (assoc model f (inc (get model f 1
{} features))

Do Clojurians usually arrange like that? Can it be rearrange for more
understandability?

Thanks


On Dec 12, 5:16 am, ataggart  wrote:
> On Dec 11, 1:14 am, ngocdaothanh  wrote:
>
>
>
> > > Do you come from a Python background?
>
> > For the sake of this discussion, I would say I come from Erlang.
>
> > > Judging by you examples, I looks like you're still getting used to the 
> > > lisp style of coding.  Everything is a chained function call.
>
> > You're correct. Comming from Erlang:
> > * I tend to see things as if they are in a chain, concatted by commas.
> > * I feel that I have to write lots of nested "let"s for temporary
> > immutables. I think to avoid adding "let"s, Clojurians would just
> > don't use temporary immutables. This makes Clojure code hard to
> > understand, because temporary immutables with good names help explain
> > the code. The tricks to avoid adding "let"s in previous posts are very
> > ugly in my opinion. Is this style of "let" common and a good practice
> > to follow? (I just want to know, sorry if my expression is offensive)
>
> > > What do you mean by abstractness?
>
> > By "abstractness level" in the previous post, I mean level of code
> > block. For example I would say B1 and B4 are of the same level.
>
> > B1
> > | B2
> > | B3
> > B4
>
> > Because of indents, my previous Clojure code lied to my eyes that x,
> > y, f, g are not at the same block level. This is my difficulty with
> > Clojure. In short, I can't see a rough algorithm from any Clojure code
> > any more just by seeing the shape (levels) of blocks. To understand a
> > Clojure code, I have to look at every bit of code, look closer.
>
> > > In Clojure we still need to look farther up the screen...
>
> > Things in Erlang are immutable, so I think Clojure has no advantage
> > over Erlang here.
>
> > > Practice using comp & partial...
>
> > What do you mean by "comp & partial"? Could you please explain?
>
> > > (let [x 1
> > >       y (+ x 2)]
> > >   (f x)
> > >   (g y))
>
> > Well, I know my example code can be rewritten like that, but I just
> > could not give a better one.
>
> > Rearranging like this reminds me of C, in which every variables must
> > be listed beforehand. Since all Clojurians say "lazy" is good, I would
> > say I prefer C++ because I can be lazy in it, I only have to declare a
> > variable when I actually use it.
>
> > I'm lost in Clojure, please light me a way.
>
> > Lots of thanks.
>
> It would be much easier if you pasted some real code.  So far it just
> looks like complaining that you find it awkward to write clojure in an
> imperative style.

-- 
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: Code arrangement for understandability

2009-12-11 Thread ngocdaothanh
> Do you come from a Python background?

For the sake of this discussion, I would say I come from Erlang.

> Judging by you examples, I looks like you're still getting used to the lisp 
> style of coding.  Everything is a chained function call.

You're correct. Comming from Erlang:
* I tend to see things as if they are in a chain, concatted by commas.
* I feel that I have to write lots of nested "let"s for temporary
immutables. I think to avoid adding "let"s, Clojurians would just
don't use temporary immutables. This makes Clojure code hard to
understand, because temporary immutables with good names help explain
the code. The tricks to avoid adding "let"s in previous posts are very
ugly in my opinion. Is this style of "let" common and a good practice
to follow? (I just want to know, sorry if my expression is offensive)

> What do you mean by abstractness?

By "abstractness level" in the previous post, I mean level of code
block. For example I would say B1 and B4 are of the same level.

B1
| B2
| B3
B4

Because of indents, my previous Clojure code lied to my eyes that x,
y, f, g are not at the same block level. This is my difficulty with
Clojure. In short, I can't see a rough algorithm from any Clojure code
any more just by seeing the shape (levels) of blocks. To understand a
Clojure code, I have to look at every bit of code, look closer.

> In Clojure we still need to look farther up the screen...

Things in Erlang are immutable, so I think Clojure has no advantage
over Erlang here.

> Practice using comp & partial...

What do you mean by "comp & partial"? Could you please explain?

> (let [x 1
>   y (+ x 2)]
>   (f x)
>   (g y))

Well, I know my example code can be rewritten like that, but I just
could not give a better one.

Rearranging like this reminds me of C, in which every variables must
be listed beforehand. Since all Clojurians say "lazy" is good, I would
say I prefer C++ because I can be lazy in it, I only have to declare a
variable when I actually use it.

I'm lost in Clojure, please light me a way.

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


Code arrangement for understandability

2009-12-10 Thread ngocdaothanh
Hi,

I want to ask about code arrangement and understandability
(readability).

Consider this "normal" code:
x = 1
...
f(x)
...
y = x + 2
...
g(y)

x, f, y, g have the same "abstractness" level, so they are indented to
the same level.

My Clojure code:
(let [x 1]
  ...
  (f x)
  ...
  (let [y (+ x 2)]
...
(g y)))

It is very difficult to capture the "algorithm" behind the Clojure
code because things of the same "abstractness" level do not have the
same indent level.

How to rearrange the Clojure code for understandability?

I have been studying Clojure for several months now but I could never
"get" it. But I couldn't explain why I couldn't get it, I just didn't
know why. But today I think I have found the reason: I think the
problem of Clojure (and Lisp) is not parenthesis, its problem is
indent.

I think if I can "let over" this problem, I will be enlightened. Would
you please help me?

Thank you,
Ngoc

-- 
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 - a Clojure build tool

2009-11-18 Thread ngocdaothanh
Which IDE and Ant plugin do you use?

I think you can use "lein pom" to have an pom.xml file for use with
Maven. Hope that your fantastic IDE supports Maven.


On Nov 18, 5:39 pm, Shantanu Kumar  wrote:
> Is any IDE support planned for this? As it turns out, many people
> (including me) stick with Ant just because the IDE support is
> fantastic.
>
> Regards,
> Shantanu
>
> On Nov 18, 12:29 pm, Phil Hagelberg  wrote:
>
> > I'm pleased to announce the initial release of Leiningen.
>
> > Leiningen is a build tool for Clojure designed to not set your hair on fire.
>
> > Building Clojure projects with tools designed for Java can be an
> > exercise in frustration. If you use Ant, you end up copying around a
> > lot of the same tasks around between XML files on all your projects;
> > there's a lot of repetition. Maven avoids repetition, but provides
> > very little transparency into what's really going on behind the scenes
> > and forces you to become a Maven expert to script a nontrivial
> > build. Either way you end up writing far more XML than is necessary.
>
> > With Leiningen, your build is described using Clojure. You can put any
> > code you like in your project.clj file; the only requirement is that
> > it includes a call to defproject. You can define your own tasks in
> > there if you need to, but the majority of projects should be able to
> > get by on the tasks that are provided with Leiningen. If you do find a
> > common task that you need to add, you can implement it as a plugin
> > rather than copying and pasting among each of your projects.
>
> > Projects are defined with Clojure syntax, (not XML!) in project.clj:
>
> >     (defproject leiningen "0.5.0"
> >       :description "A build tool designed not to set your hair on fire."
> >       :main leiningen.core
> >       :dependencies [[org.clojure/clojure "1.1.0-alpha-SNAPSHOT"]
> >                      [org.clojure/clojure-contrib "1.0-SNAPSHOT"]
> >                      [ant/ant-launcher "1.6.2"]
> >                      [org.apache.maven/maven-ant-tasks "2.0.10"]]
> >       :dev-dependencies [[org.clojure/swank-clojure "1.0"]])
>
> > A number of tasks are provided:
>
> >     $ lein deps # install dependencies in lib/
>
> >     $ lein test [PRED] # run the project's tests, optionally filtered on 
> > PRED
>
> >     $ lein compile # ahead-of-time compile into classes/
>
> >     $ lein repl # launch a REPL with the project classpath configured
>
> >     $ lein clean # remove all build artifacts
>
> >     $ lein jar # create a jar of the project
>
> >     $ lein uberjar # create a standalone jar that contains all dependencies
>
> >     $ lein pom # output a pom.xml file for interop with Maven
>
> >     $ lein install # install in local repo (currently requires mvn)
>
> >     $ lein help [TASK] # show a list of tasks or help for a given TASK
>
> > Leiningen is extensible, you can define new tasks in project.clj or in
> > plugins. Add your plugin as a dev-dependency of your project, and you'll
> > be able to call "lein $YOUR_COMMAND". See the lein-swank directory for
> > an example of a plugin.
>
> > To install simply download the shell script, place it somewhere on your
> > $PATH, and run "lein self-install":
>
> >  http://github.com/technomancy/leiningen/raw/master/bin/lein
>
> > Many people have expressed frustration at trying to use a tool designed
> > for Java with their Clojure projects, especially when dealing with
> > dependencies. I hope this can move things forward and ease the
> > pain. Note that it's still a very young project, (started about two
> > weeks ago), but in classic Clojure fashion it is able to leverage a lot
> > of functionality from other JVM tools.
>
> > Please try it out and let me know how it works for your project!
>
> > thanks,
> > Phil
>
> > Bonus: Leiningen also integrates with the Clojars open-source
> > clojure-specific repository coming soon athttp://clojars.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


Re: leiningen - a Clojure build tool

2009-11-18 Thread ngocdaothanh
Lein is super easy to install and use!

To demonstrate the ease of installation, the "Installation" part in
README should say:
1. Download only one file: wget 
http://github.com/technomancy/leiningen/raw/master/bin/lein
2. chmod +x lein
3. ./lein self-install

Thanks for the work.


On Nov 18, 4:41 pm, David Nolen  wrote:
> Awesomeness.
>
> On Wed, Nov 18, 2009 at 2:29 AM, Phil Hagelberg  wrote:
>
> > I'm pleased to announce the initial release of Leiningen.
>
> > Leiningen is a build tool for Clojure designed to not set your hair on
> > fire.
>
> > Building Clojure projects with tools designed for Java can be an
> > exercise in frustration. If you use Ant, you end up copying around a
> > lot of the same tasks around between XML files on all your projects;
> > there's a lot of repetition. Maven avoids repetition, but provides
> > very little transparency into what's really going on behind the scenes
> > and forces you to become a Maven expert to script a nontrivial
> > build. Either way you end up writing far more XML than is necessary.
>
> > With Leiningen, your build is described using Clojure. You can put any
> > code you like in your project.clj file; the only requirement is that
> > it includes a call to defproject. You can define your own tasks in
> > there if you need to, but the majority of projects should be able to
> > get by on the tasks that are provided with Leiningen. If you do find a
> > common task that you need to add, you can implement it as a plugin
> > rather than copying and pasting among each of your projects.
>
> > Projects are defined with Clojure syntax, (not XML!) in project.clj:
>
> >    (defproject leiningen "0.5.0"
> >      :description "A build tool designed not to set your hair on fire."
> >      :main leiningen.core
> >      :dependencies [[org.clojure/clojure "1.1.0-alpha-SNAPSHOT"]
> >                     [org.clojure/clojure-contrib "1.0-SNAPSHOT"]
> >                     [ant/ant-launcher "1.6.2"]
> >                     [org.apache.maven/maven-ant-tasks "2.0.10"]]
> >      :dev-dependencies [[org.clojure/swank-clojure "1.0"]])
>
> > A number of tasks are provided:
>
> >    $ lein deps # install dependencies in lib/
>
> >    $ lein test [PRED] # run the project's tests, optionally filtered on
> > PRED
>
> >    $ lein compile # ahead-of-time compile into classes/
>
> >    $ lein repl # launch a REPL with the project classpath configured
>
> >    $ lein clean # remove all build artifacts
>
> >    $ lein jar # create a jar of the project
>
> >    $ lein uberjar # create a standalone jar that contains all dependencies
>
> >    $ lein pom # output a pom.xml file for interop with Maven
>
> >    $ lein install # install in local repo (currently requires mvn)
>
> >    $ lein help [TASK] # show a list of tasks or help for a given TASK
>
> > Leiningen is extensible, you can define new tasks in project.clj or in
> > plugins. Add your plugin as a dev-dependency of your project, and you'll
> > be able to call "lein $YOUR_COMMAND". See the lein-swank directory for
> > an example of a plugin.
>
> > To install simply download the shell script, place it somewhere on your
> > $PATH, and run "lein self-install":
>
> >  http://github.com/technomancy/leiningen/raw/master/bin/lein
>
> > Many people have expressed frustration at trying to use a tool designed
> > for Java with their Clojure projects, especially when dealing with
> > dependencies. I hope this can move things forward and ease the
> > pain. Note that it's still a very young project, (started about two
> > weeks ago), but in classic Clojure fashion it is able to leverage a lot
> > of functionality from other JVM tools.
>
> > Please try it out and let me know how it works for your project!
>
> > thanks,
> > Phil
>
> > Bonus: Leiningen also integrates with the Clojars open-source
> > clojure-specific repository coming soon athttp://clojars.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: Clojure Web Libraries

2009-11-16 Thread ngocdaothanh
Could someone provide an example about using Clojure with Restlet?

I found:
http://github.com/stuartsierra/altlaw-clojure-restlet
but don't understand how the code works as a web application.

Thanks.


On Nov 15, 11:06 pm, Stefan Tilkov  wrote:
> On Nov 15, 2009, at 4:58 AM, ngocdaothanh wrote:
>
> > Hi Stuart,
>
> > Can you elaborate on Restlet? After some short investigation I think
> > it uses annotation but Clojure does not support it, so Clojure is not
> > "Restlet-ready".
>
> Only the JSR-311 (JAX-RS) API uses annotations. Restlet has a lower-level API 
> that just uses plain classes.
>
> Stefan
> --
> Stefan Tilkov,http://www.innoq.com/blog/st/
>
> > Thanks
>
> > On Jan 23, 1:44 am, Stuart Sierra  wrote:
> >> Hi Frank,
> >> I'd also recommend looking atRestlet<http://www.restlet.org/> and
> >> the Java Servlets API.
> >> -Stuart Sierra
>
> >> On Jan 21, 4:39 pm, Frank  wrote:
>
> >>> Hi,
>
> >>> I am interested in trying to use Clojure to developweb-based
> >>> applications.  Can someone point me to any Clojure libraries that have
> >>> been written that I can use.  Thanks.
>
> >>> Frank
>
> > --
> > 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: Clojure Web Libraries

2009-11-14 Thread ngocdaothanh
Hi Stuart,

Can you elaborate on Restlet? After some short investigation I think
it uses annotation but Clojure does not support it, so Clojure is not
"Restlet-ready".

Thanks


On Jan 23, 1:44 am, Stuart Sierra  wrote:
> Hi Frank,
> I'd also recommend looking atRestlet and
> the Java Servlets API.
> -Stuart Sierra
>
> On Jan 21, 4:39 pm, Frank  wrote:
>
> > Hi,
>
> > I am interested in trying to use Clojure to develop web-based
> > applications.  Can someone point me to any Clojure libraries that have
> > been written that I can use.  Thanks.
>
> > Frank

-- 
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: ANN: Clojure live-repl

2009-10-29 Thread ngocdaothanh

I think it would be great if JLine is integrated in live-repl.

I have some questions:
* Why not use maven and clojure-maven-plugin?
* Is it OK if live-repl uses one version of Clojure and the attached
process uses another?


On Oct 29, 9:35 am, David Powell  wrote:
> > Under Linux I had to fix the paths in liverepl.sh to include the build
> > folder:
>
> > java -cp "$LIVEREPL_HOME/build/*:$JDK_HOME/lib/tools.jar"
> > net.djpowell.liverepl.client.Main "$CLOJURE_JAR"
> > "$LIVEREPL_HOME/build/liverepl-agent.jar"
> > "$LIVEREPL_HOME/build/liverepl-server.jar" "$@"
>
> I think liverepl.sh gets copied to the build folder, so the intent is to run 
> that copy of the liverepl.sh script.  (Though I haven't really tested the .sh 
> script)
>
> --
> Dave
--~--~-~--~~~---~--~~
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: STM talk

2009-10-24 Thread ngocdaothanh

After reading your PDF, I now understand what Clojure means by the
term "coordinate". Thanks a lot!

--
coordinating activities of multiple actors (i.e. transactions)
• may want to send messages to multiple actors within a txn
and guarantee that either all messages are processed successfully
or all the actors involved rollback changes to their retained state
--


On Oct 25, 2:35 am, Mark Volkmann  wrote:
> I gave a talk on STM at a conference in St. Louis called "Strange
> Loop" last Thursday.
> 1 up and 2 up PDF versions of the slides are available 
> athttp://ociweb.com/mark/stm/.
> The talk was videotaped. I'll send another email when that is available.
> Feedback is welcomed! I'll update the slides if needed.
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
--~--~-~--~~~---~--~~
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 is two!

2009-10-19 Thread ngocdaothanh

Because most materials on Clojure are only at introduction level, I
think a "Clojure Cookbook" which provides solutions to many many small
real world problems would definitely be a best seller.

For most programming languages, I only need 2 books: an introduction
one and a cookbook one.


On Oct 20, 12:18 am, Robert Stehwien  wrote:
> >> two more coming.
>
> >> one is clojure in action, published by manning, written by Amit Rathore
> >> the other is definitive guide to clojure by Luke VanderHart
> >>http://www.apress.com/book/view/1430272317
>
> > There are two manning books coming out I believe.  One by Amit and the
> > other by, I don't know who.  I reviewed 2 clojure book proposals for manning
> > and was told both were green lighted.  But I haven't heard any more than
> > that.  Hoping to get on the beta for both.
>
> > I'll ping the manning representative.
>
> I asked my contact at Manning about the two books and got the following
> response:
> --
> Thanks for checking in! Both books are currently underway. Rathore is
> writing "Clojure in Action", and Chris Houser has officially joined Michael
> Fogus in writing "Idiomatic Clojure" (tentative title).
> --
>
> The more the merrier I say!  Amazing for a language so young and maybe the
> most number of Lisp like books released by major publishers in such a short
> span of time.
>
> Congratulations!
>
> --Robert
--~--~-~--~~~---~--~~
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 Cheat Sheet

2009-10-18 Thread ngocdaothanh

The bottom of that page says: Original source (pdf, tex). So it is
probably TeX.


On Oct 19, 8:06 am, Gorsal  wrote:
> All right, so this is probably way off topic, but what software was
> used to create the clojure cheat sheet?http://clojure.org/cheatsheet
> I really like the format and would like to make one for my own
> utilities so that I can actually remember what general utility
> functions i have written!
--~--~-~--~~~---~--~~
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: server-socket on exit event

2009-10-16 Thread ngocdaothanh

The snippet:
---
(def reschedule nil) ; Forward declaration

(defn broadcast [msg]
  (reschedule)
  (doall
(map
  (fn [client]
(send-msg client msg))
  @clients)))
---

(def reschedule nil) is a forward declaration. It is just there to
avoid syntax error, because "broadcast" uses "reschedule", thus
"reschedule" must exist before "broadcast". "reschedule" is actually
defined later in the file.

Thanks for your interest.


On Oct 16, 4:06 pm, Emeka  wrote:
> Ngo,
>
> I checked out your github , it is great. I have not used netty, it looks
> clean. However, what is the meaning of this, (def reshedule nil)?
>
> Regards,
> Emeka
>
> On Thu, Oct 15, 2009 at 3:02 AM, ngocdaothanh wrote:
>
>
>
> > I created this (Netty is used instead of server-socket):
> >http://github.com/ngocdaothanh/telchat-clojure
>
> > I am going to create a Scala version of the same program to have a
> > feeling of Clojure vs Scala, it will be telchat-scala.
>
> > On Oct 14, 10:12 pm, Emeka  wrote:
> > > Ngo,
>
> > > Honestly  speaking I don't know. How far have you gone?
>
> > > Regards,
> > > Emeka
>
> > > On Sat, Oct 3, 2009 at 3:21 PM, ngocdaothanh 
> > wrote:
>
> > > > Emeka, good catch. It's just my mistake.
>
> > > > Another thing is I think there may be exception raised when on-msg
> > > > sends message to a closed socket. How would you solve this?
>
> > > > On Oct 3, 7:35 pm, Emeka  wrote:
> > > > > ngo,
> > > > > I was about doing this kind of client/server thing some  days ago,
> > > > however
> > > > > now you are into it I would like to learn then. I am not quite clear
> > why
> > > > you
> > > > > have this:
> > > > > (.start (new Thread (fn [] (create-server 8080 chat-loop
>
> > > > > My concern is on  Thread, create-server function has a Thread inside
> > > > > create-server-aux function.
>
> > > > > Regards,
> > > > > Emeka
>
> > > > > On Fri, Oct 2, 2009 at 3:13 AM, ngocdaothanh 
> > > > wrote:
>
> > > > > > > I'm not sure TCP/IP has a native facility for that.
>
> > > > > > I'm afraid John's statement is correct:
>
> >http://www.velocityreviews.com/forums/t125620-client-socket-disconnec.
> > > > ..
> > > > > > and trying to read and write until something wrong happens as
> > > > > > demonstrated in Roger's code is the only way to check for
> > > > > > disconnection.
>
> > > > > > Below is my new code. Sorry it is rather long.
>
> > > > > > (import '[java.io BufferedReader InputStreamReader
> > > > > > OutputStreamWriter])
> > > > > > (use 'clojure.contrib.server-socket)
>
> > > > > > (def clients (ref []))  ; Each client is an *out*
>
> > > > > > (defn on-msg [from msg]
> > > > > >  (println msg)
> > > > > >  (doall
> > > > > >    (map
> > > > > >      (fn [client]
> > > > > >        (if-not (= from client)
> > > > > >          (binding [*out* client]
> > > > > >            (println msg)
> > > > > >            (flush
> > > > > >     �...@clients)))
>
> > > > > > (defn on-disconnect [client]
> > > > > >  (dosync
> > > > > >    (alter clients
> > > > > >      (fn [clients]
> > > > > >        (remove (fn [c] (= c client)) clients
> > > > > >  (on-msg client "A client has disconnected"))
>
> > > > > > (defn on-connect [client]
> > > > > >  (dosync (alter clients conj client))
> > > > > >  (on-msg client "A client has connected"))
>
> > > > > > (defn chat-loop [is os]
> > > > > >  (let [client (OutputStreamWriter. os)]
> > > > > >    (on-connect client)
> > > > > >    (binding [*in* (BufferedReader. (InputStreamReader. is))]
> > > > > >      (loop []
> > > > > >        (let [msg (read-line)]  ; msg is nil when the client
> > > > > > disconnects
> > > > > >          (if (nil? msg)
> > >

Re: server-socket on exit event

2009-10-14 Thread ngocdaothanh

I created this (Netty is used instead of server-socket):
http://github.com/ngocdaothanh/telchat-clojure

I am going to create a Scala version of the same program to have a
feeling of Clojure vs Scala, it will be telchat-scala.


On Oct 14, 10:12 pm, Emeka  wrote:
> Ngo,
>
> Honestly  speaking I don't know. How far have you gone?
>
> Regards,
> Emeka
>
> On Sat, Oct 3, 2009 at 3:21 PM, ngocdaothanh  wrote:
>
> > Emeka, good catch. It's just my mistake.
>
> > Another thing is I think there may be exception raised when on-msg
> > sends message to a closed socket. How would you solve this?
>
> > On Oct 3, 7:35 pm, Emeka  wrote:
> > > ngo,
> > > I was about doing this kind of client/server thing some  days ago,
> > however
> > > now you are into it I would like to learn then. I am not quite clear why
> > you
> > > have this:
> > > (.start (new Thread (fn [] (create-server 8080 chat-loop
>
> > > My concern is on  Thread, create-server function has a Thread inside
> > > create-server-aux function.
>
> > > Regards,
> > > Emeka
>
> > > On Fri, Oct 2, 2009 at 3:13 AM, ngocdaothanh 
> > wrote:
>
> > > > > I'm not sure TCP/IP has a native facility for that.
>
> > > > I'm afraid John's statement is correct:
>
> > > >http://www.velocityreviews.com/forums/t125620-client-socket-disconnec.
> > ..
> > > > and trying to read and write until something wrong happens as
> > > > demonstrated in Roger's code is the only way to check for
> > > > disconnection.
>
> > > > Below is my new code. Sorry it is rather long.
>
> > > > (import '[java.io BufferedReader InputStreamReader
> > > > OutputStreamWriter])
> > > > (use 'clojure.contrib.server-socket)
>
> > > > (def clients (ref []))  ; Each client is an *out*
>
> > > > (defn on-msg [from msg]
> > > >  (println msg)
> > > >  (doall
> > > >    (map
> > > >      (fn [client]
> > > >        (if-not (= from client)
> > > >          (binding [*out* client]
> > > >            (println msg)
> > > >            (flush
> > > >     �...@clients)))
>
> > > > (defn on-disconnect [client]
> > > >  (dosync
> > > >    (alter clients
> > > >      (fn [clients]
> > > >        (remove (fn [c] (= c client)) clients
> > > >  (on-msg client "A client has disconnected"))
>
> > > > (defn on-connect [client]
> > > >  (dosync (alter clients conj client))
> > > >  (on-msg client "A client has connected"))
>
> > > > (defn chat-loop [is os]
> > > >  (let [client (OutputStreamWriter. os)]
> > > >    (on-connect client)
> > > >    (binding [*in* (BufferedReader. (InputStreamReader. is))]
> > > >      (loop []
> > > >        (let [msg (read-line)]  ; msg is nil when the client
> > > > disconnects
> > > >          (if (nil? msg)
> > > >            (on-disconnect client)
> > > >            (do
> > > >              (on-msg client msg)
> > > >              (recur
>
> > > > (.start (new Thread (fn [] (create-server 8080 chat-loop
>
> > > > On Oct 2, 5:20 am, John Harrop  wrote:
> > > > > On Thu, Oct 1, 2009 at 4:02 PM, Roger Gilliar 
> > wrote:
> > > > > > Am 01.10.2009 um 21:28 schrieb ngocdaothanh:
> > > > > > > Roger, your code is not event based.
> > > > > > What do you mean by not event based ?
>
> > > > > He means he wants automatic notification if a connection is dropped.
>
> > > > > I'm not sure TCP/IP has a native facility for that.
>
> > > > > What most chat type programs, multiplayer games, and suchlike do is
> > send
> > > > a
> > > > > periodic ping from server to each connected client, which as part of
> > the
> > > > > chat protocol the client is supposed to acknowledge. If a client
> > stops
> > > > > responding for more than a few ping-intervals, it's assumed to have
> > > > > disconnected or otherwise become unreachable.
>
> > > > > This method has the advantage of being entirely under the control of
> > the
> > > > > application layer, and the further advantage of also working with UDP
> > > > (which
> > > > > is crucial in the "multiplayer games" case at least).
--~--~-~--~~~---~--~~
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: clojureshell-maven-plugin - easier clojure startup with maven

2009-10-14 Thread ngocdaothanh

clojure-maven-plugin is so good! Thanks a lot.

clojureshell-maven-plugin explicitly loads Clojure 1.0, so I cannot
use 1.1.0-alpha-SNAPSHOT by declaring these in my pom.xml:

...


org.clojure
clojure-lang
1.1.0-alpha-SNAPSHOT



org.clojure
clojure-contrib
1.0-SNAPSHOT





tapestry-snapshots

http://tapestry.formos.com/maven-snapshot-repository/


...


On Oct 15, 4:40 am, Stuart Sierra  wrote:
> On Oct 14, 1:03 pm, ngocdaothanh  wrote:
>
> > Is there a way to run a .clj file (with classpath correctly set by
> > Maven)? I don't want REPL, I just want to run a .clj file without
> > compiling.
>
> Look at the "clojure:run" target in the clojure-maven-plugin version
> 1.1:http://github.com/talios/clojure-maven-plugin
>
> -SS
--~--~-~--~~~---~--~~
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: clojureshell-maven-plugin - easier clojure startup with maven

2009-10-14 Thread ngocdaothanh

Is there a way to run a .clj file (with classpath correctly set by
Maven)? I don't want REPL, I just want to run a .clj file without
compiling.


On Sep 5, 12:40 am, "J. McConnell"  wrote:
> On Fri, Sep 4, 2009 at 3:35 AM, Fredrik Appelberg <
>
>
>
> fredrik.appelb...@gmail.com> wrote:
> > On Fri, Sep 4, 2009 at 3:58 AM, J. McConnell  wrote:
>
> >> On Thu, Sep 3, 2009 at 12:40 PM, Fredrik Appelberg <
> >> fredrik.appelb...@gmail.com> wrote:
>
> >>> I've just released the first tentative version of Clojureshell. It's a
> >>> simple maven plugin that allows you to easily start a clojure REPL or run 
> >>> a
> >>> Swank server in the context of any maven project.
>
> >> This looks great, thanks Fredrik! The first time I tried to run "mvn
> >> clojureshell:repl" I received an error about the plugin not being found.
> >> Running "mvn -X clojureshell:repl" results in the following snippet:
>
> >> [INFO] Searching repository for plugin with prefix: 'clojureshell'.
> >> [DEBUG] Loading plugin prefixes from group: nu.mulli
> >> [INFO] nu.mulli: checking for updates from mulli.nu
> >> [DEBUG] repository metadata for: 'nu.mulli' could not be found on
> >> repository: mulli.nu
>
> > Hm... Could you post (or email me) the relevant portions of your
> > settings.xml?
>
> I think there may be some issues with the way my company has us configure
> Maven. I'm checking with someone to see if that's the problem. I can't
> install from source either because it looks like all requests for
> dependencies, regardless of the  tag in the POM, are routed
> through our internal repository, so I can't grab your
> org.clojure:clojure-lang:1.0 jar hosted on milli.nu.
>
> > Also, what version of maven are you running? I've tested this on three
> > machines (two linux, one OSX), but it strikes me that they all run maven
> > 2.0.9; I haven't tested running any previous (or later) versions at all.
>
> I'm also on 2.0.9.
>
> Thanks for the help. I'll update you if the problem does not end up being on
> my side, but I strongly suspect it is.
>
> Thanks,
>
> - J.
--~--~-~--~~~---~--~~
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: Agent send-off: ~20k/s

2009-10-07 Thread ngocdaothanh

Mark,
What tool did you use to see the CPU utilization, especially when the
test run time is so short?

Just curious.


On Oct 7, 12:58 pm, MarkSwanson  wrote:
> > (You wrote "atom" several times but I guess you meant "agent".)
>
> Heh heh... yeah.
--~--~-~--~~~---~--~~
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: Agent send-off: ~20k/s

2009-10-04 Thread ngocdaothanh

I think it is not "spawn about 20K agents / second", it is 20K message
passings / second. The number is about that of Erlang.


On Oct 5, 11:45 am, MarkSwanson  wrote:
> I recently integrated Clojure with two async messaging systems.
> I wound up doing "send" operations through a Clojure agent.
> I was curious how many agents I could spawn per second and found I
> could spawn about 20K agents / second.
>
> Code for testing:
>
> (def t (agent true))
>
> (defn tt [_ num]
>      (try
>        (let [x (inc num)])
>        (catch Throwable t (println "error"
>
> (defn agent-speed-test []
>      (time (loop [b 1]
>              (send-off t tt b)
>              (if (> b 2)
>                b
>                (recur (inc b))
>
> After a few iterations in the repl (started with -server) my best time
> was:
> "Elapsed time: 1021.700789 msecs" - which is pretty much exactly 20k/
> s.
>
> CPU: 2.4GHz Core2 Duo.
> Java 1.6.0_14-ea-b03
> Clojure from git/master around Sept/2009.
--~--~-~--~~~---~--~~
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: server-socket on exit event

2009-10-03 Thread ngocdaothanh

Emeka, good catch. It's just my mistake.

Another thing is I think there may be exception raised when on-msg
sends message to a closed socket. How would you solve this?


On Oct 3, 7:35 pm, Emeka  wrote:
> ngo,
> I was about doing this kind of client/server thing some  days ago, however
> now you are into it I would like to learn then. I am not quite clear why you
> have this:
> (.start (new Thread (fn [] (create-server 8080 chat-loop
>
> My concern is on  Thread, create-server function has a Thread inside
> create-server-aux function.
>
> Regards,
> Emeka
>
> On Fri, Oct 2, 2009 at 3:13 AM, ngocdaothanh  wrote:
>
> > > I'm not sure TCP/IP has a native facility for that.
>
> > I'm afraid John's statement is correct:
>
> >http://www.velocityreviews.com/forums/t125620-client-socket-disconnec...
> > and trying to read and write until something wrong happens as
> > demonstrated in Roger's code is the only way to check for
> > disconnection.
>
> > Below is my new code. Sorry it is rather long.
>
> > (import '[java.io BufferedReader InputStreamReader
> > OutputStreamWriter])
> > (use 'clojure.contrib.server-socket)
>
> > (def clients (ref []))  ; Each client is an *out*
>
> > (defn on-msg [from msg]
> >  (println msg)
> >  (doall
> >    (map
> >      (fn [client]
> >        (if-not (= from client)
> >          (binding [*out* client]
> >            (println msg)
> >            (flush
> >     �...@clients)))
>
> > (defn on-disconnect [client]
> >  (dosync
> >    (alter clients
> >      (fn [clients]
> >        (remove (fn [c] (= c client)) clients
> >  (on-msg client "A client has disconnected"))
>
> > (defn on-connect [client]
> >  (dosync (alter clients conj client))
> >  (on-msg client "A client has connected"))
>
> > (defn chat-loop [is os]
> >  (let [client (OutputStreamWriter. os)]
> >    (on-connect client)
> >    (binding [*in* (BufferedReader. (InputStreamReader. is))]
> >      (loop []
> >        (let [msg (read-line)]  ; msg is nil when the client
> > disconnects
> >          (if (nil? msg)
> >            (on-disconnect client)
> >            (do
> >              (on-msg client msg)
> >              (recur
>
> > (.start (new Thread (fn [] (create-server 8080 chat-loop
>
> > On Oct 2, 5:20 am, John Harrop  wrote:
> > > On Thu, Oct 1, 2009 at 4:02 PM, Roger Gilliar  wrote:
> > > > Am 01.10.2009 um 21:28 schrieb ngocdaothanh:
> > > > > Roger, your code is not event based.
> > > > What do you mean by not event based ?
>
> > > He means he wants automatic notification if a connection is dropped.
>
> > > I'm not sure TCP/IP has a native facility for that.
>
> > > What most chat type programs, multiplayer games, and suchlike do is send
> > a
> > > periodic ping from server to each connected client, which as part of the
> > > chat protocol the client is supposed to acknowledge. If a client stops
> > > responding for more than a few ping-intervals, it's assumed to have
> > > disconnected or otherwise become unreachable.
>
> > > This method has the advantage of being entirely under the control of the
> > > application layer, and the further advantage of also working with UDP
> > (which
> > > is crucial in the "multiplayer games" case at least).
--~--~-~--~~~---~--~~
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: REPL integration in a existing java project

2009-10-01 Thread ngocdaothanh

You can create-repl-server:
http://richhickey.github.com/clojure-contrib/server-socket-api.html
and access the server remotely from telnet.


On Oct 1, 9:29 pm, DomS  wrote:
> Hello all,
>
> I'm trying to integrate an REPL in a existing java project, but i dont
> know how it works or where to start.
>
> At first it should only have the functionality from an ordinary clj
> repl. Later we want to extend it with some functions and macros, to
> control our software via "console".
>
> Help would be appreciated.
>
> Thanks,
> Dominik
--~--~-~--~~~---~--~~
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: server-socket on exit event

2009-10-01 Thread ngocdaothanh

> I'm not sure TCP/IP has a native facility for that.

I'm afraid John's statement is correct:
http://www.velocityreviews.com/forums/t125620-client-socket-disconnection-event-not-received-on-server-socket-java-nio.html
and trying to read and write until something wrong happens as
demonstrated in Roger's code is the only way to check for
disconnection.

Below is my new code. Sorry it is rather long.

(import '[java.io BufferedReader InputStreamReader
OutputStreamWriter])
(use 'clojure.contrib.server-socket)

(def clients (ref []))  ; Each client is an *out*

(defn on-msg [from msg]
  (println msg)
  (doall
(map
  (fn [client]
(if-not (= from client)
  (binding [*out* client]
(println msg)
(flush
  @clients)))

(defn on-disconnect [client]
  (dosync
(alter clients
  (fn [clients]
(remove (fn [c] (= c client)) clients
  (on-msg client "A client has disconnected"))

(defn on-connect [client]
  (dosync (alter clients conj client))
  (on-msg client "A client has connected"))

(defn chat-loop [is os]
  (let [client (OutputStreamWriter. os)]
(on-connect client)
(binding [*in* (BufferedReader. (InputStreamReader. is))]
  (loop []
(let [msg (read-line)]  ; msg is nil when the client
disconnects
  (if (nil? msg)
(on-disconnect client)
(do
  (on-msg client msg)
  (recur

(.start (new Thread (fn [] (create-server 8080 chat-loop


On Oct 2, 5:20 am, John Harrop  wrote:
> On Thu, Oct 1, 2009 at 4:02 PM, Roger Gilliar  wrote:
> > Am 01.10.2009 um 21:28 schrieb ngocdaothanh:
> > > Roger, your code is not event based.
> > What do you mean by not event based ?
>
> He means he wants automatic notification if a connection is dropped.
>
> I'm not sure TCP/IP has a native facility for that.
>
> What most chat type programs, multiplayer games, and suchlike do is send a
> periodic ping from server to each connected client, which as part of the
> chat protocol the client is supposed to acknowledge. If a client stops
> responding for more than a few ping-intervals, it's assumed to have
> disconnected or otherwise become unreachable.
>
> This method has the advantage of being entirely under the control of the
> application layer, and the further advantage of also working with UDP (which
> is crucial in the "multiplayer games" case at least).
--~--~-~--~~~---~--~~
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: server-socket on exit event

2009-10-01 Thread ngocdaothanh

Roger, your code is not event based.

I'm new to Clojure and as a small exercise I just want to create a
simple chat server for telnet clients, any usable socket library is
OK:
* Chat messages are broadcast to all clients
* When a client disconnect, all others will receive "A client has
disconnected" message

Below is my code up to the moment. The problem is because there seems
to be no disconnect event in server-socket, when a client disconnect
the clients ref is inconsistent.

(import '[java.io BufferedReader InputStreamReader
OutputStreamWriter])
(use 'clojure.contrib.server-socket)

(def clients (ref []))

(defn on-input [input]
  (println input)
  (doall
(map
  (fn [out]
(binding [*out* (OutputStreamWriter. out)]
  (println input)
  (flush)))
  @clients)))


(defn echo [in out]
  (dosync (alter clients conj out))

  (binding [*in* (BufferedReader. (InputStreamReader. in))]
(loop []
  (let [input (read-line)]
(on-input input))
  (recur

(.start (new Thread (fn [] (create-server 8080 echo


On Oct 2, 4:05 am, Roger Gilliar  wrote:
> > I want to write a simple socket server in Clojure. I want to perform
> > some action when a client disconnects.
>
> ---
> The following code works for me. read-input returns nil if the socket  
> is closed (the client disconnects)
>
> Regards
>    Roger
>
> (defn read-input []
>         (loop [result [] input (read-line)]
>                 (if input
>                         (if (= (first input) \#)
>                  result
>                                 (recur (conj result input) (read-line))
>                         )
>                         nil)))
>
> (defn handle-client [in out]
>         (binding [
>                 *in* (reader in)
>                 ]
>                 (with-connection db
>                         (let [outstream (writer out)]
>                                 (loop []
>                                         (let [xml (read-input)]
>                                                 (if xml
>                                                         (do
>                                                                 (send-answers 
> (parse outstream (makestr xml)))
>                                                                 (recur))
>                                                         (info 
> "disconnected"
>
> (def server (create-server *port* handle-client))
>
> Am 01.10.2009 um 20:39 schrieb ngocdaothanh:
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



server-socket on exit event

2009-10-01 Thread ngocdaothanh

I want to write a simple socket server in Clojure. I want to perform
some action when a client disconnects.

I tried server-socket:
http://richhickey.github.com/clojure-contrib/server-socket-api.html
but it does not support on exit event.

Is there a solution? Should I look at something like Grizzly, Mina, or
Netty?

--~--~-~--~~~---~--~~
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: Can anyone here give a comparison between Clojure and Erlang on concurrent programming?

2009-09-24 Thread ngocdaothanh

I think there are 2 kinds of concurrency: local concurrency (one
machine) and distributed concurrency (parallel).

Is there a comparison about the speed of local concurrency of Clojure
and Erlang?

I would like to create an online multiplayer game server which serves
thousands of persistent flash connections. On a single machine
(something like Intel i7 with 6GB RAM), can JBoss Netty + Clojure beat
gen_tcp + Erlang?

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: Lazy binding

2009-09-03 Thread ngocdaothanh

Compojure's default view syntax looks great (same idea as Yaw's EHTML:
http://yaws.hyber.org/dynamic.yaws). It allows one to "stay in
Clojure".

I found an example of integrating StringTemplate (and Hibernate) with
Clojure:
http://bitbucket.org/kumarshantanu/blogjure/

Is there more example of integrating StringTemplate with Clojure?


On Sep 4, 10:07 am, James Sofra  wrote:
> Not to distract from the talk on how to achieve these things in
> Clojure but I really want to second Stuart's recommendation of
> StringTemplate, it really is a great library and is seamless to use
> from Clojure.
>
> I would recommend it for any templating needs, not just HTML views, in
> fact I have used it at a micro level in Java to do just the kind of
> lazy binding you are talking about, passed a template as a String
> argument to a method and let the method then provide the attributes to
> be bound to the template worked great.
>
> Cheers,
> James Sofra
>
> On Sep 3, 11:23 pm, Stuart Sierra  wrote:
>
> > Check outwww.stringtemplate.org, a Java template library with a
> > functional design.
> > -SS
>
> > On Sep 3, 8:42 am, ngocdaothanh  wrote:
>
> > > Hi,
>
> > > In Rails you can create a view like this:
>
> > > my_view.erb:
> > > <%= "hello" + @name %>
>
> > > I'm new to Clojure. I want to create something like the above like
> > > this:
>
> > > (defn my-view []
> > >   (str "hello" name))
>
> > > The point is:
> > > * name is not known when my-view is defined
> > > * I don't want to pass name as a argument of my-view, this is kind of
> > > ugly boilerplate
>
> > > How can I implement this feature in 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
-~--~~~~--~~--~--~---



Re: clojureshell-maven-plugin - easier clojure startup with maven

2009-09-03 Thread ngocdaothanh

What do you mean "Swank server"? Could you explain about that?


On Sep 4, 1:40 am, Fredrik Appelberg 
wrote:
> Hello everyone,
>
> I've just released the first tentative version of Clojureshell. It's a
> simple maven plugin that allows you to easily start a clojure REPL or run a
> Swank server in the context of any maven project. This means that maven does
> all the dependency management heavy lifting; all runtime dependencies are
> automatically added to the classpath of the clojure process. And you don't
> even have to modify your project pom.xml; as long as you have this plugin
> installed in you local repo it will work with *any* maven project.
>
> Note that Clojureshell doesn't have any of the features of the
> clojure-maven-plugin (such as managing, compiling and packaging clojure code
> in a project), it merely provides an easier way to start up clojure with the
> proper dependencies loaded.
>
> If this sounds interesting, please check out the project 
> athttps://github.com/fred-o/clojureshell-maven-plugin/tree
>
> Comments, suggestions and criticism is most welcome. As I said, I'm still in
> the early stages of development, and I'm sure there are a lot of issues that
> I haven't caught.
>
> Cheers,
> -- Fredrik
> ==
> What am I up to?http://twitter.com/appelberg
--~--~-~--~~~---~--~~
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: Lazy binding

2009-09-03 Thread ngocdaothanh

Using a map of keywords is a good solution, but I think it is somewhat
just boilerplate code to satisfy the compiler, not to satisfy
developers (yes, human). In view we have to write (:my-var map)
everywhere. Is there a better way, something like lazy variable
binding or lazy function binding?

To repair the Ruby code, instance variable or method can be used:

def my_view
  "hello #...@name}"
end
@name = "bilbo"
puts my_view

Or
def my_view
  "hello #{name}"
end
def name "bilbo" end
puts my_view

Ruby does not force @name or name in my_view to exist before hand,
this is really dynamic.

Well, the idea is I want to create a web framework based on Compojure
with as less code as possible in view (may be designers would like it,
it's not normal HTML anyway). Place-holders in view should be lazy,
then when an action wants to use a view, it just has to declare a
bunch of concrete values and include the desired view, something like:

(defn my-action []
  (with-variables [foo "hello", bar "world"] my-view))

The Clojure code may be incorrect, but I think you have captured the
idea.


On Sep 3, 10:32 pm, tmountain  wrote:
> I believe the way this works in rails has to do with the order in
> which variables are resolved. In this case, @name is an instance
> variable that's already been assigned elsewhere (your controller).
> Rails loads the view after the controller class has been instantiated.
> For this to work, the view is probably "mixed-into" the controller
> class somehow to ensure that the instance variable is visible. If you
> try this with a standard ruby function, it doesn't work.
>
> def my_view
>   "hello #{name}"
> end
>
> name = "bilbo"
> puts my_view()
> `my_view': undefined local variable or method `name' for main:Object
> (NameError)
>
> You could obviously use a global variable, but that would be really
> nasty. With Clojure, your function can see the variable so long as
> it's defined ahead of time.
>
> (def my-name "bilbo") ; name is a reserved word
>
> (defn my-view []
>   (str "hello " my-name))
> (my-view)
> "hello bilbo"
>
> The my-name variable doesn't even have to be bound in this case, just
> created. I think what you're really looking for though is a way to
> define a function with no arguments referencing a variable that isn't
> defined at all. I'm not sure how you would accomplish that.
>
> -Travis
>
> On Sep 3, 8:42 am, ngocdaothanh  wrote:
>
>
>
>
>
> > Hi,
>
> > In Rails you can create a view like this:
>
> > my_view.erb:
> > <%= "hello" + @name %>
>
> > I'm new to Clojure. I want to create something like the above like
> > this:
>
> > (defn my-view []
> >   (str "hello" name))
>
> > The point is:
> > * name is not known when my-view is defined
> > * I don't want to pass name as a argument of my-view, this is kind of
> > ugly boilerplate
>
> > How can I implement this feature in 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
-~--~~~~--~~--~--~---



Lazy binding

2009-09-03 Thread ngocdaothanh

Hi,

In Rails you can create a view like this:

my_view.erb:
<%= "hello" + @name %>

I'm new to Clojure. I want to create something like the above like
this:

(defn my-view []
  (str "hello" name))

The point is:
* name is not known when my-view is defined
* I don't want to pass name as a argument of my-view, this is kind of
ugly boilerplate

How can I implement this feature in 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
-~--~~~~--~~--~--~---



I18n

2009-08-27 Thread ngocdaothanh

Hi all,

Is there an i18n library for Clojure? What Java i18n library should I
use in a Clojure program (it suits Clojure syntax for example)? For
Ruby and Erlang I prefer Gettext, but for Java it seems
that .properties files are in major use.

Thanks,
Ngoc.

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



Enumerate namespaces

2009-08-27 Thread ngocdaothanh

Hi all,

To have dynamic to study Clojure, I would like to create a pluggable
(like Rails Engines) web framework based on Compojure. It will add
some conventions like:
* Controllers files are prefixed with "c-", ex: src/main/clojure/myapp/
c-article.clj
* To make controllers pluggable, routes are not defined in a central
place, but defined in controllers themselves. On startup, the
framework will scan all controllers to collect routes.

It is simple if there are source files of the controllers. The
framework can find all .clj files with the "c-" prefix in the project
directory and load them on startup.

But if the .clj files are compiled into a .war file without source
code in it, there will be no .clj files. Can you give advices on how
to solve this bootstrap process?

Thanks all,
Ngoc.

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



Connection pool with clojure.contrib.sql

2009-08-26 Thread ngocdaothanh

Hi.

As I understand clojure.contrib.sql's with-connection opens DB
connection at the beginning and closes it at the end of each call. How
do I create a connection pool so that with-connection can reuse
connections?

Thanks,
Ngoc.

--~--~-~--~~~---~--~~
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 vs scala

2009-08-26 Thread ngocdaothanh

> In the meantime this may be helpful:
> http://en.wikibooks.org/wiki/Clojure_Programming/Examples/API_Example...

Thank you, this is very helpful.

> > * Clojure doc is hard to understand.
>
> Have you seen http://ociweb.com/mark/clojure/article.html?

Yes I have, this may be the best Clojure doc on the Internet. I mean
people are more attracted to Clojure than Scala if the Clojure doc is
improved, and it is greatly improved if there are examples in the API
doc (http://clojure.org/api). An example is worth a thousand words.

--~--~-~--~~~---~--~~
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 vs scala

2009-08-25 Thread ngocdaothanh

I think there are a lot of people who need to choose between Clojure
and Scala to study as a "new" language. I must say that both are bad:
* Clojure doc is hard to understand.
* Scala grammar is complicated.

I prefer Clojure. I think Clojure feature at this time is OK, thus the
decisive point to draw people to Clojure is doc. I wonder if the doc
at this time is obvious for LISP people, but comming from C/C++, Java,
Ruby, and Erlang (Erlang doc is bad, but it is paradise compared to
that of Clojure :D) and even after reading the Clojure book, I must
say that I can't understand 99% of the doc of both clojure and clojure-
contrib.

For example, what does the following mean?
-
(-> x form)
(-> x form & more)
Macro
Threads the expr through the forms. Inserts x as the second item in
the first form, making a list of it if it is not a list already. If
there are more forms, inserts the first form as the second item in
second form, etc.
-

My wish: There are easy-to-understand examples in API doc.

Rails is easy to use largely because there are examples in doc of
every API function.


On Aug 26, 12:37 pm, Alan Busby  wrote:
> On Wed, Aug 26, 2009 at 5:43 AM, npowell  wrote:
>
> > I mean, I didn't think the article was terribly in depth, but a real,
> > evenhanded comparison would be enlightening.
>
> Reducing it further, I'd be interested just to hear more about the contrast
> of static typing versus macros. Which is more beneficial for different
> situations and why?
--~--~-~--~~~---~--~~
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: ANN: clojure-maven-plugin 1.0 released and in maven central

2009-08-24 Thread ngocdaothanh

I'm new to Maven. Thank you for the explanation.

Using git-submodules and  is a good idea. Prior to
using your plugin, I use clojure and clojure-contrib with Maven like
this:

1. Manually download from GitHub and compile clojure and clojure-
contrib.
2. Install them to the local Maven repository:
mvn install:install-file -DgroupId=org.clojure -DartifactId=clojure -
Dversion=SNAPSHOT -Dpackaging=jar -Dfile=clojure.jar
mvn install:install-file -DgroupId=org.clojure -DartifactId=clojure-
contrib -Dversion=SNAPSHOT -Dpackaging=jar -Dfile=clojure-contrib.jar
3. Add clojure and clojure-contrib and other dependencies that my
project uses in pom.xml:
...
  

  org.clojure
  clojure
  SNAPSHOT


  org.clojure
  clojure-contrib
  SNAPSHOT

...
  
...

4. Use Exec Maven Plugin (http://mojo.codehaus.org/exec-maven-plugin/)
to run my Clojure file:
mvn exec:java -Dexec.mainClass="clojure.main" -Dexec.args="path/to/my/
clojure/file.clj"

I want to ask is there a better way to use clojure and clojure-contrib
and running Clojure file with Maven?


On Aug 25, 1:54 pm, Mark Derricutt  wrote:
> The plugin itself has NO dependency on clojure or clojure contrib so you'll
> need to add them to your own pom.xml first.
> This is mostly because a) clojure contrib hasn't been released or in maven
> central, b) I'm using clojure 1.1 on my own projects which isn't released.
>
> For my own projects, I have compojure and some other libs included as
> git-submodules in my repository, and have configured additional
>  to compile.
>
> --
>
> On Tue, Aug 25, 2009 at 4:19 PM, ngocdaothanh wrote:
>
> > Is clojure-contrib included?
>
> > I tried but mvn clojure:compile gives:
> > Exception in thread "main" java.io.FileNotFoundException: Could not
> > locate clojure/contrib/json/read__init.class or clojure/contrib/json/
> > read.clj on classpath
--~--~-~--~~~---~--~~
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: ANN: clojure-maven-plugin 1.0 released and in maven central

2009-08-24 Thread ngocdaothanh

Hi,

Is clojure-contrib included?

I tried but mvn clojure:compile gives:
Exception in thread "main" java.io.FileNotFoundException: Could not
locate clojure/contrib/json/read__init.class or clojure/contrib/json/
read.clj on classpath

pom.xml:
http://gist.github.com/174217

hello.clj:
(ns hello)
(use 'clojure.contrib.json.read)
(read-json "{\"x\": 1}")

Thanks.


On Aug 25, 6:28 am, Mark Derricutt  wrote:
> Hey all,
> I've released 1.0 of my clojure-maven-plugin and its now available in
> maven-central.
>
> To use it, a minimal pom.xml declaring a dependency on clojure, and the the
> plugin (without configuration) is all you need.
>
>   -http://gist.github.com/174217
>
> With the above pom, running "mvn clojure:compile" will scan any .clj file
> under ./src/main/clojure and compile them into the ./target/classes
> directory.
>
> "mvn clojure:test-compile" will do the same for any .clj file under
> ./src/test/clojure.
>
> For more options such as hooking up a test script, filtering namespaces etc.
> see the project site at:
>
>  http://github.com/talios/clojure-maven-plugin
>
> Mark
>
> --
> Discouragement is a dissatisfaction with the past, a distaste for the
> present, and a distrust of the future
> - Maree De Jong, Life NZ.
>
> blog:http://www.talios.com
> podcast:http://www.illegalargument.com
> skype / twitter: talios
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Fwd: Annotations and gen-class

2009-08-24 Thread ngocdaothanh

Hi,

I'm new to Clojure. How can I add @ChannelPipelineCoverage("one")
annotation to a proxy as in?
http://viewvc.jboss.org/cgi-bin/viewvc.cgi/netty/trunk/src/main/java/org/jboss/netty/example/http/snoop/HttpResponseHandler.java?view=markup

I tried:
(def handler
  (proxy [SimpleChannelUpstreamHandler] []
(messageReceived [ctx e]
  ((.println System/out) "hello"

(with-meta handler {:annotations ["ChannelPipelineCoverage" "one"]})

But there is error:
Exception in thread "main" java.lang.ClassCastException:
clojure.proxy.org.jboss.netty.channel.SimpleChannelUpstreamHandler
cannot be cast to clojure.lang.IObj

Thanks.


-- Forwarded message --
From: Matt Revelle 
Date: Mar 25, 1:15 am
Subject: Annotations and gen-class
To: Clojure


On Mar 24, 10:19 am, Sean  wrote:

> Some working code would make it a lot easier to understand *exactly*
> what you're looking for.  Do you think you could post a few quick
> methods on github?

No need for gist, this will do as an example:
(ns some.namespace
  (:gen-class
    :methods [^#{:annotations [SomeAnnotation]} [aMethod [T] S]]
...)

This adds an annotation, SomeAnnotation, to the gen-class'd method,
aMethod.



> If memory serves, the reflections package should
> be a good place to start.

> However, you'd need to ask *why* you need this.

> If the answer is "I need to work with and modify a pre-existing, pre-
> tested, needs-to-stay-in-production application", then this is a great
> idea.  Clojrue should help you glue your components together.

> If your answer is "I'm making a brand new application", or "This is
> for a side project", this might be a bad approach.  Annotations
> generally are used to make up for a weakness in the Java language.
> Some Clojure language features could probably do the job better

> * Dynamic Typing
> * First class functions
> * Sequence functions. such as map/reduce/filter etc.
> * Macros

> Specifically, I think Guice (and other DI tools) should be avoided.
> They are the antithesis of functional programming, and first class
> functions will make your life much easier.  Try re-thinking about a
> problem in a functional style.  I'm willing to bet that you'll have a
> solution that is easier to write, easier to test, and will scale
> better.

You're preaching to the choir.  The reasoning behind supporting
annotations in gen-class is the
same as providing gen-class in the first place.  Generating classes
usable in Java code is
sometimes necessary and as gen-class' feature set becomes more
complete the better it serves users.



> On Mar 24, 9:57 am, Matt Revelle  wrote:

> > Support for using JVM annotations with Clojure code has come up
> > several times before,
> > I'd like a feature request issue to be created and to start discussing
> > the implementation.

> > It seems that an "annotations" metadata tag could contain all
> > annotations for an object,
> > and any annotations that persist to runtime would need bytecode
> > emitted.  This appears straightforward,
> > but I wonder if there will be a problem using Method or Parameter
> > annotations.

> > The motivation for this is to support Java libraries which depend on
> > annotations at runtime for discovery and metadata persistence.
> > Being able to integrate a class generated by gen-class with, for
> > example, a Java project using Guice would be handy.

> > Thoughts?

> > -Matt

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



proxy and annotation

2009-08-24 Thread ngocdaothanh

Hi,

How can I define annotation for a proxy?

For example:

Java code:

http://viewvc.jboss.org/cgi-bin/viewvc.cgi/netty/trunk/src/main/java/org/jboss/netty/example/http/snoop/HttpResponseHandler.java?view=markup

Clojure code:

(def handler
  (proxy [SimpleChannelUpstreamHandler] []
(messageReceived [ctx e]
  ((.println System/out) "hello"

How can I set   @ChannelPipelineCoverage("one")  for the "handler"
proxy?

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