[ClojureScript] Wrapping all def into a load event handler

2011-12-26 Thread Takahiro Hozumi
Hi,
In order to manipulate dom, I often want to bind elements into
variable through def, but we cannot manipulate it until load event.
So I wrapped all def into a load event handler in the following way.
https://gist.github.com/1521051
I don't use let, because many elements cause deep nested let,
and I don't use atom to store elements, because reset! and deref are
not necessary by binding element directly.
Is this bad way in ClojureScript? Is there a downside?

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


Lithub and Marginalia

2011-12-26 Thread nchurch
> Like this?  http://brighterplanet.github.com/flight/impact_model.html

> You can see how they handle it (from a Ruby-centric perspective) here: 
> https://github.com/brighterplanet/numbers/blob/gh-pages/_posts/2010-12-02-github-pages-rocco-and-rake-file-tasks.markdown

(The original thread seems to have disappeared; it can be found here:
http://groups.google.com/group/clojure/browse_thread/thread/7f31a8e7aa98a547/5562eb25b9d70365?lnk=gst&q=Lithub#5562eb25b9d70365.)

This does seem to be a good way of doing a Lithub.  For that matter,
there is the recent release of Clojure fs utils with Marginalia docs
at http://raynes.github.com/fs/

I'd say this kind of thing needs really only two steps to be a full
Lithub.  One, this should be the \main way of viewing code, i.e. in
place of https://github.com/Raynes/fs.  There does seem to be a
certain amount of customization of Github possible from the
Brighterplanet example, so maybe a Marginalia-centric Lithub within
Github is possible.  Maybe it would even be possible to give three
views of the same material: code and docs side-by-side, docs with
links to code, and vice-versa.

The second step is a matter of search-engine optimizationsomething
I know very little about, I have to admit.  Look at this line in the
fs utils Marginalia, for instance:

Return the base name (final segment/file part) of a path.

(defn base-name
  [path]
  (.getName (file path)))

All the keywords you need to find that function are there; it even
provides three alternatives!  If I were searching off the top of my
head, I'd probably Google: return file part of path in Clojure.  But
this returns a mess of links that don't really lead to that function;
the Marginalia line doesn't even show up in the first few pages of
results (granted, it's fairly new).

Imagine if that kind of thing \were the first link, every time.
Consider how much time people spend every day looking for library
functionsany improvement in that process would be a big
productivity and coding-flow gain.  Having independent HTML anchors
for each function in a Marginalia page would be a startmuch
simpler than convincing Google to rank specific functions first.  If
the Google-whispering proves to be too difficult, the next best thing
would be optimizing search within the Lithub sites, so that the top
links are always to Clojure library functions and how to call them,
without any distraction.

-- 
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: Lithub and Marginalia

2011-12-26 Thread nchurch
There is really one more Lithub concern (at least), and that is how to
structure entry points into a huge codebase like Clojurehow to
present simplifications and toy examples, etc., and walk the reader
through it.  I think the other two things are such big wins, though,
that this third concern can take a back seat.

On Dec 26, 12:13 pm, nchurch  wrote:
> > Like this?  http://brighterplanet.github.com/flight/impact_model.html
> > You can see how they handle it (from a Ruby-centric perspective) 
> > here:https://github.com/brighterplanet/numbers/blob/gh-pages/_posts/2010-1...
>
> (The original thread seems to have disappeared; it can be found 
> here:http://groups.google.com/group/clojure/browse_thread/thread/7f31a8e7a)
>
> This does seem to be a good way of doing a Lithub.  For that matter,
> there is the recent release of Clojure fs utils with Marginalia docs
> athttp://raynes.github.com/fs/
>
> I'd say this kind of thing needs really only two steps to be a full
> Lithub.  One, this should be the \main way of viewing code, i.e. in
> place ofhttps://github.com/Raynes/fs.  There does seem to be a
> certain amount of customization of Github possible from the
> Brighterplanet example, so maybe a Marginalia-centric Lithub within
> Github is possible.  Maybe it would even be possible to give three
> views of the same material: code and docs side-by-side, docs with
> links to code, and vice-versa.
>
> The second step is a matter of search-engine optimizationsomething
> I know very little about, I have to admit.  Look at this line in the
> fs utils Marginalia, for instance:
>
> Return the base name (final segment/file part) of a path.
>
> (defn base-name
>   [path]
>   (.getName (file path)))
>
> All the keywords you need to find that function are there; it even
> provides three alternatives!  If I were searching off the top of my
> head, I'd probably Google: return file part of path in Clojure.  But
> this returns a mess of links that don't really lead to that function;
> the Marginalia line doesn't even show up in the first few pages of
> results (granted, it's fairly new).
>
> Imagine if that kind of thing \were the first link, every time.
> Consider how much time people spend every day looking for library
> functionsany improvement in that process would be a big
> productivity and coding-flow gain.  Having independent HTML anchors
> for each function in a Marginalia page would be a startmuch
> simpler than convincing Google to rank specific functions first.  If
> the Google-whispering proves to be too difficult, the next best thing
> would be optimizing search within the Lithub sites, so that the top
> links are always to Clojure library functions and how to call them,
> without any distraction.

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


Codox: an API doc generator for Clojure

2011-12-26 Thread James Reeves
Hi folks,

In order to generate the documentation for Ring and Compojure, I
created Codox after being unable to get Autodoc working.

Codox is pretty simple, but should work out of the box, and hopefully
looks quite nice. Here are a couple of examples:

http://mmcgrana.github.com/ring/
http://weavejester.github.com/compojure/

Options are limited so far, but patches to add options or improve the
formatting are welcome.

The project page is here:

https://github.com/weavejester/codox

- James

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Codox: an API doc generator for Clojure

2011-12-26 Thread Shantanu Kumar
+1 This is pretty neat! (I too couldn't get Autodoc working in the
past several months.)

Regards,
Shantanu

On Dec 26, 10:29 pm, James Reeves  wrote:
> Hi folks,
>
> In order to generate the documentation for Ring and Compojure, I
> created Codox after being unable to get Autodoc working.
>
> Codox is pretty simple, but should work out of the box, and hopefully
> looks quite nice. Here are a couple of examples:
>
> http://mmcgrana.github.com/ring/http://weavejester.github.com/compojure/
>
> Options are limited so far, but patches to add options or improve the
> formatting are welcome.
>
> The project page is here:
>
> https://github.com/weavejester/codox
>
> - James

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Codox: an API doc generator for Clojure

2011-12-26 Thread Gert Verhoog
I love it, thanks, and I got it running in about 10 seconds:

lein install plugin codox 0.3.1
lein doc

Question: One of my ns docstrings is a fair amount of text which is rendered as 
a really long line (because codox puts it inside a ... element). How 
would you deal with longer documentation strings? Would I need to insert manual 
line breaks or is there a better way?

cheers,
gert


On 27/12/2011, at 6:29 AM, James Reeves wrote:

> Hi folks,
> 
> In order to generate the documentation for Ring and Compojure, I
> created Codox after being unable to get Autodoc working.
> 
> Codox is pretty simple, but should work out of the box, and hopefully
> looks quite nice. Here are a couple of examples:
> 
> http://mmcgrana.github.com/ring/
> http://weavejester.github.com/compojure/
> 
> Options are limited so far, but patches to add options or improve the
> formatting are welcome.
> 
> The project page is here:
> 
> https://github.com/weavejester/codox
> 
> - James
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> 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


Running clojure.test.generative specs using lein test

2011-12-26 Thread Román González
Hey guys,

Just wondering, is there any way to integrate clojure.test.generative specs
with leiningen's "lein test" command? I googled but the documentation of
test.generative is pretty scarse. How should I run specs?

Thanks in advance.

Roman.-

-- 
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: Alternative structures to arrays?

2011-12-26 Thread Philip Potter
On Dec 22, 2011 3:35 PM, "Tassilo Horn"  wrote:
>
> Brian Hurt  writes:
>
> Hi Brian,
>
> > Vectors are actually a great trade-off, giving you almost the same
> > access and memory costs arrays do, but with all the advantages of
> > being immutable (multi-threaded goodness).
>
> On the other hand, you can have arrays of primitives but no vector of
> primitives.  That might make a difference for intensive numerical
> computations.
>
What about (vector-of :int) and friends?

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

ANN: okasaki-clojure

2011-12-26 Thread JuanManuel Gimeno Illa
Hi all,

   I've been working a "proof of concept" implementation of some data 
structures from Okasaki's book "Purely functional data structures". The 
implementations tries to follow the ML implementation describes in the book 
so I have defined some macros than use clojure.match to allow patter 
matching and datatypes.

   For instance, an unbalances binary search tree can be defined as:

(defdatatype
::UnbalancedBST
Empty ; empty tree
(Node a x b)) ; tree with root x, left subtree a and right subtree b

And the insert and member functions as:
(defun insert [x t]
[x Empty] 
(Node Empty x Empty)
[x ([Node a y b] :as s)]
(cond 
(< x y) (Node (insert x a) y b)
(< y x) (Node a y (insert x b))
:else   s))

(defun member [x t]
[_ Empty]
false
[x [Node a y b]]
(cond
(< x y) (recur x a)
(< y x) (recur x b)
:else   true))

   If you want to play with it is in
 https://github.com/jmgimeno/okasaki-clojure


   Juan Manuel

   

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

unchecked-int returning long?

2011-12-26 Thread Joel Hobson
Hi everyone,

I've noticed some unexpected behaviour with the unchecked-int function
- I think it's a bug, but I'm not entirely sure I've correctly
understood the purpose of the function.

(type (unchecked-int 0x)) shows long instead of int. This
isn't what I would have expected, either from the name, documentation
or source code.
Interestingly, (type (int (unchecked-int 0x))) also shows
java.lang.long instead of int.
Using (unchecked-int 0x) as an argument to call a java
function requiring an int causes an IllegalArgumentException.

In addition, the unchecked casting functions do not currently appear
on the clojure.org documentation cheat sheet.

Thanks,

Joel

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


Response to Being a Coder and 10 000 hours.

2011-12-26 Thread algo-lord
Check out The Dunning Kruger Effect to really see people have
incorrect opinions of themselves

-- 
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: Literate programming

2011-12-26 Thread Jay Edwards
Like this?  http://brighterplanet.github.com/flight/impact_model.html

You can see how they handle it (from a Ruby-centric perspective) here: 
https://github.com/brighterplanet/numbers/blob/gh-pages/_posts/2010-12-02-github-pages-rocco-and-rake-file-tasks.markdown

The same approach should work fine for a Clojure project.

J.


On Dec 22, 2011, at 10:14 PM, daly wrote:

> On Thu, 2011-12-22 at 17:53 -0800, nchurch wrote:
>> Firstly, there really needs to be something like a Github for literate
>> programming.  
> 
> What a great idea!
> I'll see what I can do.
> 
> Tim Daly
> 
> 
> -- 
> 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


Strange eval behavior on user-defined macros

2011-12-26 Thread Chris McBride
I'm working on a project where I want to use clojure macros in part of
my config file that I eval at runtime. However, I'm getting an "Unable
to resolve symbol" exception. So I made a test case to reproduce it
below:

(ns test.core (:gen-class))

(defmacro make-list [& body]
`(list ~@body))

(defn  stuff[]
(prn (eval (read-string "(make-list 1 2 3)"

(defn -main [& args] (stuff))
(-main)

When I run this file through the clojure interpreter I get the output
"(1 2 3)" from the -main call. Now if I do 'lein run' with my 'main'
namespace defined as test.core, I get this output:

(1 2 3)
Exception in thread "main" java.lang.RuntimeException: Unable to
resolve symbol: make-list in this context, compiling:(NO_SOURCE_PATH:
1)
at clojure.lang.Compiler.analyze(Compiler.java:6235)
at clojure.lang.Compiler.analyze(Compiler.java:6177)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3452)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6411)
at clojure.lang.Compiler.analyze(Compiler.java:6216)
at clojure.lang.Compiler.analyze(Compiler.java:6177)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5572)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5008)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3629)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6407)
at clojure.lang.Compiler.analyze(Compiler.java:6216)
at clojure.lang.Compiler.eval(Compiler.java:6462)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at test.core$stuff.invoke(core.clj:7)
at test.core$_main.doInvoke(core.clj:9)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.Var.invoke(Var.java:397)
at user$eval46.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6465)
at clojure.lang.Compiler.eval(Compiler.java:6455)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at clojure.main$eval_opt.invoke(main.clj:296)
at clojure.main$initialize.invoke(main.clj:315)
at clojure.main$null_opt.invoke(main.clj:348)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:405)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: Unable to resolve symbol: make-
list in this context
at clojure.lang.Util.runtimeException(Util.java:156)
at clojure.lang.Compiler.resolveIn(Compiler.java:6720)
at clojure.lang.Compiler.resolve(Compiler.java:6664)
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:6625)
at clojure.lang.Compiler.analyze(Compiler.java:6198)
... 31 more

 So first I get the "(1 2 3)" output from clojure calling -main when
it reads the file, but it seems like when lein calls -main it can't
resolve the symbol. Is this a limitation of java since this is at
runtime and macros have to be expanded at read-time? Or is this a bug?

-- 
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 list syntax sugar: f(x) notation

2011-12-26 Thread Louis Yu Lu
Recently, I found freedom of coding playing with Clojure with over 20
years’ experience on other program languages, Previously, I had
several trials of learning Lisp, but never got traction.

However there are two syntax notations always bother me, it feels
unnatural with my experience on other programming languages and math:

1)  Prefix operator for math formula. Jeffrey Bester’s math library
https://github.com/jbester/cljext/blob/master/cljext/math.clj has
brought in the infix notation and solved the problem;
2)  The leading item of a list follows the parenthesis when it serves
as a function name, (f x) instead of f(x). I am fully aware of many
discussions on alternative syntax for Clojure and Lisp in the past,
one stream is here 
http://groups.google.com/group/clojure/browse_thread/thread/319a1c77ed718ba/3e4be7484b7cbe38
My proposition is enhance Clojure to accept both (f x) and f(x), the
leading item can appear either after ‘(‘ as usual with classic Lisp
notion:
(println "Hello," "world!")
or with conventional function call notation:
println("Hello," "world!")
The f(x) notation is just a syntax sugar, the only restriction is no
space between the leading item and '('.  If one or more spaces in
between, the item will be treated as a separate symbol. Either notion
or a mix of them can be used in the same program. Here are some
examples:

; classic Lisp syntax notation
(defn pig-latin [word]
  (let [first-letter (first word)]
(if (.contains "aeiou" (str first-letter))
  (str word "ay")
  (str (subs word 1) first-letter "ay"
(println (pig-latin "red"))
(println (pig-latin "orange"))

; f(x) syntax notation
defn(pig-latin [word]
  let( [first-letter first(word)]
if(.contains("aeiou", str(first-letter))
  str(word, "ay")
  str(subs(word, 1), first-letter, "ay"
println(pig-latin("red"))
println(pig-latin("orange"))

; classic Lisp syntax notation
(defn fib [n]
   (if  (< n 2)
   1
  (+  (fib (dec n) )  (fib (- n 2)
(fib 36)

; mix of two notations
defn(fib [n]
   if((< n 2)
   1
   (+ fib(dec(n))  fib((- n 2)))
   )
)
fib(36)

I have made minor changes (dozen lines) in one file (LispReader.java)
from Clojure source repository to implement this syntax sugar(code
posted at https://github.com/louisyulu/clojure-fx). It works with well-
formed classic Clojure code and the proposed notation.
Running the test suite from Clojure distribution results two error:
One in the file compilation.clj line 90:
(recur y ^Long(rem x y)]
The problem is ^Long(… becomes function call, the fix is adding a
space in between
(recur y ^Long  (rem x y)]

The second is in the file sequences.clj line 1131:
(is (=(partition-by #{\a \e \i \o \u} "abcdefghijklm")
The problem is (=(… , ‘=’ is associated with following ‘(‘, the
intention was the previous ‘(‘, the fix is also adding a space in
between
(is (=  (partition-by #{\a \e \i \o \u} "abcdefghijklm")

These two cases are caused by the not well-formed Clojure code
(strictly speaking, each item in the list should be separated by a
space).

The proposed syntax sugar apparently pleases my eyes and fingers from
conventional languages. With some experiments, I found the code is
more readable for me to use f(x) notation for function call, and (op
x) for operator.

I like to hear from the community what kind of dark corner the
proposed syntax sugar may run into.

Thanks,
Louis

-- 
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 list syntax sugar: f(x) notation

2011-12-26 Thread Louis Yu Lu
Recently, I found freedom of coding playing with Clojure with over 20
years’ experience on other program languages, Previously, I had
several trials of learning Lisp, but never got traction.

However there are two syntax notations always bother me, it feels
unnatural with my experience on other programming languages and math:

1)  Prefix operator for math formula. Jeffrey Bester’s math library
https://github.com/jbester/cljext/blob/master/cljext/math.clj has
brought in the infix notation and solved the problem;
2)  The leading item of a list follows the parenthesis when it serves
as a function name, (f x) instead of f(x). I am fully aware of many
discussions on alternative syntax for Clojure and Lisp in the past,
one stream is here 
http://groups.google.com/group/clojure/browse_thread/thread/319a1c77ed718ba/3e4be7484b7cbe38
My proposition is enhance Clojure to accept both (f x) and f(x), the
leading item can appear either after ‘(‘ as usual with classic Lisp
notion:
(println "Hello," "world!")
or with conventional function call notation:
println("Hello," "world!")
The f(x) notation is just a syntax sugar, the only restriction is no
space between the leading item and '('.  If one or more spaces in
between, the item will be treated as a separate symbol. Either notion
or a mix of them can be used in the same program. Here are some
examples:

; classic Lisp syntax notation
(defn pig-latin [word]
  (let [first-letter (first word)]
(if (.contains "aeiou" (str first-letter))
  (str word "ay")
  (str (subs word 1) first-letter "ay"
(println (pig-latin "red"))
(println (pig-latin "orange"))

; f(x) syntax notation
defn(pig-latin [word]
  let( [first-letter first(word)]
if(.contains("aeiou", str(first-letter))
  str(word, "ay")
  str(subs(word, 1), first-letter, "ay"
println(pig-latin("red"))
println(pig-latin("orange"))

; classic Lisp syntax notation
(defn fib [n]
   (if  (< n 2)
   1
  (+  (fib (dec n) )  (fib (- n 2)
(fib 36)

; mix of two notations
defn(fib [n]
   if((< n 2)
   1
   (+ fib(dec(n))  fib((- n 2)))
   )
)
fib(36)

I have made minor changes (dozen lines) in one file (LispReader.java)
from Clojure source repository to implement this syntax sugar(code
posted at https://github.com/louisyulu/clojure-fx). It works with well-
formed classic Clojure code and the proposed notation.
Running the test suite from Clojure distribution results two error:
One in the file compilation.clj line 90:
(recur y ^Long(rem x y)]
The problem is ^Long(… becomes function call, the fix is adding a
space in between
(recur y ^Long  (rem x y)]

The second is in the file sequences.clj line 1131:
(is (=(partition-by #{\a \e \i \o \u} "abcdefghijklm")
The problem is (=(… , ‘=’ is associated with following ‘(‘, the
intention was the previous ‘(‘, the fix is also adding a space in
between
(is (=  (partition-by #{\a \e \i \o \u} "abcdefghijklm")

These two cases are caused by the not well-formed Clojure code
(strictly speaking, each item in the list should be separated by a
space).

The proposed syntax sugar apparently pleases my eyes and fingers from
conventional languages. With some experiments, I found the code is
more readable for me to use f(x) notation for function call, and (op
x) for operator.

I like to hear from the community what kind of dark corner the
proposed syntax sugar may run into.

Thanks,
Louis









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


Interested in a port of Ruby's String#unpack

2011-12-26 Thread mrb_bk
Hey Everyone:

I'm working on a project in Clojure that involves parsing binary data
files.  Specifically, I'm building a tool for analyzing Redis (http://
redis.io) dump files (.rdb format).  The very beginnings of this
nascent project are here: http://github.com/mrb/pianist .  I am a
beginner to Clojure and Lisp in general, but I'm a long time Ruby
programmer with experience in C, Java, etc.  During the course of
working through some Clojure learning materials and general poking
around the web and #clojure in IRC, I've noticed that one of my
favorite tools for working with binary data from Ruby is missing in
the Java/Clojure world.  This is String#unpack:

http://www.ruby-doc.org/core-1.9.3/String.html#method-i-unpack

After a brief Twitter conversation with @abedra, and while I get the
chance to submit my contributors agreement in order to access Clojure-
dev, I thought I'd bring this topic up here.

For what it's worth, I've checked out Gloss, which is interesting but
a bit too opinionated for me.  Plus I believe that something to this
effect should be part of clojure core - it seems that easy interface
for lazily handling binary data as seqs doesn't exist as such right
now.

If anyone has comments on the beginnings of my codebase (be gentle),
or thoughts about implementing something similar to String#unpack, or
a suggestion of an alternative set of tools I could use, that would be
great.  Thanks!

Mike
twitter.com/mrb_bk
github.com/mrb

-- 
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: Codox: an API doc generator for Clojure

2011-12-26 Thread Meikel Brandmeyer
Hi,

Am 26.12.2011 um 22:23 schrieb Gert Verhoog:

> Question: One of my ns docstrings is a fair amount of text which is rendered 
> as a really long line (because codox puts it inside a ... 
> element). How would you deal with longer documentation strings? Would I need 
> to insert manual line breaks or is there a better way?

Maybe we could agree on something like Markdown to render docstrings?

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Strange eval behavior on user-defined macros

2011-12-26 Thread Meikel Brandmeyer
Hi,

eval happens with *ns* bound to clojure-core. Try to fully qualify make-list.

Sincerely
Meikel

PS: In case you are Chris on SO, I answered your question there also.

-- 
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 list syntax sugar: f(x) notation

2011-12-26 Thread Softaddicts
Hi,

I have more than 30 years of dev under my belt dated back to Fortran, Cobol,... 
never had a problem with Lisp syntax

Far more bothering to me were immutability and laziness, it took me three 
months to get used to it,
not in a home project but laying out production code.

Clojure is a Lisp and prefix notation is part of it. It brings uniformity to 
the syntax,
on the contrary, your alternate syntax breaks it.

You forget to consider a Lisp form as data structures into which your code can 
crawl
and alter it to generate different forms. The prefix notation and the list 
shape of forms allows that to be done easily.

Even if it was done, I see a huge usability problem with your approach because
code generation in macros and elsewhere would be impacted badly or at least the
two syntax would have problems coexisting in the same code base.

Look at forms as data structures and it should ease the transition.

Luc P.

> Recently, I found freedom of coding playing with Clojure with over 20
> years’ experience on other program languages, Previously, I had
> several trials of learning Lisp, but never got traction.
> > However there are two syntax notations always bother me, it feels
> unnatural with my experience on other programming languages and math:
> > 1)  Prefix operator for math formula. Jeffrey Bester’s math library
> https://github.com/jbester/cljext/blob/master/cljext/math.clj has
> brought in the infix notation and solved the problem;
> 2)The leading item of a list follows the parenthesis when it serves
> as a function name, (f x) instead of f(x). I am fully aware of many
> discussions on alternative syntax for Clojure and Lisp in the past,
> one stream is here 
> http://groups.google.com/group/clojure/browse_thread/thread/319a1c77ed718ba/3e4be7484b7cbe38
> My proposition is enhance Clojure to accept both (f x) and f(x), the
> leading item can appear either after ‘(‘ as usual with classic Lisp
> notion:
> (println "Hello," "world!")
> or with conventional function call notation:
>   println("Hello," "world!")
> The f(x) notation is just a syntax sugar, the only restriction is no
> space between the leading item and '('.  If one or more spaces in
> between, the item will be treated as a separate symbol. Either notion
> or a mix of them can be used in the same program. Here are some
> examples:
> > ; classic Lisp syntax notation
> (defn pig-latin [word]
>   (let [first-letter (first word)]
> (if (.contains "aeiou" (str first-letter))
>   (str word "ay")
>   (str (subs word 1) first-letter "ay"
> (println (pig-latin "red"))
> (println (pig-latin "orange"))
> > ; f(x) syntax notation
> defn(pig-latin [word]
>   let( [first-letter first(word)]
> if(.contains("aeiou", str(first-letter))
>   str(word, "ay")
>   str(subs(word, 1), first-letter, "ay"
> println(pig-latin("red"))
> println(pig-latin("orange"))
> > ; classic Lisp syntax notation
> (defn fib [n]
>(if  (< n 2)
>1
>   (+  (fib (dec n) )  (fib (- n 2)
> (fib 36)
> > ; mix of two notations
> defn(fib [n]
>if((< n 2)
>1
>(+ fib(dec(n))  fib((- n 2)))
>)
> )
> fib(36)
> > I have made minor changes (dozen lines) in one file (LispReader.java)
> from Clojure source repository to implement this syntax sugar(code
> posted at https://github.com/louisyulu/clojure-fx). It works with well-
> formed classic Clojure code and the proposed notation.
> Running the test suite from Clojure distribution results two error:
> One in the file compilation.clj line 90:
> (recur y ^Long(rem x y)]
> The problem is ^Long(… becomes function call, the fix is adding a
> space in between
> (recur y ^Long  (rem x y)]
> > The second is in the file sequences.clj line 1131:
>   (is (=(partition-by #{\a \e \i \o \u} "abcdefghijklm")
> The problem is (=(… , ‘=’ is associated with following ‘(‘, the
> intention was the previous ‘(‘, the fix is also adding a space in
> between
>   (is (=  (partition-by #{\a \e \i \o \u} "abcdefghijklm")
> > These two cases are caused by the not well-formed Clojure code
> (strictly speaking, each item in the list should be separated by a
> space).
> > The proposed syntax sugar apparently pleases my eyes and fingers from
> conventional languages. With some experiments, I found the code is
> more readable for me to use f(x) notation for function call, and (op
> x) for operator.
> > I like to hear from the community what kind of dark corner the
> proposed syntax sugar may run into.
> > Thanks,
> Louis
> > > > > > > > > > -- > 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/cloju

Re: Interested in a port of Ruby's String#unpack

2011-12-26 Thread mrb_bk
I also thought I would mention that I've been hanging out in #clojure
as mrb_bk - please hit me up if you would like to chat about this.

On Dec 26, 10:08 am, mrb_bk  wrote:
> Hey Everyone:
>
> I'm working on a project in Clojure that involves parsing binary data
> files.  Specifically, I'm building a tool for analyzing Redis (http://
> redis.io) dump files (.rdb format).  The very beginnings of this
> nascent project are here:http://github.com/mrb/pianist.  I am a
> beginner to Clojure and Lisp in general, but I'm a long time Ruby
> programmer with experience in C, Java, etc.  During the course of
> working through some Clojure learning materials and general poking
> around the web and #clojure in IRC, I've noticed that one of my
> favorite tools for working with binary data from Ruby is missing in
> the Java/Clojure world.  This is String#unpack:
>
> http://www.ruby-doc.org/core-1.9.3/String.html#method-i-unpack
>
> After a brief Twitter conversation with @abedra, and while I get the
> chance to submit my contributors agreement in order to access Clojure-
> dev, I thought I'd bring this topic up here.
>
> For what it's worth, I've checked out Gloss, which is interesting but
> a bit too opinionated for me.  Plus I believe that something to this
> effect should be part of clojure core - it seems that easy interface
> for lazily handling binary data as seqs doesn't exist as such right
> now.
>
> If anyone has comments on the beginnings of my codebase (be gentle),
> or thoughts about implementing something similar to String#unpack, or
> a suggestion of an alternative set of tools I could use, that would be
> great.  Thanks!
>
> Mike
> twitter.com/mrb_bk
> github.com/mrb

-- 
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: Interested in a port of Ruby's String#unpack

2011-12-26 Thread Geoff Salmon
Hi, does the unpack function in this library do what you're looking
for? https://github.com/geoffsalmon/bytebuffer
It unpacks values from Java's ByteBuffer objects instead of strings,
which seemed more appropriate in Java-land.

I haven't touched the code since Clojure 1.2, but if it looks useful I
can try to bring it up to date.

- Geoff

On Dec 26, 10:03 pm, mrb_bk  wrote:
> I also thought I would mention that I've been hanging out in #clojure
> as mrb_bk - please hit me up if you would like to chat about this.
>
> On Dec 26, 10:08 am, mrb_bk  wrote:
>
>
>
>
>
>
>
> > Hey Everyone:
>
> > I'm working on a project in Clojure that involves parsing binary data
> > files.  Specifically, I'm building a tool for analyzing Redis (http://
> > redis.io) dump files (.rdb format).  The very beginnings of this
> > nascent project are here:http://github.com/mrb/pianist.  I am a
> > beginner to Clojure and Lisp in general, but I'm a long time Ruby
> > programmer with experience in C, Java, etc.  During the course of
> > working through some Clojure learning materials and general poking
> > around the web and #clojure in IRC, I've noticed that one of my
> > favorite tools for working with binary data from Ruby is missing in
> > the Java/Clojure world.  This is String#unpack:
>
> >http://www.ruby-doc.org/core-1.9.3/String.html#method-i-unpack
>
> > After a brief Twitter conversation with @abedra, and while I get the
> > chance to submit my contributors agreement in order to access Clojure-
> > dev, I thought I'd bring this topic up here.
>
> > For what it's worth, I've checked out Gloss, which is interesting but
> > a bit too opinionated for me.  Plus I believe that something to this
> > effect should be part of clojure core - it seems that easy interface
> > for lazily handling binary data as seqs doesn't exist as such right
> > now.
>
> > If anyone has comments on the beginnings of my codebase (be gentle),
> > or thoughts about implementing something similar to String#unpack, or
> > a suggestion of an alternative set of tools I could use, that would be
> > great.  Thanks!
>
> > Mike
> > twitter.com/mrb_bk
> > github.com/mrb

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


Bug in extend-protocol macro? (Clojure 1.3.0)

2011-12-26 Thread Peter Taoussanis
Hi there,

I'm using Clojure 1.3.0 and am running into what seems like an edge-
case problem with extend-protocol (?)...

Given (defprotocol MyProtocol (action [x])),

(extend-protocol MyProtocol
  (Class/forName "[B") (action [x] "ByteArray")
  java.lang.Integer (action [x] "Integer"))

expands to (do (clojure.core/extend-type java.lang.Integer MyProtocol
(action [x] "Integer")) (clojure.core/extend-type (Class/forName "[B")
MyProtocol (action [x] "ByteArray")))

which works as expected. Note the acrobatics to get a byte[] class.


BUT, if I reorder the implementations,

(extend-protocol MyProtocol
  java.lang.Integer (action [x] "Integer")
  (Class/forName "[B") (action [x] "ByteArray"))

the expansion becomes (do (clojure.core/extend-type java.lang.Integer
MyProtocol (action [x] "Integer") (Class/forName "[B") (action [x]
"ByteArray"))), which is malformed.


Am I correct in assuming this isn't the desired behaviour? Thanks!

--
Peter Taoussanis

-- 
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: Bug in extend-protocol macro? (Clojure 1.3.0)

2011-12-26 Thread Alan Malloy
On Dec 26, 10:21 pm, Peter Taoussanis  wrote:
> Hi there,
>
> I'm using Clojure 1.3.0 and am running into what seems like an edge-
> case problem with extend-protocol (?)...
>
> Given (defprotocol MyProtocol (action [x])),
>
> (extend-protocol MyProtocol
>   (Class/forName "[B") (action [x] "ByteArray")
>   java.lang.Integer (action [x] "Integer"))
>
> expands to (do (clojure.core/extend-type java.lang.Integer MyProtocol
> (action [x] "Integer")) (clojure.core/extend-type (Class/forName "[B")
> MyProtocol (action [x] "ByteArray")))
>
> which works as expected. Note the acrobatics to get a byte[] class.
>
> BUT, if I reorder the implementations,
>
> (extend-protocol MyProtocol
>   java.lang.Integer (action [x] "Integer")
>   (Class/forName "[B") (action [x] "ByteArray"))
>
> the expansion becomes (do (clojure.core/extend-type java.lang.Integer
> MyProtocol (action [x] "Integer") (Class/forName "[B") (action [x]
> "ByteArray"))), which is malformed.
>
> Am I correct in assuming this isn't the desired behaviour? Thanks!

extend-protocol groups things by splitting them into seqs and symbols.
(Class/forName "[B") is a seq, so it's an implementation of a protocol
function, not a class. If you want to do these sorts of gymnastics you
can use the underlying extend primitive directly - I believe it just
takes a seq of protocol/impl-map pairs, so you get/have to do the
grouping yourself.

Of course, you could use extend-type instead of extend, but if you
need some expression to figure out which protocol to extend you're in
the same boat AFAIK, which is why I might recommend using extend.

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