Re: Macros, namespaces, and lexical scope

2009-09-26 Thread Meikel Brandmeyer

Hi,

Am 26.09.2009 um 17:06 schrieb Constantine Vetoshev:


This seems indeed useless at a first glance, but looking down the
cause trace usually shows the real problem.


Full stack trace follows, although I still don't know what it means.

No message.
 [Thrown class java.lang.ExceptionInInitializerError]

Backtrace:
 0: sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
 1: sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
 2: sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
 3: java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 4: java.lang.Class.newInstance0(Class.java:355)
 5: java.lang.Class.newInstance(Class.java:308)
 6: clojure.lang.Compiler$FnExpr.eval(Compiler.java:3428)
 7: clojure.lang.Compiler.eval(Compiler.java:4531)
 8: clojure.core$eval__3990.invoke(core.clj:1728)


No. This is a *stack*trace. I meant the *cause* trace. That is, the  
chain of wrapped exceptions. You should look in the trace for lines  
like "Caused by ...". The last should point to the real problem. Of  
course, that might be something obscure, eg. in the case Chouser  
mentioned. However I found it to be something in my code in 99.9% of  
the cases. :] From what you print, it seems you use SLIME. This maybe  
hides the "Caused by..." lines and only prints the stracktrace. Not  
sure, though.


Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: Macros, namespaces, and lexical scope

2009-09-26 Thread Meikel Brandmeyer

Hi,

Am 25.09.2009 um 22:49 schrieb Constantine Vetoshev:


(defmacro def-with-db-macro [macro-name open-fn close-fn]
 `(defmacro ~macro-name [[var# & open-args#] & body#]
`(let [~var# (apply ~'~open-fn [...@open-args#])]
   (try
~...@body#
(finally (~'~close-fn ~var#))


The problem is, that you quote the symbol you inject into the inner  
defmacro. Hence it does not get resolved. The solution in this case  
seems to be to syntax-quote the symbol correctly before injection.  
Replace the two ~'~ with ~~ and call the macro as (def-with-db-macro  
with-foo `open-foo `close-foo). This correctly resolves the symbols in  
the namespace calling def-with-db-macro and injects them into the with- 
foo expansion. I haven't really tested this, but it seems to be  
consistent with the macro machinery.



While searching for a workaround, I thought maybe I could capture the
functions I need during expansion of def-with-db-macro, but kept
getting a useless exception. I ended up reducing that problem to this:

(let [f1 #(inc %)]
 (defmacro m1 [x]
   `(~f1 ~x)))

(m1 12)
=> No message.
 [Thrown class java.lang.ExceptionInInitializerError]


This seems indeed useless at a first glance, but looking down the  
cause trace usually shows the real problem.


Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: Getting REPL transcript

2009-09-26 Thread Emeka
Thank you all. Chris Grand has figured it out for me. However, I invite you
to look at it and comment.

Regards,
Emeka

On Sat, Sep 26, 2009 at 12:15 PM, Daniel Werner <
daniel.d.wer...@googlemail.com> wrote:

>
> On Sep 23, 6:20 pm, Emeka  wrote:
> > Hello All,
> >
> > I would like to have a transcript of Repl. Could someone help me out
> here?
> >
> > Regards,
> > Emeka
>
> If you use rlwrap, you can give it the --log-file (-l) argument:
>
> $ rlwrap -l repl.log java -cp ...
> >
>

--~--~-~--~~~---~--~~
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: "Schema" for data structures

2009-09-26 Thread Daniel Werner

On Sep 24, 10:14 am, Miron Brezuleanu  wrote:
> about). The degree of typing can be varied (i.e. a person is any map
> with a :name key, or any map with only a :name key, or any map with a
> :name key which is nil or string etc.)

You may be interested in Konrad Hinsen's (algebraic) data type support
in clojure.contrib.types. As far as I've discovered from toying with
it, it doesn't seem to cover your "vector of persons" use case, but it
does support matching maps by the keys they contain and the keys'
values, but not their types.
--~--~-~--~~~---~--~~
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: Macros, namespaces, and lexical scope

2009-09-26 Thread Constantine Vetoshev

On Sep 26, 7:35 am, Meikel Brandmeyer  wrote:
> The problem is, that you quote the symbol you inject into the inner
> defmacro. Hence it does not get resolved. The solution in this case
> seems to be to syntax-quote the symbol correctly before injection.
> Replace the two ~'~ with ~~ and call the macro as (def-with-db-macro
> with-foo `open-foo `close-foo). This correctly resolves the symbols in
> the namespace calling def-with-db-macro and injects them into the with-
> foo expansion. I haven't really tested this, but it seems to be
> consistent with the macro machinery.

Thank you. That works. I had tried ~~ by itself, and it didn't fly. I
didn't think to syntax-quote the symbol in its place of expansion.

So referring back to http://paste.lisp.org/display/87734, the solution
is:

user> (defmacro make-myfoo [foo] `(defmacro ~'myfoo [s#] `(~~foo
~s#)))
   => #'user/make-myfoo
user> (ns tmp)
tmp> (user/make-myfoo `foo)
   => #'tmp/myfoo
tmp> (macroexpand '(tmp/myfoo bar))
   => (tmp/foo bar)

As expected, in the tmp namespace.

> This seems indeed useless at a first glance, but looking down the
> cause trace usually shows the real problem.

Full stack trace follows, although I still don't know what it means.

No message.
  [Thrown class java.lang.ExceptionInInitializerError]

Backtrace:
  0: sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
  1: sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
  2: sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
  3: java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  4: java.lang.Class.newInstance0(Class.java:355)
  5: java.lang.Class.newInstance(Class.java:308)
  6: clojure.lang.Compiler$FnExpr.eval(Compiler.java:3428)
  7: clojure.lang.Compiler.eval(Compiler.java:4531)
  8: clojure.core$eval__3990.invoke(core.clj:1728)

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



Fwd: Re: "Schema" for data structures

2009-09-26 Thread Artyom Shalkhakov

Ooops, sent it to the wrong address.

-- Forwarded message --
From: Artyom Shalkhakov 
Date: 2009/9/25
Subject: Re: "Schema" for data structures
To: clojure group 


Hello Miron,

> is there a way to check if a data structure complies to a given
> schema? (e.g. people is a vector of persons).
>
> I'm using C# a lot and maybe the static typing has changed the way I
> think. I feel like adding "type checks" in unit tests and being able
> to say something like:
>
> (is-type (people (vector person)))
>
> sounds like a neat way to check types (I know 'vector' is a 'taken'
> name, I'm just trying to illustrate the kind of syntax I'm thinking
> about). The degree of typing can be varied (i.e. a person is any map
> with a :name key, or any map with only a :name key, or any map with a
> :name key which is nil or string etc.)

You might be looking for something akin to contracts of PLT Scheme:

http://pre.plt-scheme.org/docs/html/guide/contracts.html

there are also "define-type" and "type-case" macros (again for Scheme,
specifically PLAI language, but I guess they can be translated to
Clojure easily), which I find very handy. Can't post the link ATM
because PLaneT seems to be down or something though.

Here's an example of define-type/type-case in Scheme:

(require (planet "main.ss" ("plai" "plai.plt" 1 3)))

;; arithmetical expressions
(define-type AE
  ;; distinguish various cases,
  ;; very much like a union in C but with an explicit "type" tag
  ;; (one of num, plus, sub)
  ;; not we enforce a contract on each member
  (num (n number?))
  (plus (l AE?) (r AE?))
  (sub (l AE?) (r AE?)))

(provide/contract
   [interp  (-> AE? number?)])

;; interpret an arithmetical expression yielding a number
(define (interp exp)
  ;; type-case is very much like a "case ... of" in Haskell/ML
  (type-case AE exp
    (num (n) n)
    (plus (l r) (+ (interp l) (interp r)))
    (sub (l r) (- (interp l) (interp r)

Contracts work only between module boundaries though.

Cheers,
Artyom Shalkhakov.

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



Authers needed for Apress book: "Definitive Guide to Clojure"

2009-09-26 Thread Luke VanderHart

Hello all,

I am writing a book on Clojure for Apress - you can read about it at
http://www.apress.com/book/view/1430272317 (be aware, before you
consider buying it, that it's still VERY rough and less than half
done)

It's coming along well. I am enjoying the writing, and I feel it will
be a good resource to supplement what is already available.

Unfortunately, it is progressing rather slowly. It's my first book,
and somewhat more labor-intensive than I had guessed, in addition to
which I am working full time on several other projects. Apress would
like to publish as soon as possible, and in order to do that we
decided to see if we could bring in some guest authors to help out and
write some chapters. That's where you all come in.

We're looking for one or more guest authors to contribute 1 to ~5
chapters. Each chapter needs to be at least 20 pages long
(approximately). There will be compensation, with advances, royalties
and marketing recognition proportionate to the amount of work
contributed.

The list of chapters so far looks like this:

1   The Clojure Way
2   The Clojure Environment
3   Defining Symbols and Functions
4   Data Types and Structures
5   Sequences
6   State Management
7   Namespaces and Libraries
8   Multimethods
9   Metadata
10  Working with Java
11  Parallel Programming
12  Macros & Metaprogramming
13  Appendices (Overview of Clojure tooling and environments,
overview of Java)

I've finished through chapter 5.

If you've written about Clojure in the past, or if you feel you are
able to write lucidly about any of the following chapters, with
examples, then I strongly encourage you to consider doing this. It
would be a great help to Apress, and having more variety of experience
in the book can only make it stronger. It will continue, either way,
but this is a great opportunity to be a part of it and help it get to
market more quickly (hurray for parallelism in writing!) .

Also, if you have an idea for an additional chapter that you're
willing to contribute, we will definitely entertain the idea - I
didn't initially put in chapters about web programming, GUI
programming or unit testing in Clojure to keep the scope down, but
these are all deserving topics if someone really wants to give them a
shot.

If you are interested, reply here, or send me an email to me, or to my
editor Michelle Lowman ( michellelow...@apress.com ) so we can talk
about it.

Thanks very much for considering this.

Sincerely,
-Luke VanderHart


--~--~-~--~~~---~--~~
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: Macros, namespaces, and lexical scope

2009-09-26 Thread Chouser

On Fri, Sep 25, 2009 at 4:49 PM, Constantine Vetoshev
 wrote:
>
> Chris Houser has summarized the problem here more succinctly than I
> can: http://paste.lisp.org/display/87734

This is a syntax-quote expansion-timing issue, which is why
Meikel's solutions works.  I think it would work the way you want
for all the actual examples you gave, including the literal
anonymous function.

> While searching for a workaround, I thought maybe I could capture the
> functions I need during expansion of def-with-db-macro, but kept
> getting a useless exception. I ended up reducing that problem to this:
>
> (let [f1 #(inc %)]
>  (defmacro m1 [x]
>    `(~f1 ~x)))
>
> (m1 12)
> => No message.
>  [Thrown class java.lang.ExceptionInInitializerError]

This a separate issue having to do with support for AOT
compilation.  It actually worked fine with an older version of
Clojure, specifically 043093bd670d4981a3136294941831c4cfcb7bae
from Sun Oct 12 14:47:24 2008.

The next commit removed support for that feature: "first step
towards AOT compilation - constants now read from strings in
classfiles instead of hand-off from classloader"

--Chouser

--~--~-~--~~~---~--~~
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: Getting REPL transcript

2009-09-26 Thread Daniel Werner

On Sep 23, 6:20 pm, Emeka  wrote:
> Hello All,
>
> I would like to have a transcript of Repl. Could someone help me out here?
>
> Regards,
> Emeka

If you use rlwrap, you can give it the --log-file (-l) argument:

$ rlwrap -l repl.log java -cp ...
--~--~-~--~~~---~--~~
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: Getting REPL transcript

2009-09-26 Thread Emeka
Sorry, here is the link.
http://gist.github.com/193550



On Sat, Sep 26, 2009 at 2:03 PM, Emeka  wrote:

> Thank you all. Chris Grand has figured it out for me. However, I invite you
> to look at it and comment.
>
> Regards,
> Emeka
>
>
> On Sat, Sep 26, 2009 at 12:15 PM, Daniel Werner <
> daniel.d.wer...@googlemail.com> wrote:
>
>>
>> On Sep 23, 6:20 pm, Emeka  wrote:
>> > Hello All,
>> >
>> > I would like to have a transcript of Repl. Could someone help me out
>> here?
>> >
>> > Regards,
>> > Emeka
>>
>> If you use rlwrap, you can give it the --log-file (-l) argument:
>>
>> $ rlwrap -l repl.log java -cp ...
>> >>
>>
>

--~--~-~--~~~---~--~~
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: VimClojure on Windows (problem + solution)

2009-09-26 Thread Meikel Brandmeyer

Hi,

Am 07.09.2009 um 22:28 schrieb Niels Aan de Brugh:


The problem is probably that you have 'shellslash' set. This
influences the behavior of the function shellescape(), which is used
by VimClojure. Resetting this options fixes the problem.


Thank you for reporting that. I will reset the shellslash option  
around calls to shellescape (if possible).


Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: VimClojure - OpenSolaris - What am I doing wrong?

2009-09-26 Thread Meikel Brandmeyer

Hi,

Am 08.09.2009 um 15:31 schrieb Michael Aldred:


The NailGun client assumes that the strlen function will handle a null
pointer for the argument.
Under Solaris this is not the case (http://technopark02.blogspot.com/
2006/04/solaris-null-pointer-bugs-usrlib00so1.html)


Thank you for the fix. I will include the patch.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: How to use vimClojure?

2009-09-26 Thread Meikel Brandmeyer

Hi,

Am 10.09.2009 um 06:41 schrieb MarkSwanson:

8. A new window should open, containing #'user/greet. Type \p to  
close

the window.


It's all good up to this point.


9. Go to the Repl window, eg. with .
11. At the prompt type (gr and hit  to complete the  
function

name.
10. Submit (greet) by hitting return. (the Repl should now print
"Hello, World!")


This doesn't work.
The new window opened up containing the right text. However, the REPL
can not use the function.


This is rather strange. If the result window really contains '#'user/ 
greet, I don't understand, why it is not available at the repl



What's strange is that I can type (gr and CTRL-n and user/greet shows
up! This tells me the REPL has the function, but it gives this error:
#


No.  is completely independent of the Clojure side of VC. It also  
works with the dynamic part turned off. It learns all keywords from  
all open files. Hence the clojure side is not required as for o>.


Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: "Schema" for data structures

2009-09-26 Thread Daniel Renfer

One of the things I'm doing in my application is I modified clj-record  
to attach metadata about the record's type to each record when find- 
records is used. I am then able to have a function that checks that  
metadata which can be used as a predicate.

It gets even better because I can then write multi-methods that  
dispatch on the type of record I have. You will have to take care that  
your multimethods will only work if you have the metadata attached, so  
you'll have to take care to with-meta any records you create yourself.

my fork of clj-record is on github

On Sep 24, 2009, at 4:14 AM, Miron Brezuleanu wrote:

>
> Hello,
>
> is there a way to check if a data structure complies to a given
> schema? (e.g. people is a vector of persons).
>
> I'm using C# a lot and maybe the static typing has changed the way I
> think. I feel like adding "type checks" in unit tests and being able
> to say something like:
>
> (is-type (people (vector person)))
>
> sounds like a neat way to check types (I know 'vector' is a 'taken'
> name, I'm just trying to illustrate the kind of syntax I'm thinking
> about). The degree of typing can be varied (i.e. a person is any map
> with a :name key, or any map with only a :name key, or any map with a
> :name key which is nil or string etc.)
>
> I browsed through clojure.test (which is clojure.contrib.test-is
> integrated into Clojure, right?) but couldn't find something like
> this.
>
> Thank you,
> -- 
> Miron Brezuleanu
>
> >


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



Mocking?

2009-09-26 Thread Mark Derricutt
'lo all,

How are people handling mocking/stubbing in clojure?  Google finds me some
old posts about a called? function/macro as part of test-is which looks like
it'd do what I need but I can't seem to find any trace of it under
clojure/clojure-contrib trunk.

Any pointers?

-- 
Pull me down under...

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