Re: scoped local memoize

2010-03-18 Thread Per Vognsen
No, it won't force a GC. But it should be eligible for GC, if that's
what you mean. Hopefully the memo cache will stay in the
generation-zero nursery, in which case it will incur effectively no GC
cost since the nursery collector runs in time O(live objects in
nursey) rather than O(total objects in nursery).

In a Platonic paradise, the cache could even be allocated and freed
without any GC involvement whatosever due to the magic of HotSpot's
escape analysis. But that seldom works as widely in practice as one
might hope and I expect it wouldn't in this example.

-Per

On Fri, Mar 19, 2010 at 1:05 PM, Greg  Fodor  wrote:
> Ah, I think I have the solution:
>
> (defn foo []
>  (let [bar-memoized (memoize bar)]
>    ; Do stuff with bar-memoized
> ))
>
> Seems to work -- to verify, this will GC the memoized cache for bar
> after each call to foo, right?
>
> On Mar 19, 1:56 am, Greg  Fodor  wrote:
>> Hi there -- I am looking for a solution to a particular memoization
>> pattern. I have a function foo that is the entry point of a caller
>> that makes many thousands of calls to a function bar. In calling foo,
>> bar will be called with many different args but there are many
>> repeated calls to bar with the same args.
>>
>> I would like to memoize bar such that the memory used for memoization
>> is GC'ed at the end of the call to foo, and additionally the cache
>> used for memoization is thread local (so no need for heavyweight
>> synchronization tools like atoms, etc.) In Ruby, I would implement
>> this as a simple local hash with the ||= operator through each
>> iteration of a loop inside foo that calls bar.
>>
>> This seems like a fairly common case, so I was wondering if there is
>> an idiom/API to do this for me easily. Alternatively, my first guess
>> is to write a macro that memoizes the function but allows the macro
>> caller to name a dynamic var for the cache which can then be thread-
>> locally bound from the caller side. When the caller var falls out of
>> scope it should be GC'ed. If this makes sense, let me know.
>>
>> 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
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: scoped local memoize

2010-03-18 Thread Greg Fodor
Ah, is there any concern with pummeling that var?

On Mar 19, 2:22 am, Meikel Brandmeyer  wrote:
> Hi,
>
> On Mar 19, 7:05 am, Greg  Fodor  wrote:
>
> > Ah, I think I have the solution:
>
> > (defn foo []
> >   (let [bar-memoized (memoize bar)]
> >     ; Do stuff with bar-memoized
> > ))
>
> > Seems to work -- to verify, this will GC the memoized cache for bar
> > after each call to foo, right?
>
> Yes. I would think so. However, recursive calls in bar to itself will
> not be memoised! You could combine this technique however.
>
> (defn foo
>   []
>   (binding [bar (memoize bar)]
>     ...))
>
> This will also catch recursive calls of bar to itself.
>
> 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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: scoped local memoize

2010-03-18 Thread Meikel Brandmeyer
Hi,

On Mar 19, 7:05 am, Greg  Fodor  wrote:

> Ah, I think I have the solution:
>
> (defn foo []
>   (let [bar-memoized (memoize bar)]
>     ; Do stuff with bar-memoized
> ))
>
> Seems to work -- to verify, this will GC the memoized cache for bar
> after each call to foo, right?

Yes. I would think so. However, recursive calls in bar to itself will
not be memoised! You could combine this technique however.

(defn foo
  []
  (binding [bar (memoize bar)]
...))

This will also catch recursive calls of bar to itself.

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: scoped local memoize

2010-03-18 Thread B Smith-Mannschott
On Fri, Mar 19, 2010 at 06:56, Greg  Fodor  wrote:

> I would like to memoize bar such that the memory used for memoization
> is GC'ed at the end of the call to foo, and additionally the cache
> used for memoization is thread local (so no need for heavyweight
> synchronization tools like atoms, etc.) In Ruby, I would implement
> this as a simple local hash with the ||= operator through each
> iteration of a loop inside foo that calls bar.

;; the "trick" I found is to explicitly deref the var binding the
;; function to be memoized. This way fib's recursive calls will use
;; the memoized binding established in
;; use-fib-memoized-thread-locally.

(defn fib [n]
  (if (> 2 n) n
  (+ (@#'fib (dec n))
 (@#'fib (dec (dec n))

(defn use-fib-memoized-thread-locally [n]
  (binding [fib (memoize fib)]
(fib n)))

;; user> (time (fib 32))
;; "Elapsed time: 1755.796366 msecs"  ;; SLOW
;; 2178309
;;
;; user> (time (use-fib-memoized-thread-locally 32))
;; "Elapsed time: 1.514927 msecs" ;; FAST
;; 2178309
;;
;; user> (time (fib 32))
;; "Elapsed time: 2024.836838 msecs"  ;; SLOW, again
;; 2178309

// Ben

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Java method call irritation

2010-03-18 Thread Laurent PETIT
Hi,

In this particular case, his get-properties macros was a demonstration
of how to write a macro, but could have been replaced with an
out-of-the-box clojure.core/bean call.

2010/3/19 Per Vognsen :
> My experience as a newcomer to Clojure is that one of the most
> surprising things is the dichotomy between the Clojure and JVM world.
>
> I was reading one of Lau's blog posts on converting images to ASCII art:
>
> http://www.bestinclass.dk/index.php/2010/02/my-tribute-to-steve-ballmer
>
> His get-properties macro is only really needed because of this issue
> with methods. If .methods were wrapped up as clojures, you could write
> it directly like this:
>
> ;; General purpose function. Useful whenever you want to reverse the
> sense of function and arguments.
> (defn with-args [& args]
>  #(apply % args))
>
> (map (with-args (.getRGB image 10 10)) [.getRed .getGreen .getBlue])
>
> -Per
>
> On Fri, Mar 19, 2010 at 4:30 AM, Michael Gardner  wrote:
>> On Mar 18, 2010, at 10:55 AM, Per Vognsen wrote:
>>
>>> Is there any reason why a .method occurrence in non-operator position
>>> doesn't just do the closure wrapping automagically?
>>
>> I'd like to know this as well. Smooth Java interop is one of Clojure's 
>> selling points, but having to wrap Java methods in lambdas to use them as 
>> first-class functions feels awkward. Especially if the method in question 
>> has multiple arguments!
>>
>> -Michael
>>
>> --
>> 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
>>
>> To unsubscribe from this group, send email to 
>> clojure+unsubscribegooglegroups.com or reply to this email with the words 
>> "REMOVE ME" as the subject.
>>
>
> --
> 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
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


clojure-mode-like syntax highlighting for the SLIME REPL

2010-03-18 Thread Michał Marczyk
Hi Group,

there was a Stack Overflow question recently re: syntax highlighting
Clojure REPLs. This got me thinking that since I was going to tweak
SLIME REPL font-lock for quite some time now (I find the default a bit
too aggressive), I might as well do it now and have it use
clojure-mode's font-lock settings too.

Here's what I came up with:
http://gist.github.com/337280

I've got some questions in connection with this. Firstly, I'd love to
know whether this could be done in a simpler way. If not, then I
wonder if clojure-mode could move the font-lock setup from the
clojure-mode function itself to something like my
clojure-font-lock-setup function and  then just call that from
clojure-mode? That way a usable syntax highlighting SLIME REPL would
become a one hook affair.

Then there's one thing I didn't try to tackle for now (because it
would actually require me to write font-lock code, which is something
that scares me to death), namely prompt highlighting ("namespace>"
appears in plain text for now). Is there a simple way to add this on
top of clojure-mode font-lock settings?

All the best,
Michał

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: scoped local memoize

2010-03-18 Thread Greg Fodor
Ah, I think I have the solution:

(defn foo []
  (let [bar-memoized (memoize bar)]
; Do stuff with bar-memoized
))

Seems to work -- to verify, this will GC the memoized cache for bar
after each call to foo, right?

On Mar 19, 1:56 am, Greg  Fodor  wrote:
> Hi there -- I am looking for a solution to a particular memoization
> pattern. I have a function foo that is the entry point of a caller
> that makes many thousands of calls to a function bar. In calling foo,
> bar will be called with many different args but there are many
> repeated calls to bar with the same args.
>
> I would like to memoize bar such that the memory used for memoization
> is GC'ed at the end of the call to foo, and additionally the cache
> used for memoization is thread local (so no need for heavyweight
> synchronization tools like atoms, etc.) In Ruby, I would implement
> this as a simple local hash with the ||= operator through each
> iteration of a loop inside foo that calls bar.
>
> This seems like a fairly common case, so I was wondering if there is
> an idiom/API to do this for me easily. Alternatively, my first guess
> is to write a macro that memoizes the function but allows the macro
> caller to name a dynamic var for the cache which can then be thread-
> locally bound from the caller side. When the caller var falls out of
> scope it should be GC'ed. If this makes sense, let me know.
>
> 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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


scoped local memoize

2010-03-18 Thread Greg Fodor
Hi there -- I am looking for a solution to a particular memoization
pattern. I have a function foo that is the entry point of a caller
that makes many thousands of calls to a function bar. In calling foo,
bar will be called with many different args but there are many
repeated calls to bar with the same args.

I would like to memoize bar such that the memory used for memoization
is GC'ed at the end of the call to foo, and additionally the cache
used for memoization is thread local (so no need for heavyweight
synchronization tools like atoms, etc.) In Ruby, I would implement
this as a simple local hash with the ||= operator through each
iteration of a loop inside foo that calls bar.

This seems like a fairly common case, so I was wondering if there is
an idiom/API to do this for me easily. Alternatively, my first guess
is to write a macro that memoizes the function but allows the macro
caller to name a dynamic var for the cache which can then be thread-
locally bound from the caller side. When the caller var falls out of
scope it should be GC'ed. If this makes sense, let me know.

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: type hint puzzler

2010-03-18 Thread Per Vognsen
My guess from looking at the API documentation for ResultSet is that
it doesn't know which of the several one-parameter overloads of
getObject to choose. Presumably you want the integer one, so try
(.getObject rs (int i)).

-Per

On Fri, Mar 19, 2010 at 12:08 PM, cageface  wrote:
> I'm trying to eliminate some reflection overhead in little SQL utility
> I'm working on and can't seem to get the type hint right for this
> code:
>
> (import 'java.sql.ResultSet)
>
> (set! *warn-on-reflection* true)
>
> (defn rs-get-row [#^ResultSet rs]
>  (if (.next rs)
>    (let [cols (.. rs getMetaData getColumnCount)]
>      (doall (for [i (range 1 (+ 1 cols))]
>               (.getObject rs i
>    nil))
>
> When I run this I get this warning:
> Reflection warning, /tmp/simple.clj:11 - call to getObject can't be
> resolved.
> Reflection warning, /tmp/simple.clj:11 - call to getObject can't be
> resolved.
>
> Is the #^ResultSet hint correct? If so, what else do I need to do to
> resolve this?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> 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
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


type hint puzzler

2010-03-18 Thread cageface
I'm trying to eliminate some reflection overhead in little SQL utility
I'm working on and can't seem to get the type hint right for this
code:

(import 'java.sql.ResultSet)

(set! *warn-on-reflection* true)

(defn rs-get-row [#^ResultSet rs]
  (if (.next rs)
(let [cols (.. rs getMetaData getColumnCount)]
  (doall (for [i (range 1 (+ 1 cols))]
   (.getObject rs i
nil))

When I run this I get this warning:
Reflection warning, /tmp/simple.clj:11 - call to getObject can't be
resolved.
Reflection warning, /tmp/simple.clj:11 - call to getObject can't be
resolved.

Is the #^ResultSet hint correct? If so, what else do I need to do to
resolve this?

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Java method call irritation

2010-03-18 Thread Per Vognsen
My experience as a newcomer to Clojure is that one of the most
surprising things is the dichotomy between the Clojure and JVM world.

I was reading one of Lau's blog posts on converting images to ASCII art:

http://www.bestinclass.dk/index.php/2010/02/my-tribute-to-steve-ballmer

His get-properties macro is only really needed because of this issue
with methods. If .methods were wrapped up as clojures, you could write
it directly like this:

;; General purpose function. Useful whenever you want to reverse the
sense of function and arguments.
(defn with-args [& args]
  #(apply % args))

(map (with-args (.getRGB image 10 10)) [.getRed .getGreen .getBlue])

-Per

On Fri, Mar 19, 2010 at 4:30 AM, Michael Gardner  wrote:
> On Mar 18, 2010, at 10:55 AM, Per Vognsen wrote:
>
>> Is there any reason why a .method occurrence in non-operator position
>> doesn't just do the closure wrapping automagically?
>
> I'd like to know this as well. Smooth Java interop is one of Clojure's 
> selling points, but having to wrap Java methods in lambdas to use them as 
> first-class functions feels awkward. Especially if the method in question has 
> multiple arguments!
>
> -Michael
>
> --
> 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
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Name suggestions

2010-03-18 Thread Zach Tellman
how about 'patois' or 'creole'

On Mar 17, 12:08 am, mac  wrote:
> After just a little more test and polish I plan on calling clj-native
> 1.0. But clj-native is a *really* boring name so I want to change it
> before 1.0 and I don't have very good imagination when it comes to
> these things.
> So I need your help.
> It doesn't have to have anything to do with anything, could just be
> something that sounds funny, like sasquatch, that's a funny word.
>
> Please help!
>
> /Markus
>
> On 13 mar, 19:14, mac  wrote:
>
>
>
> > Hello all.
> > I have had some time lately to work on my C FFI for Clojure and I
> > think it's pretty much feature complete now.
> > It has support for functions, callbacks, structures, unions and
> > globals.
> > For structures there is support for different alignments.
>
> > The library has two main namespaces: clj-native.direct and clj-
> > native.dynamic.
> > The direct namespace uses the "direct mapping" feature of JNA in order
> > to be as efficient and arity and type safe as possible. However, it
> > does not support varargs functions since they require reflection and
> > dynamic translation of the parameters. That's what the dynamic
> > namespace is for: It can map any C function into clojure, even vararg
> > functions like printf but at a higher cost in call time and less
> > safety (it's easy to crash the jvm by sending the wrong type or number
> > of parameters). Access to global variables through the JNA Pointer
> > class is also available in the dynamic namespace.
>
> > The library is available from github:http://github.com/bagucode/clj-native
> > and clojars:http://clojars.org/clj-native
>
> > Example usage of the direct namespace can be found 
> > here:http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
>
> > Please report issues or make requests to my github account or by mail.
>
> > Enjoy!
>
> > /Markus

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Web Programming with clojure

2010-03-18 Thread Tim Johnson
* LauJensen  [100318 00:26]:
> Hey Tim,
> 
> Welcome - I might be restating, but this should get you going quickly:
 Oh that's great Lau!
 I have been looking at your videos and was wondering where I could
 find text instructions 
   (see my posting subject: "Clojure 101 - Slime installation") 
   so I think my questions in that posting are answered. 

> Getting ready: 
> http://www.bestinclass.dk/index.php/2009/12/clojure-101-getting-clojure-slime-installed/
> Doing simple pages: 
> http://www.bestinclass.dk/index.php/2009/12/beating-the-arc-challenge-in-clojure/
> Including SQL: 
> http://www.bestinclass.dk/index.php/2009/12/dynamic-interactive-webdevelopment/
> Making a simple Reddit clone:
> http://www.bestinclass.dk/index.php/2010/02/reddit-clone-in-10-minutes-and-91-lines-of-clojure/
> ..and extending that with a user database:
> http://www.bestinclass.dk/index.php/2010/02/reddit-clone-with-user-registration/
> 
> I wrote them in a style which targets new-comers, so I hope it will be
> of some help.
> Lau
 I know they will.
 Thanks
 cheers
-- 
Tim 
t...@johnsons-web.com
http://www.akwebsoft.com

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Translation from Common Lisp 1

2010-03-18 Thread Richard Newman

But using symbols for something like this is a bit contrived anyway.


Maybe, but I've seen it in other Common Lisp books/tutorials before.
e.g. I'm sure PAIP was one of them.


Part of the motivation is that CL symbols always compare with EQ and  
EQL, whilst strings are not required to do so:


cl-user(9): (eq (concatenate 'string "foo" "bar") "foobar")
nil

This means you can use nice constructs such as CASE with symbols, but  
you need to roll your own using string-equal or string= to handle  
strings.


(Using symbols also saves you typing all those double-quote  
characters, as well as saving memory and computation during  
comparison: symbols are interned, unlike strings.)


In Clojure (thanks to Java's immutable interned strings) strings  
compare efficiently with = just like everything else, so there's less  
motivation.


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

To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or 
reply to this email with the words "REMOVE ME" as the subject.


Re: Translation from Common Lisp 1

2010-03-18 Thread Brian Schlining
> Yes, of course, thats what a sane person would do ;-)
>
> I mentioned in my later post, this usage of symbols as data is 1. non-
> idiomatic but 2. really illuminating for somebody with Java
> background.
> Well, and its what this tutorial does.
>
> Nevertheless thank you for the answer!
>
>
Ha, my bad! But ouch, LISP makes my head hurt ;-)
-- 
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Brian Schlining
bschlin...@gmail.com

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Translation from Common Lisp 1

2010-03-18 Thread Michael Wood
On 18 March 2010 23:40, Michael Gardner  wrote:
> On Mar 18, 2010, at 4:17 PM, David Nolen wrote:
>
>> On Thu, Mar 18, 2010 at 4:25 PM, alux  wrote:
>> Hello!
>>
>> I much enjoyed reading the tutorial http://www.lisperati.com/casting.html
>> , mentioned by eyeris today. The most mind-extending thing (to me,
>> having Java background) is the, admittedly non-idiomatic, use of
>> symbols as data.
>>
>> But I have two translation problems, I want to pose before going to
>> sleep (its pitch dark in Europe :). First the easy one:
>>
>> Common Lisp
>> (defun describe-path (path)
>>  `(there is a ,(second path) going ,(first path) from here.))
>>
>> You probably want
>>
>> (defn describe-path [path]
>>    `(~'there ~'is ~'a ~(second path) ~'going ~(first path) ~'from ~'here))
>
> Or just:
>
> (defn describe-path [path]
>    ['there 'is 'a (second path) 'path 'going (first path) 'from 'here])
>
> But using symbols for something like this is a bit contrived anyway.

Maybe, but I've seen it in other Common Lisp books/tutorials before.
e.g. I'm sure PAIP was one of them.

-- 
Michael Wood 

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Translation from Common Lisp 2

2010-03-18 Thread Michael Wood
On 18 March 2010 23:40, Dave M  wrote:
> ...
>
>> (game-action weld chain bucket attic
>>          (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn
>                ^
> Your if-condition is nested one form too deeply; try "(if (and (have
> 'bucket) ...) ...)"
>
> I haven't tried it, so there might be other problems.

Oh right, yes, I didn't notice before your message that he had "(if
((and ..." in his game-action macro :)

-- 
Michael Wood 

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Translation from Common Lisp 2

2010-03-18 Thread Dave M
...

> (game-action weld chain bucket attic
>          (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn
^
Your if-condition is nested one form too deeply; try "(if (and (have
'bucket) ...) ...)"

I haven't tried it, so there might be other problems.

-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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Translation from Common Lisp 1

2010-03-18 Thread Michael Gardner
On Mar 18, 2010, at 4:17 PM, David Nolen wrote:

> On Thu, Mar 18, 2010 at 4:25 PM, alux  wrote:
> Hello!
> 
> I much enjoyed reading the tutorial http://www.lisperati.com/casting.html
> , mentioned by eyeris today. The most mind-extending thing (to me,
> having Java background) is the, admittedly non-idiomatic, use of
> symbols as data.
> 
> But I have two translation problems, I want to pose before going to
> sleep (its pitch dark in Europe :). First the easy one:
> 
> Common Lisp
> (defun describe-path (path)
>  `(there is a ,(second path) going ,(first path) from here.))
> 
> You probably want
> 
> (defn describe-path [path]
>`(~'there ~'is ~'a ~(second path) ~'going ~(first path) ~'from ~'here)) 

Or just:

(defn describe-path [path]
['there 'is 'a (second path) 'path 'going (first path) 'from 'here])

But using symbols for something like this is a bit contrived anyway.

-Michael

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Montreal Clojure User Group

2010-03-18 Thread Michael Kohl
Don't want to start my own thread, so here goes: we are starting a
functional programming user group in Vienna that - judging by the
people who showed interest so far - will probably be quite heavy on
all things Lisp, so it'd be nice if you could include that too:

http://metalab.at/wiki/Lambdaheads

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Translation from Common Lisp 2

2010-03-18 Thread Michael Wood
On 18 March 2010 22:38, alux  wrote:
> Again, from my translation of the http://www.lisperati.com/casting.html
> tutorial.
>
> I completely lost track at the macro generating macro (defspel game-
> action ..
>
> In short, Barski writes a very simple (and neat) text adventure. To
> avoid wrong assumtions he doesnt talk about macros but SPELs, using
>
> CL (defmacro defspel (&rest rest) `(defmacro ,@rest))
> Clj (defmacro defspel [& rest] `(defmacro ~...@rest))
>
> I translated everything up to the last page 
> http://www.lisperati.com/actions.html,
> then he arrives at
>
> (defspel game-action (command subj obj place &rest rest)
>  `(defspel ,command (subject object)
>     `(cond ((and (eq *location* ',',place)
>                  (eq ',subject ',',subj)
>                  (eq ',object ',',obj)
>                  (have ',',subj))
>             ,@',rest)
>            (t '(i cant ,',command like that.)
>
> Without CL knowledge, I dont really understand whats going on, but
> gave a try (please dont lough to hard :)
>
> (defspel game-action [command subj obj place & rest]
>  `(defspel ~command [subject# object#]
>     `(if ((and (= *location* '~'~place)
>                  (= '~subject# '~'~subj)
>                  (= '~object# '~'~obj)
>                  (have '~'~subj))
>             ~@'~rest)
>            '(i cant ~'~command like that.
>
> use
>
> (game-action weld chain bucket attic
>         (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn
> [_] true)))
>                   '(the chain is now securely welded to the bucket.))
>                   '(you do not have a bucket.)))
>
> If I try it, I get
>
> spels=> (weld chain bucket)
> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
> clojure.lang.I
> Fn (NO_SOURCE_FILE:0)
>
> And I'm stuck.

I've just had a brief look and I can't say where it's coming from, but
if you try:

(macroexpand-1 '(weld chain bucket))

You get something like this (after some cleanup):

(if ((and (= *location* 'attic) (= 'chain 'chain) (= 'bucket 'bucket)
(have 'chain)) (if ((and ...

Those ((and ...)) are the problem.  (and ...) will return true or false.
(true) or (false) are invalid because they are true and false are not
functions (i.e. they don't implement the clojure.lang.IFn interface.)
So ((and ...)) is trying to treat a boolean as a function, which
explains the exception.

By the way, you might want to use keywords like :chain instead of
symbols.  Also your (fn [_] true) could be replaced by (constantly
true).  It's not exactly the same, because (constantly true) is more
like (fn [& rest] true), but it should be close enough.  :)

-- 
Michael Wood 

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Java method call irritation

2010-03-18 Thread Michael Gardner
On Mar 18, 2010, at 10:55 AM, Per Vognsen wrote:

> Is there any reason why a .method occurrence in non-operator position
> doesn't just do the closure wrapping automagically?

I'd like to know this as well. Smooth Java interop is one of Clojure's selling 
points, but having to wrap Java methods in lambdas to use them as first-class 
functions feels awkward. Especially if the method in question has multiple 
arguments!

-Michael

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Translation from Common Lisp 1

2010-03-18 Thread David Nolen
On Thu, Mar 18, 2010 at 4:25 PM, alux  wrote:

> Hello!
>
> I much enjoyed reading the tutorial http://www.lisperati.com/casting.html
> , mentioned by eyeris today. The most mind-extending thing (to me,
> having Java background) is the, admittedly non-idiomatic, use of
> symbols as data.
>
> But I have two translation problems, I want to pose before going to
> sleep (its pitch dark in Europe :). First the easy one:
>
> Common Lisp
> (defun describe-path (path)
>  `(there is a ,(second path) going ,(first path) from here.))
>

You probably want

(defn describe-path [path]
   `(~'there ~'is ~'a ~(second path) ~'going ~(first path) ~'from ~'here))

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Broken JSON API in clojure-contrib?

2010-03-18 Thread Michael Wood
On 18 March 2010 20:31, Timothy Washington  wrote:
> Too right. Thanks very much friend.

No problem :)

> On Wed, Mar 17, 2010 at 3:25 PM, Michael Wood  wrote:
>>
>> On 17 March 2010 21:18, Michael Wood  wrote:
>> [...]
>> > $ java -cp clojure-1.1.0.jar:clojure-contrib.jar clojure.mainClojure
>> > 1.1.0
>> [...]
>>
>> Whoops!  Not sure what happened there.  That's of course supposed to be:
>>
>> $ java -cp clojure-1.1.0.jar:clojure-contrib.jar clojure.main
>> Clojure 1.1.0
>>
>> but I'm sure nobody was confused :)

-- 
Michael Wood 

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Translation from Common Lisp 1

2010-03-18 Thread alux
Hello Fons,

(my former answer was to Brian)

I tried this one, actually. But the result is really used as output of
the adventure 'game' here. So the namespace prefix must not be there.

Thank you for the answer, alux

On 18 Mrz., 21:50, fons haffmans  wrote:
> I just did this :
>
> (defn describe-path [path]
>   `(there is a ,(second path) going ,(first path) from here.))
>
> which gives me :
> (describe-path (list "left" "right"))
> (user/there user/is user/a (clojure.core/second user/path) user/going
> (clojure.core/first user/path) user/from here.)
>
> Sure, it prepends the namespace to the symbol. Is that the issue ?
> I thats the the case I guess you can use something like (concat...).
>
> On Thu, Mar 18, 2010 at 4:25 PM, alux  wrote:
> > Hello!
>
> > I much enjoyed reading the tutorialhttp://www.lisperati.com/casting.html
> > , mentioned by eyeris today. The most mind-extending thing (to me,
> > having Java background) is the, admittedly non-idiomatic, use of
> > symbols as data.
>
> > But I have two translation problems, I want to pose before going to
> > sleep (its pitch dark in Europe :). First the easy one:
>
> > Common Lisp
> > (defun describe-path (path)
> >  `(there is a ,(second path) going ,(first path) from here.))
>
> > My Clojure version, I use a map:
> > (defn describe-path [path]
> >        (let [what (path :kind) where (path :direction)]
> >    (concat '(there is a) (list what) '(going) (list where) '(from
> > here.
>
> > Thats much less elegant. Is there a nicer way?
>
> > Thank you, alux
>
> > --
> > 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
>
> > To unsubscribe from this group, send email to clojure+
> > unsubscribegooglegroups.com or reply to this email with the words "REMOVE
> > ME" as the subject.

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Translation from Common Lisp 1

2010-03-18 Thread alux
Yes, of course, thats what a sane person would do ;-)

I mentioned in my later post, this usage of symbols as data is 1. non-
idiomatic but 2. really illuminating for somebody with Java
background.
Well, and its what this tutorial does.

Nevertheless thank you for the answer!

Kind regards, alux


On 18 Mrz., 21:49, Brian Schlining  wrote:
> > But I have two translation problems, I want to pose before going to
> > sleep (its pitch dark in Europe :). First the easy one:
>
> > Common Lisp
> > (defun describe-path (path)
> >  `(there is a ,(second path) going ,(first path) from here.))
>
> > My Clojure version, I use a map:
> > (defn describe-path [path]
> >        (let [what (path :kind) where (path :direction)]
> >    (concat '(there is a) (list what) '(going) (list where) '(from
> > here.
>
> > Thats much less elegant. Is there a nicer way?
>
> It looks like you really want a formated string (concat returns a sequence
> not a string). You could use:
>
> (defn describe-path [path]
>     (format "this is a, %s, going, %s, from here" (path :kind) (path
> :direction)))
>
> --
> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
> Brian Schlining

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Translation from Common Lisp 1

2010-03-18 Thread fons haffmans
I just did this :


(defn describe-path [path]
  `(there is a ,(second path) going ,(first path) from here.))

which gives me :
(describe-path (list "left" "right"))
(user/there user/is user/a (clojure.core/second user/path) user/going
(clojure.core/first user/path) user/from here.)

Sure, it prepends the namespace to the symbol. Is that the issue ?
I thats the the case I guess you can use something like (concat...).

On Thu, Mar 18, 2010 at 4:25 PM, alux  wrote:

> Hello!
>
> I much enjoyed reading the tutorial http://www.lisperati.com/casting.html
> , mentioned by eyeris today. The most mind-extending thing (to me,
> having Java background) is the, admittedly non-idiomatic, use of
> symbols as data.
>
> But I have two translation problems, I want to pose before going to
> sleep (its pitch dark in Europe :). First the easy one:
>
> Common Lisp
> (defun describe-path (path)
>  `(there is a ,(second path) going ,(first path) from here.))
>
> My Clojure version, I use a map:
> (defn describe-path [path]
>(let [what (path :kind) where (path :direction)]
>(concat '(there is a) (list what) '(going) (list where) '(from
> here.
>
> Thats much less elegant. Is there a nicer way?
>
> Thank you, alux
>
> --
> 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
>
> To unsubscribe from this group, send email to clojure+
> unsubscribegooglegroups.com or reply to this email with the words "REMOVE
> ME" as the subject.
>

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Translation from Common Lisp 1

2010-03-18 Thread Brian Schlining
>
> But I have two translation problems, I want to pose before going to
> sleep (its pitch dark in Europe :). First the easy one:
>
> Common Lisp
> (defun describe-path (path)
>  `(there is a ,(second path) going ,(first path) from here.))
>
> My Clojure version, I use a map:
> (defn describe-path [path]
>(let [what (path :kind) where (path :direction)]
>(concat '(there is a) (list what) '(going) (list where) '(from
> here.
>
> Thats much less elegant. Is there a nicer way?
>

It looks like you really want a formated string (concat returns a sequence
not a string). You could use:

(defn describe-path [path]
(format "this is a, %s, going, %s, from here" (path :kind) (path
:direction)))

-- 
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Brian Schlining

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Translation from Common Lisp 2

2010-03-18 Thread alux
Again, from my translation of the http://www.lisperati.com/casting.html
tutorial.

I completely lost track at the macro generating macro (defspel game-
action ..

In short, Barski writes a very simple (and neat) text adventure. To
avoid wrong assumtions he doesnt talk about macros but SPELs, using

CL (defmacro defspel (&rest rest) `(defmacro ,@rest))
Clj (defmacro defspel [& rest] `(defmacro ~...@rest))

I translated everything up to the last page 
http://www.lisperati.com/actions.html,
then he arrives at

(defspel game-action (command subj obj place &rest rest)
  `(defspel ,command (subject object)
 `(cond ((and (eq *location* ',',place)
  (eq ',subject ',',subj)
  (eq ',object ',',obj)
  (have ',',subj))
 ,@',rest)
(t '(i cant ,',command like that.)

Without CL knowledge, I dont really understand whats going on, but
gave a try (please dont lough to hard :)

(defspel game-action [command subj obj place & rest]
  `(defspel ~command [subject# object#]
 `(if ((and (= *location* '~'~place)
  (= '~subject# '~'~subj)
  (= '~object# '~'~obj)
  (have '~'~subj))
 ~@'~rest)
'(i cant ~'~command like that.

use

(game-action weld chain bucket attic
 (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn
[_] true)))
   '(the chain is now securely welded to the bucket.))
   '(you do not have a bucket.)))

If I try it, I get

spels=> (weld chain bucket)
java.lang.ClassCastException: java.lang.Boolean cannot be cast to
clojure.lang.I
Fn (NO_SOURCE_FILE:0)

And I'm stuck.

My whole try is here: http://paste.lisp.org/+22IH

Many thanks and a good night.

alux

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Translation from Common Lisp 1

2010-03-18 Thread alux
Hello!

I much enjoyed reading the tutorial http://www.lisperati.com/casting.html
, mentioned by eyeris today. The most mind-extending thing (to me,
having Java background) is the, admittedly non-idiomatic, use of
symbols as data.

But I have two translation problems, I want to pose before going to
sleep (its pitch dark in Europe :). First the easy one:

Common Lisp
(defun describe-path (path)
  `(there is a ,(second path) going ,(first path) from here.))

My Clojure version, I use a map:
(defn describe-path [path]
(let [what (path :kind) where (path :direction)]
(concat '(there is a) (list what) '(going) (list where) '(from
here.

Thats much less elegant. Is there a nicer way?

Thank you, alux

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Simple functional programming lexicon?

2010-03-18 Thread Ben Armstrong

On 18/03/10 06:57 AM, Michael Kohl wrote:

There's a really nice article series on monads in Clojure:

http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure-programmers-part-1/
   


Oh, wow!  Lucidly written.  And it gives me something, maybe-m, that I 
can't believe I got along without before.  I'm eager now to continue 
with part 2 ...



Also the "Learn you a Haskell for Great Good" tutorial is a pretty
nice and light-hearted introduction to FP with Haskell which might
also help you to understand some of the concepts better:

http://learnyouahaskell.com/
   


I've filed this one away.  I had better stick with clojure for now until 
I get more comfortable with it.  Thanks. :)


Ben

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

To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or 
reply to this email with the words "REMOVE ME" as the subject.


Re: Java method call irritation

2010-03-18 Thread Sean Devlin
And upgrade the doc macro accordingly?  That would make entirely too
much sense.

+1

On Mar 18, 2:36 pm, Seth  wrote:
> Would :deprecated be a reasonable thing to include in a function's
> metadata? Just the presence of it seems good enough, but I guess
> pairing it with some programmer friendly message ("hey, use bar
> instead of foo") might be nice.
>
> Or... maybe 10,000 lines of XML as metadata! :-)
>
> On Mar 18, 10:50 am, Stuart Halloway 
> wrote:
>
> > memfn is from the depths of time and should be deprecated -- it is  
> > idiomatic to write an anonymous fn around the method.
>
> > Stu
>
> > > This seems like a potential usecase for (memfn):
>
> > > -
> > > clojure.core/memfn
> > > ([name & args])
> > > Macro
> > >  Expands into code that creates a fn that expects to be passed an
> > >  object and any args and calls the named instance method on the
> > >  object passing the args. Use when you want to treat a Java method as
> > >  a first-class fn.
>
> > > user> (= (map (memfn getName) (-> (Runtime/
> > > getRuntime) .getClass .getMethods seq))
> > >         (map #(.getName %) (-> (Runtime/
> > > getRuntime) .getClass .getMethods seq)))
> > > true
>
> > > On Mar 18, 6:21 am, Meikel Brandmeyer  wrote:
> > >> Hi,
>
> > >> Java methods are not clojure functions. To treat them like first-
> > >> class
> > >> functions you have to wrap them in clojure functions as you did in
> > >> your second example.
>
> > >> For your actual task: you might want to look at clojure.contrib.repl-
> > >> utils/show.
>
> > >> 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-Hide quoted text -
>
> > - Show quoted text -

-- 
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 101 - Slime installation

2010-03-18 Thread Tim Johnson
See http://vimeo.com/8398020
Great video!

But, it would be great if I could capture the *text* of the video,
(if available) that would be very helpful in referrencing Lau's
instructions

Anyone know how to do that?

thanks
-- 
Tim 
t...@johnsons-web.com
http://www.akwebsoft.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Java method call irritation

2010-03-18 Thread Seth
Would :deprecated be a reasonable thing to include in a function's
metadata? Just the presence of it seems good enough, but I guess
pairing it with some programmer friendly message ("hey, use bar
instead of foo") might be nice.

Or... maybe 10,000 lines of XML as metadata! :-)

On Mar 18, 10:50 am, Stuart Halloway 
wrote:
> memfn is from the depths of time and should be deprecated -- it is  
> idiomatic to write an anonymous fn around the method.
>
> Stu
>
>
>
> > This seems like a potential usecase for (memfn):
>
> > -
> > clojure.core/memfn
> > ([name & args])
> > Macro
> >  Expands into code that creates a fn that expects to be passed an
> >  object and any args and calls the named instance method on the
> >  object passing the args. Use when you want to treat a Java method as
> >  a first-class fn.
>
> > user> (= (map (memfn getName) (-> (Runtime/
> > getRuntime) .getClass .getMethods seq))
> >         (map #(.getName %) (-> (Runtime/
> > getRuntime) .getClass .getMethods seq)))
> > true
>
> > On Mar 18, 6:21 am, Meikel Brandmeyer  wrote:
> >> Hi,
>
> >> Java methods are not clojure functions. To treat them like first-
> >> class
> >> functions you have to wrap them in clojure functions as you did in
> >> your second example.
>
> >> For your actual task: you might want to look at clojure.contrib.repl-
> >> utils/show.
>
> >> 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- Hide quoted text -
>
> - Show quoted text -

-- 
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: Broken JSON API in clojure-contrib?

2010-03-18 Thread Timothy Washington
Too right. Thanks very much friend.

Tim


On Wed, Mar 17, 2010 at 3:25 PM, Michael Wood  wrote:

> On 17 March 2010 21:18, Michael Wood  wrote:
> [...]
> > $ java -cp clojure-1.1.0.jar:clojure-contrib.jar clojure.mainClojure
> 1.1.0
> [...]
>
> Whoops!  Not sure what happened there.  That's of course supposed to be:
>
> $ java -cp clojure-1.1.0.jar:clojure-contrib.jar clojure.main
> Clojure 1.1.0
>
> but I'm sure nobody was confused :)
>
> --
> Michael Wood 
>
> --
> 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: clj-native 0.8.1

2010-03-18 Thread eyeris
clj-segfault

j/k :)

Seriously though, thank you for working on this. I'm sure it will
remove a serious barrier to entry for some people.



On Mar 13, 1:14 pm, mac  wrote:
> Hello all.
> I have had some time lately to work on my C FFI for Clojure and I
> think it's pretty much feature complete now.
> It has support for functions, callbacks, structures, unions and
> globals.
> For structures there is support for different alignments.
>
> The library has two main namespaces: clj-native.direct and clj-
> native.dynamic.
> The direct namespace uses the "direct mapping" feature of JNA in order
> to be as efficient and arity and type safe as possible. However, it
> does not support varargs functions since they require reflection and
> dynamic translation of the parameters. That's what the dynamic
> namespace is for: It can map any C function into clojure, even vararg
> functions like printf but at a higher cost in call time and less
> safety (it's easy to crash the jvm by sending the wrong type or number
> of parameters). Access to global variables through the JNA Pointer
> class is also available in the dynamic namespace.
>
> The library is available from github:http://github.com/bagucode/clj-native
> and clojars:http://clojars.org/clj-native
>
> Example usage of the direct namespace can be found 
> here:http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
>
> Please report issues or make requests to my github account or by mail.
>
> Enjoy!
>
> /Markus

-- 
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: Java method call irritation

2010-03-18 Thread Per Vognsen
Is there any reason why a .method occurrence in non-operator position
doesn't just do the closure wrapping automagically?

-Per

On Thu, Mar 18, 2010 at 9:50 PM, Stuart Halloway
 wrote:
> memfn is from the depths of time and should be deprecated -- it is idiomatic
> to write an anonymous fn around the method.
>
> Stu
>
>> This seems like a potential usecase for (memfn):
>>
>> -
>> clojure.core/memfn
>> ([name & args])
>> Macro
>>  Expands into code that creates a fn that expects to be passed an
>>  object and any args and calls the named instance method on the
>>  object passing the args. Use when you want to treat a Java method as
>>  a first-class fn.
>>
>> user> (= (map (memfn getName) (-> (Runtime/
>> getRuntime) .getClass .getMethods seq))
>>        (map #(.getName %) (-> (Runtime/
>> getRuntime) .getClass .getMethods seq)))
>> true
>>
>>
>> On Mar 18, 6:21 am, Meikel Brandmeyer  wrote:
>>>
>>> Hi,
>>>
>>> Java methods are not clojure functions. To treat them like first-class
>>> functions you have to wrap them in clojure functions as you did in
>>> your second example.
>>>
>>> For your actual task: you might want to look at clojure.contrib.repl-
>>> utils/show.
>>>
>>> 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
>
> --
> 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: reload of REPL init file

2010-03-18 Thread alux
Many thanks, all questions I had are answered. And some I didn't have
but should!

Greetings, alux

On 18 Mrz., 14:25, Meikel Brandmeyer  wrote:
> Hi,
>
> On Mar 18, 12:06 pm, alux  wrote:
>
> > is there a possibility to reload a clj-file that has been provided at
> > the REPL-start via -i filename.clj ? (It doesn't have a name space.)
>
> > This would save me to provide a namespace in the file an thus type (ns
> > my-ns) after every REPL start.
>
> I understand you, that you don't mean "reload" in the sense of
> "reading the file and evaluating its contents", but as "change to the
> namespace defined in the file". If this is true: java -cp clojure.jar -
> i foo.clj -e "(in-ns  'foo)" -r
>
> Reloading the file in the first sense, is done via load-file or (if
> the file is on the classpath in the correct directory)
> (require :reload 'foo).
>
> Note: ns is only to initially define the namespace. To change the
> namespace use in-ns.
>
> 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: Name suggestions

2010-03-18 Thread Edmund Jackson
I love the reference,  but I dunno dude, the word itself sounds venereal !

On 18 Mar 2010, at 14:36, Alexandre Patry wrote:

> 
>>> On Wed, Mar 17, 2010 at 3:08 AM, mac  wrote:
>>>
 After just a little more test and polish I plan on calling clj-native
 1.0. But clj-native is a *really* boring name so I want to change it
 before 1.0 and I don't have very good imagination when it comes to
 these things.
 So I need your help.
 It doesn't have to have anything to do with anything, could just be
 something that sounds funny, like sasquatch, that's a funny word.
> What about cocytus, the deepest level of hell in Dante's inferno.  I guess 
> you cannot go lower level than that :)  And it reflect the pain of leaving 
> clojure to write native code.
> 
> There are also the clo-cytus or clocytus variations.
> 
> Alexandre
> 
> -- 
> 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

  Edmund

"Do it with love, l-o-v-e"
MJ




-- 
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: Java method call irritation

2010-03-18 Thread Stuart Halloway
memfn is from the depths of time and should be deprecated -- it is  
idiomatic to write an anonymous fn around the method.


Stu


This seems like a potential usecase for (memfn):

-
clojure.core/memfn
([name & args])
Macro
 Expands into code that creates a fn that expects to be passed an
 object and any args and calls the named instance method on the
 object passing the args. Use when you want to treat a Java method as
 a first-class fn.

user> (= (map (memfn getName) (-> (Runtime/
getRuntime) .getClass .getMethods seq))
(map #(.getName %) (-> (Runtime/
getRuntime) .getClass .getMethods seq)))
true


On Mar 18, 6:21 am, Meikel Brandmeyer  wrote:

Hi,

Java methods are not clojure functions. To treat them like first- 
class

functions you have to wrap them in clojure functions as you did in
your second example.

For your actual task: you might want to look at clojure.contrib.repl-
utils/show.

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


--
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: Name suggestions

2010-03-18 Thread Alexandre Patry



On Wed, Mar 17, 2010 at 3:08 AM, mac  wrote:


After just a little more test and polish I plan on calling clj-native
1.0. But clj-native is a *really* boring name so I want to change it
before 1.0 and I don't have very good imagination when it comes to
these things.
So I need your help.
It doesn't have to have anything to do with anything, could just be
something that sounds funny, like sasquatch, that's a funny word.
What about cocytus, the deepest level of hell in Dante's inferno.  I 
guess you cannot go lower level than that :)  And it reflect the pain of 
leaving clojure to write native code.


There are also the clo-cytus or clocytus variations.

Alexandre

--
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: Name suggestions

2010-03-18 Thread Martin DeMello
C-Foam

martin

On Wed, Mar 17, 2010 at 12:38 PM, mac  wrote:
> After just a little more test and polish I plan on calling clj-native
> 1.0. But clj-native is a *really* boring name so I want to change it
> before 1.0 and I don't have very good imagination when it comes to
> these things.
> So I need your help.
> It doesn't have to have anything to do with anything, could just be
> something that sounds funny, like sasquatch, that's a funny word.
>
> Please help!
>
> /Markus
>
> On 13 mar, 19:14, mac  wrote:
>> Hello all.
>> I have had some time lately to work on my C FFI for Clojure and I
>> think it's pretty much feature complete now.
>> It has support for functions, callbacks, structures, unions and
>> globals.
>> For structures there is support for different alignments.
>>
>> The library has two main namespaces: clj-native.direct and clj-
>> native.dynamic.
>> The direct namespace uses the "direct mapping" feature of JNA in order
>> to be as efficient and arity and type safe as possible. However, it
>> does not support varargs functions since they require reflection and
>> dynamic translation of the parameters. That's what the dynamic
>> namespace is for: It can map any C function into clojure, even vararg
>> functions like printf but at a higher cost in call time and less
>> safety (it's easy to crash the jvm by sending the wrong type or number
>> of parameters). Access to global variables through the JNA Pointer
>> class is also available in the dynamic namespace.
>>
>> The library is available from github:http://github.com/bagucode/clj-native
>> and clojars:http://clojars.org/clj-native
>>
>> Example usage of the direct namespace can be found 
>> here:http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
>>
>> Please report issues or make requests to my github account or by mail.
>>
>> Enjoy!
>>
>> /Markus
>
> --
> 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: reload of REPL init file

2010-03-18 Thread Meikel Brandmeyer
Hi,

On Mar 18, 12:06 pm, alux  wrote:

> is there a possibility to reload a clj-file that has been provided at
> the REPL-start via -i filename.clj ? (It doesn't have a name space.)
>
> This would save me to provide a namespace in the file an thus type (ns
> my-ns) after every REPL start.

I understand you, that you don't mean "reload" in the sense of
"reading the file and evaluating its contents", but as "change to the
namespace defined in the file". If this is true: java -cp clojure.jar -
i foo.clj -e "(in-ns  'foo)" -r

Reloading the file in the first sense, is done via load-file or (if
the file is on the classpath in the correct directory)
(require :reload 'foo).

Note: ns is only to initially define the namespace. To change the
namespace use in-ns.

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: Java method call irritation

2010-03-18 Thread Seth
This seems like a potential usecase for (memfn):

-
clojure.core/memfn
([name & args])
Macro
  Expands into code that creates a fn that expects to be passed an
  object and any args and calls the named instance method on the
  object passing the args. Use when you want to treat a Java method as
  a first-class fn.

user> (= (map (memfn getName) (-> (Runtime/
getRuntime) .getClass .getMethods seq))
 (map #(.getName %) (-> (Runtime/
getRuntime) .getClass .getMethods seq)))
true


On Mar 18, 6:21 am, Meikel Brandmeyer  wrote:
> Hi,
>
> Java methods are not clojure functions. To treat them like first-class
> functions you have to wrap them in clojure functions as you did in
> your second example.
>
> For your actual task: you might want to look at clojure.contrib.repl-
> utils/show.
>
> 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


reload of REPL init file

2010-03-18 Thread alux
Hello,

is there a possibility to reload a clj-file that has been provided at
the REPL-start via -i filename.clj ? (It doesn't have a name space.)

This would save me to provide a namespace in the file an thus type (ns
my-ns) after every REPL start.

Thank you and greetings,

alux

-- 
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: Java method call irritation

2010-03-18 Thread alux
Thank you Meikel. I just didnt encounter that information before ;-)

I'm still in the process of learning the core lib, so while learning I
sometimes avoid the contrib libraries, and try myself. Here this
proved educating again ;-)
(wouldn't do so for production ;-)

Thank you and regards, alux



On 18 Mrz., 11:21, Meikel Brandmeyer  wrote:
> Hi,
>
> Java methods are not clojure functions. To treat them like first-class
> functions you have to wrap them in clojure functions as you did in
> your second example.
>
> For your actual task: you might want to look at clojure.contrib.repl-
> utils/show.
>
> 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: Java method call irritation

2010-03-18 Thread Meikel Brandmeyer
Hi,

Java methods are not clojure functions. To treat them like first-class
functions you have to wrap them in clojure functions as you did in
your second example.

For your actual task: you might want to look at clojure.contrib.repl-
utils/show.

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


Java method call irritation

2010-03-18 Thread alux
Hello, I just was to lazy to get my Javadoc, so I wanted to list the
methods of an object from the 1.1-REPL.

I got different results when mapping .getName or #(.getName %) over
the seq I produced - I expected this to be the same. So seemingly my
expectations are wrong. Would you please rectify?

(map .getName (-> (Runtime/getRuntime) .getClass .getMethods seq))

got

java.lang.Exception: Unable to resolve symbol: .getName in this
context

but the following worked fine:

(map #(.getName %) (-> (Runtime/getRuntime) .getClass .getMethods
seq))


Thanks for any help, alux

-- 
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: Simple functional programming lexicon?

2010-03-18 Thread Michael Kohl
On Wed, Mar 17, 2010 at 1:28 PM, Ben Armstrong  wrote:
> What I would like to have is some sort of lexicon to at least help explain
> the terminology in a way that doesn't require three years of academic
> exposure to functional programming to read.  Is there such a reference?  Or
> should I just ignore threads like "Why do functions in the state monad only
> accept one value?" and be happy that at least somebody cares about this
> stuff, so that I don't have to?

There's a really nice article series on monads in Clojure:

http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure-programmers-part-1/

Also the "Learn you a Haskell for Great Good" tutorial is a pretty
nice and light-hearted introduction to FP with Haskell which might
also help you to understand some of the concepts better:

http://learnyouahaskell.com/

Michael

-- 
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: Name suggestions

2010-03-18 Thread Joop Kiefte
What about Clonure? Wordplay on Clone and leaving out the j ;)

2010/3/17 mac :
> After just a little more test and polish I plan on calling clj-native
> 1.0. But clj-native is a *really* boring name so I want to change it
> before 1.0 and I don't have very good imagination when it comes to
> these things.
> So I need your help.
> It doesn't have to have anything to do with anything, could just be
> something that sounds funny, like sasquatch, that's a funny word.
>
> Please help!
>
> /Markus
>
> On 13 mar, 19:14, mac  wrote:
>> Hello all.
>> I have had some time lately to work on my C FFI for Clojure and I
>> think it's pretty much feature complete now.
>> It has support for functions, callbacks, structures, unions and
>> globals.
>> For structures there is support for different alignments.
>>
>> The library has two main namespaces: clj-native.direct and clj-
>> native.dynamic.
>> The direct namespace uses the "direct mapping" feature of JNA in order
>> to be as efficient and arity and type safe as possible. However, it
>> does not support varargs functions since they require reflection and
>> dynamic translation of the parameters. That's what the dynamic
>> namespace is for: It can map any C function into clojure, even vararg
>> functions like printf but at a higher cost in call time and less
>> safety (it's easy to crash the jvm by sending the wrong type or number
>> of parameters). Access to global variables through the JNA Pointer
>> class is also available in the dynamic namespace.
>>
>> The library is available from github:http://github.com/bagucode/clj-native
>> and clojars:http://clojars.org/clj-native
>>
>> Example usage of the direct namespace can be found 
>> here:http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
>>
>> Please report issues or make requests to my github account or by mail.
>>
>> Enjoy!
>>
>> /Markus
>
> --
> 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



-- 
Communication is essential. So we need decent tools when communication
is lacking, when language capability is hard to acquire...

- http://esperanto.net  - http://esperanto-jongeren.nl

Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004

-- 
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: web starting clojure apps without Java code

2010-03-18 Thread LauJensen
Eugen,

Fantastic insight - I cant wait to work that into a blogpost :)

Lau

On 17 Mar., 15:56, Eugen Dück  wrote:
> All,
>
> Developing in clojure is a lot of fun, at least it was for me and a
> project of mine - except for one thing: Deploying the app as Java Web
> Start app, that took me a bit of time to figure out, and not only
> because Java Web Start is broken in debian squeeze (for a workaround,
> see bugs.debian.org/560056 ).
>
> Java Web Start has been discussed in this group some time ago 
> (http://groups.google.com/group/clojure/browse_thread/thread/f0c69735c...
> ), and the proposed solution at that time contained one Java class
> that did some static initialization (to propagate the necessary
> permissions to clojure's own classloader) and then went on to call RT
> to load a clj file, after fiddling around with PushBackReaders and so
> forth.
>
> I would like to stay away from RT, as it can change, and I don't want
> to depend on RT staying the way it is. Now it turns out that Web Start
> is actually pretty easy if you just AOT your whole app and gen-class
> your main entry point. That way you don't need any Java code.
>
> My clj file that contains the entry point starts like this:
>
> (ns kanshiki.swing
>   (:gen-class))
>
> Then I compile the app and create the jar file:
> mkdir classes
> java -cp clojure.jar:clojure-contrib-slim.jar:classes:. clojure.main -
> e "(compile 'kanshiki.swing)"
> (cd classes; jar cf ../kanshiki-boom.jar *)
> jarsigner kanshiki-boom.jar
>
> And the jnlp contains these tags to make it work:
> ...
>   
>     
>     
>     
>   
>   
> ...
>
> The complete jnlp can be found athttp://dueck.org/kanshiki-boom/.
>
> I plan to introduce and document this beta-grade app soon, but if
> there's any Japanese learner out there interested in or in need of
> Kanji handwriting recognition, check it out, but please hold back with
> any bug reports etc. until I have introduced it.
>
> Only one quick note: Kanjis you click will automatically be copied to
> the clipboard, so if you use it together with a kanji dictionary that
> can search the clipboard like kiten (yes, that's the KDE kanji
> dictionary with the hge memory leak, the other day it grew to 6GB
> before I killed it), it is actually useful to look up kanjis or words.
>
> Oh, and did I mention lately that clojure is pure fun? Thanks again
> Rich! You've done (and are still doing) a terrific job!
>
> Eugen

-- 
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: Web Programming with clojure

2010-03-18 Thread LauJensen
Hey Tim,

Welcome - I might be restating, but this should get you going quickly:

Getting ready: 
http://www.bestinclass.dk/index.php/2009/12/clojure-101-getting-clojure-slime-installed/
Doing simple pages: 
http://www.bestinclass.dk/index.php/2009/12/beating-the-arc-challenge-in-clojure/
Including SQL: 
http://www.bestinclass.dk/index.php/2009/12/dynamic-interactive-webdevelopment/
Making a simple Reddit clone:
http://www.bestinclass.dk/index.php/2010/02/reddit-clone-in-10-minutes-and-91-lines-of-clojure/
..and extending that with a user database:
http://www.bestinclass.dk/index.php/2010/02/reddit-clone-with-user-registration/

I wrote them in a style which targets new-comers, so I hope it will be
of some help.

Lau

On 17 Mar., 04:23, Tim Johnson  wrote:
> * Wilson MacGyver  [100316 18:17]:> there is a good 
> screencast that deal with compojure + emacs.
>
> >http://www.bestinclass.dk/index.php/2009/12/dynamic-interactive-webde...
>
> > compujure is a route based webframework, very much like ruby's sinatra.
>
> > I figure with your emacs background, this will feel very much at home.
>
>   And again ... my many thanks.
>   Here's a story for you:
>
>   Some years ago, I posted a query to an online lisp community
>   regarding a recommended lisp.
>
>   One common lisp programmer recommended newlisp.
>
>   I did a little with newlisp, really liked it, but one day I posted
>   to the newlisp community whether any of them had contemplated
>   writing newlisp in java.
>
>   The developer replied: "That's clojure". So here I am.
>   cheers
> --
> Tim
> t...@johnsons-web.comhttp://www.akwebsoft.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Simple functional programming lexicon?

2010-03-18 Thread LauJensen
Hi Ben,

I think we often get the impression that functional programming is
directly connected to monads, but in practical terms the important
concepts are pure functions and persistent immutable datastructures.
The learning curve when coming from an imperative language, lies (for
me at least) mostly in avoiding looping/mutation and thinking in terms
of purely functional constructs and sequences. The surprising thing
is, that 99% of your code then turns out to be immutable and where you
would normally introduce state, you now don't have to. There are of
course things like I/O which are inherently stateful.

So long story short, read anyone of the many interesting blog posts
floating around on how to tackle real world problems using idiomatic
Clojure and you should be able to quickly grasp the jargon and
terminology. In my opinion you can entirely dismiss monads for the
first year or so of your Clojure experience.

If I'm over simplifying, feel free to correct me :)

Lau

On 17 Mar., 13:28, Ben Armstrong  wrote:
> I am new to clojure and functional programming, but not to programming
> in general, having been in the profession for a quarter of a century.  
> I'm trying to stretch myself a bit by learning clojure, but some of the
> threads here go beyond mere stretching to verge on head-exploding.  In
> my offline reading of this list this morning, I tried using the tools
> available to me at the time (dict client and a few dictionaries like
> foldoc) to make sense of words like:  http://foldoc.org/monad.  I
> survived to write this post, but only barely.
>
> What I would like to have is some sort of lexicon to at least help
> explain the terminology in a way that doesn't require three years of
> academic exposure to functional programming to read.  Is there such a
> reference?  Or should I just ignore threads like "Why do functions in
> the state monad only accept one value?" and be happy that at least
> somebody cares about this stuff, so that I don't have to?
>
> Ben

-- 
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: help with infinite loop: break and examine stack? dynamic tracing? circular lists?

2010-03-18 Thread LauJensen
Hi Lee,

Personally I think JSwat does the job right in that you can break the
code and get a look at local variables. There has also been release a
'debug-repl' which allows you to halt execution and jump into a REPL,
like so: http://georgejahad.com/clojure/debug-repl.html. There exists
2 versions, 1 requiring a compile mod.

Finally both CounterClockwise and Enclojure for Netbeans have
breakpoint functionality, which is also finding its way into emacs:
http://github.com/technomancy/swank-clojure/tree/swank-break.

That should give you enough options to inspect locals when the
situation arises.

Lau

On 17 Mar., 16:14, Lee Spector  wrote:
> I apologize for the length of this message, but I've run into a problem that 
> I think I might approach in any of several ways, each of which leads to 
> questions about things that I'd like to know more about in any event. Some 
> are dev environment questions and some (re: circular lists near the end) are 
> core Clojure language questions.
>
> The root problem is that I think I have an infinite loop somewhere in my code 
> and I'm having a hard time tracking it down. My system has a lot of 
> randomness in it and I've been unable to produce a repeatable or minimal 
> example, but in many full-scale runs I eventually get a hang that smells like 
> an infinite loop. I found one that I tracked down to some recursive zipper 
> code, and I fixed that, but there's at least one more and I can't find it. 
> One of the reasons this is particularly tricky is that I'm dynamically 
> generating and executing lots of calls in random/evolved orders with 
> random/evolved arguments, so unexpected sequences of events can arise. (And 
> they do arise, which is the point! :-)
>
> In Common Lisp I would wait until I think I'm in trouble, break execution 
> with a keyboard interrupt, look at the function call stack (and local vars, 
> if I'm in a nice CL environment), and probably figure it out pretty quickly.
>
> What would experienced Clojurians suggest in a situation like this?
>
> Is there is a way to break and look around under slime? I just finally got 
> slime working with Clojure (THANKS to Lau 
> Jens,http://www.bestinclass.dk/index.php/2009/12/clojure-101-getting-cloju...),
>  but I don't yet know my way around it. Can anyone recommend a good concise 
> description of all of the relevant key commands? I've never used slime much 
> for Common Lisp either -- I've used mostly IDEs like MCL and various lisp 
> machines way back in the last century -- so I need to start near the 
> beginning on slime. Knowing that I could break and examine state would 
> certainly motivate that.
>
> In general I've been running a REPL in a separate terminal window using the 
> clj script that comes with ClojureX (on macs running OS X 10.6.2). I don't 
> know how to force a break or get a break loop in this environment but when I 
> hit an error I can do (.printStackTrace *e) and this does show me some of my 
> own function calls amid the other stuff. Even though this is pretty minimal 
> it has been very helpful at times. Two problems with this, however: 1) I can 
> only get this from an error; I don't know how to force a break so I can look 
> at this when I seem to be stuck in a loop, and 2) The stack trace info is 
> always elided, with lines saying something like "... 31 more". I want all the 
> trace information that it can give me, but I've been unable to figure out how 
> to keep it from eliding. I've tried to force clj-initiated runs to break by 
> sending signals to the java process from the Mac OS X Activity Monitor app, 
> but everything that I have tried (e.g. SIGINT) either does nothing or kills 
> the whole process. Is there a signal that I could sent to abort execution but 
> not quit java, as happens with errors,  so that I could look at a backtrace? 
> Is there a handler that I could add to my code to allow this to happen? It'd 
> only help if it allowed me to see what else was going on when the signal was 
> received; if it only told me that the error was from a signal arriving then 
> that would defeat the purpose.
>
> I've also been doing some runs under MCLIDE, with help from Terje Norderhaug, 
> and there I can indeed issue a break from a menu and get a backtrace of 
> sorts... but so far I have not been able to get a backtrace that shows me 
> what I need -- that is, I don't see any of my own functions, presumably 
> because the break changed the context... I'm not sure what's going on there. 
> I've also briefly experimented with Eclipse/Counterclockwise, but found 
> Eclipse fairly confusing in general... but does it provide a better approach 
> to breaking/exploring running code? If so then perhaps I should give that 
> another shot.
>
> An alternative: Is there a way to watch my running Clojure program without 
> breaking it, that is to observe the recent call history (of my own 
> definitions, either all of them or specifically marked ones) from outside the 
> process?

Re: Name suggestions

2010-03-18 Thread LauJensen
Hey Markus,

Probably not what you want to hear, but I think great names are both
memorable and descriptive. Leaning on those criterias clj-native is
not bad at all.

Lau

On 17 Mar., 08:08, mac  wrote:
> After just a little more test and polish I plan on calling clj-native
> 1.0. But clj-native is a *really* boring name so I want to change it
> before 1.0 and I don't have very good imagination when it comes to
> these things.
> So I need your help.
> It doesn't have to have anything to do with anything, could just be
> something that sounds funny, like sasquatch, that's a funny word.
>
> Please help!
>
> /Markus
>
> On 13 mar, 19:14, mac  wrote:
>
>
>
> > Hello all.
> > I have had some time lately to work on my C FFI for Clojure and I
> > think it's pretty much feature complete now.
> > It has support for functions, callbacks, structures, unions and
> > globals.
> > For structures there is support for different alignments.
>
> > The library has two main namespaces: clj-native.direct and clj-
> > native.dynamic.
> > The direct namespace uses the "direct mapping" feature of JNA in order
> > to be as efficient and arity and type safe as possible. However, it
> > does not support varargs functions since they require reflection and
> > dynamic translation of the parameters. That's what the dynamic
> > namespace is for: It can map any C function into clojure, even vararg
> > functions like printf but at a higher cost in call time and less
> > safety (it's easy to crash the jvm by sending the wrong type or number
> > of parameters). Access to global variables through the JNA Pointer
> > class is also available in the dynamic namespace.
>
> > The library is available from github:http://github.com/bagucode/clj-native
> > and clojars:http://clojars.org/clj-native
>
> > Example usage of the direct namespace can be found 
> > here:http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
>
> > Please report issues or make requests to my github account or by mail.
>
> > Enjoy!
>
> > /Markus

-- 
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: Simple functional programming lexicon?

2010-03-18 Thread Konrad Hinsen
On 18.03.2010, at 04:50, Praki Prakash wrote:

> As others have mentioned, Haskell is heavy in its use of monads and  many 
> other  algebraic structures. I don't know why the two languages feel so 
> different with respect to the level of formalism you need to use them. But, 
> Haskell is one of the most mind bending programming language there and well 
> worth the study.

The difference is perhaps more in the community than in the language. But 
Haskell clearly shows its academic origins, whereas Clojure clearly shows the 
pragmatic attitude of its creator. I can appreciate both, being in the academic 
world but not in computer science - programming for me is mostly pragmatic 
rather than a research goal in itself.

Konrad.

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