Re: Source code as metadata

2012-04-01 Thread Phil Hagelberg
Jeff Weiss jeffrey.m.we...@gmail.com writes:

 From browsing git, it looks like the project.clj version hasn't been
 incremented in 7 months, and the fix for closures came in after that.
 If you're using serializable.fn from a maven repo, it is out of
 date, AFAICT.

Sorry about that; just pushed a new 1.1.2 version with the latest code
from Github.

-Phil

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


Re: Source code as metadata

2012-03-31 Thread Nathan Matthews

On 31 Mar 2012, at 00:00, Cedric Greevey wrote:

 On Fri, Mar 30, 2012 at 6:17 PM, Lee Spector lspec...@hampshire.edu wrote:
 
 On Mar 30, 2012, at 5:11 PM, Cedric Greevey wrote:
 
 That opens a giant can of worms. How, for example, do we discover that
 (partial * 2) and #(* % 2) and (fn [x] (* 2 x)) and #(+ %1 %1) are all
 equal? Nevermind once we get into situations like #(reduce + (map
 (constantly 1) %) equals #(loop [n 0 s (seq %)] (if s (recur (inc n)
 (next s)) n) equals count.
 
 In fact that's an uncomputable can of worms.
 
 I was pretty sure it smelled like halting problem; thanks for confirming. :)

Agreed, but I'm not suggesting determining whether two forms are 
computationally equivalent, just if two forms are 
literally equivalent. I know it wouldn't cover all cases, but cases like:

(= (partial * 2) (partial * 2))

it would cover, which would seem like an improvement over the situation today. 
I suppose my bigger point is if code is data 
when thy isn't the code for functions available for analysis at runtime? 

 
 -- 
 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: Source code as metadata

2012-03-31 Thread Jeff Weiss
I believe the latest code does capture closures properly.  I haven't tested 
all kinds of crazy corner cases, but it does work for all my closures.

From browsing git, it looks like the project.clj version hasn't been 
incremented in 7 months, and the fix for closures came in after that.  If 
you're using serializable.fn from a maven repo, it is out of date, AFAICT.

-jeff

On Friday, March 30, 2012 3:07:53 PM UTC-4, Phil Hagelberg wrote:

 Nathan Matthews nathan.r.matth...@gmail.com writes:

  I wanted to serialise functions and send them over the network. The
  problem with serializable-fn is that it doesn't capture closures.

 It's designed to capture closures; if it doesn't that would be an
 (unsurprising) bug.

 -Phil



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

Re: Source code as metadata

2012-03-30 Thread Vinzent
Another idea is to put :indentation metadata on vars, so user-defined 
macros could be indented properly. Currently I have (define-clojure-indent 
...) with a number of forms in my emacs config file, and it seems to be 
pretty common solution. It'd be nice to replace this hack with an 
IDE-independent way to control the indentation.

Phil, what do you think? Could it be experimentally implemented in 
clojure-mode?

-- 
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: Source code as metadata

2012-03-30 Thread Phil Hagelberg
Vinzent ru.vinz...@gmail.com writes:

 Phil, what do you think? Could it be experimentally implemented in
 clojure-mode?

No, clojure-mode determines indentation exclusively from static
heuristics. There is dynamic indentation support in slime, but I've
never looked into it; I'm not sure how I feel about indentation rules
changing depending on whether slime is active or not.

-Phil

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


Re: Source code as metadata

2012-03-30 Thread Nathan Matthews
Hi, 

I wanted to serialise functions and send them over the network. The problem 
with serializable-fn is that it doesn't capture closures. 
I wrote some code which re-programmed the fn macro to capture the closures as 
well as the actual function form, and attach them as meta-data also on the 
actual function object. 
I could share this code if people would find this useful. Its non-trivial due 
to various complexities and bugs in Clojure.

Also it bothers me that

(= (partial * 2) (partial * 2)) 

is false. Logically it shouldn't be right?  If we captured the function forms, 
that would enable better equality for functions.

On 29 Mar 2012, at 17:44, Phil Hagelberg wrote:

 On Thu, Mar 29, 2012 at 9:29 AM, Petr Gladkikh petrg...@gmail.com wrote:
 I am pondering on the idea of having more (or even a lot) of metadata
 that could be useful for debugging and problem resolution.
 Since we can store anything in metadata, can we store not only  source
 file path and line number but whole source code that is associated
 with piece of code?
 
 See https://github.com/technomancy/serializable-fn/ for a
 proof-of-concept of this idea.
 
 It's always bothered be that defn puts metadata on the var and not on
 the function itself.
 
 Anyway, supposedly Rich is in favour of having dynamicity knobs
 according to his Conj 2011 keynote, and this sounds like just the kind
 of thing that would fall under that.
 
 -Phil
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
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: Source code as metadata

2012-03-30 Thread Phil Hagelberg
Nathan Matthews nathan.r.matth...@gmail.com writes:

 I wanted to serialise functions and send them over the network. The
 problem with serializable-fn is that it doesn't capture closures.

It's designed to capture closures; if it doesn't that would be an
(unsurprising) bug.

-Phil

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


Re: Source code as metadata

2012-03-30 Thread Vinzent


 I'm not sure how I feel about indentation rules
 changing depending on whether slime is active or not.


What I was thinking, is that there'd be some function which would collect 
and save indentation metadata, so it can be used later. Thus, active slime 
connection required only the first time one uses a library with 
non-standart indentation rules. 

-- 
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: Source code as metadata

2012-03-30 Thread Phil Hagelberg
Nathan Matthews nathan.r.matth...@gmail.com writes:

 I wrote some code which re-programmed the fn macro to capture the
 closures as well as the actual function form, and attach them as
 meta-data also on the actual function object.

Could you submit it as a patch to serializable-fn? It would be nice to
have everything in one place.

-Phil

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


Re: Source code as metadata

2012-03-30 Thread Phil Hagelberg
Vinzent ru.vinz...@gmail.com writes:

 I'm not sure how I feel about indentation rules
 changing depending on whether slime is active or not.

 What I was thinking, is that there'd be some function which would
 collect and save indentation metadata, so it can be used later. Thus,
 active slime connection required only the first time one uses a
 library with non-standart indentation rules. 

Currently clojure-mode operates on each file in isolation. As soon as
you start remembering macro indentation, you're back in a
non-deterministic state where indentation depends on the history of
which files you've visited in the current Emacs session.

You could make it work just for the macros in a single file, but that
doesn't seem very valuable.

-Phil

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


Re: Source code as metadata

2012-03-30 Thread Cedric Greevey
On Fri, Mar 30, 2012 at 1:26 PM, Vinzent ru.vinz...@gmail.com wrote:
 Another idea is to put :indentation metadata on vars, so user-defined macros
 could be indented properly. Currently I have (define-clojure-indent ...)
 with a number of forms in my emacs config file, and it seems to be pretty
 common solution. It'd be nice to replace this hack with an IDE-independent
 way to control the indentation.

 Phil, what do you think? Could it be experimentally implemented in
 clojure-mode?

My thought on this? Just look for the macro to have a rest arg.
Function argument indentation should be used for non-rest macro args,
and body indentation for macro rest args.

-- 
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: Source code as metadata

2012-03-30 Thread Cedric Greevey
On Fri, Mar 30, 2012 at 2:48 PM, Nathan Matthews
nathan.r.matth...@gmail.com wrote:
 Also it bothers me that

 (= (partial * 2) (partial * 2))

 is false. Logically it shouldn't be right?  If we captured the function 
 forms, that would enable better equality for functions.

That opens a giant can of worms. How, for example, do we discover that
(partial * 2) and #(* % 2) and (fn [x] (* 2 x)) and #(+ %1 %1) are all
equal? Nevermind once we get into situations like #(reduce + (map
(constantly 1) %) equals #(loop [n 0 s (seq %)] (if s (recur (inc n)
(next s)) n) equals count.

-- 
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: Source code as metadata

2012-03-30 Thread Vinzent
Probably you slightly misunderstood what I mean. Consider this scenario:
I've set up a project which uses a new library with non-standart indent. 
I've connected to swank and compiled it. Then I'm calling some 
clojure-mode-update-indent function, which walks through all loaded 
namespaces and collects :indent metadata (on the clojure side) and saves 
appropriate define-clojure-indent form somewhere in config file (on the 
elisp side). After that I have all macros indented properly.

It's better than manually writing define-clojure-indent form because it's 
tool-agnostic; say, CCW can use the same data, so library maintainers only 
have to add {:indent :defn} to their defmacros. 

суббота, 31 марта 2012 г. 2:32:35 UTC+6 пользователь Phil Hagelberg написал:

 Vinzent ru.vinz...@gmail.com writes:

  I'm not sure how I feel about indentation rules
  changing depending on whether slime is active or not.
 
  What I was thinking, is that there'd be some function which would
  collect and save indentation metadata, so it can be used later. Thus,
  active slime connection required only the first time one uses a
  library with non-standart indentation rules. 

 Currently clojure-mode operates on each file in isolation. As soon as
 you start remembering macro indentation, you're back in a
 non-deterministic state where indentation depends on the history of
 which files you've visited in the current Emacs session.

 You could make it work just for the macros in a single file, but that
 doesn't seem very valuable.

 -Phil



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

Re: Source code as metadata

2012-03-30 Thread Vinzent
Counter-example: one could write if-authenticated macro, which will take 
fixed number of args, but should be indented as normal if.

суббота, 31 марта 2012 г. 3:07:23 UTC+6 пользователь Cedric Greevey написал:

 On Fri, Mar 30, 2012 at 1:26 PM, Vinzent ru.vinz...@gmail.com wrote:
  Another idea is to put :indentation metadata on vars, so user-defined 
 macros
  could be indented properly. Currently I have (define-clojure-indent ...)
  with a number of forms in my emacs config file, and it seems to be pretty
  common solution. It'd be nice to replace this hack with an 
 IDE-independent
  way to control the indentation.
 
  Phil, what do you think? Could it be experimentally implemented in
  clojure-mode?

 My thought on this? Just look for the macro to have a rest arg.
 Function argument indentation should be used for non-rest macro args,
 and body indentation for macro rest args.


-- 
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: Source code as metadata

2012-03-30 Thread Phil Hagelberg
Vinzent ru.vinz...@gmail.com writes:

 Probably you slightly misunderstood what I mean. Consider this
 scenario:
 I've set up a project which uses a new library with non-standart
 indent. I've connected to swank and compiled it. Then I'm calling
 some clojure-mode-update-indent function, which walks through all
 loaded namespaces and collects :indent metadata (on the clojure side)
 and saves appropriate define-clojure-indent form somewhere in config
 file (on the elisp side). After that I have all macros indented
 properly.

I see. Yes, that would be better. I don't think it belongs in
clojure-mode, but you could make a tool that could collect that data and
export it into .dir-locals.el files or something like that.

-Phil

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


Re: Source code as metadata

2012-03-30 Thread Lee Spector

On Mar 30, 2012, at 5:11 PM, Cedric Greevey wrote:
 
 That opens a giant can of worms. How, for example, do we discover that
 (partial * 2) and #(* % 2) and (fn [x] (* 2 x)) and #(+ %1 %1) are all
 equal? Nevermind once we get into situations like #(reduce + (map
 (constantly 1) %) equals #(loop [n 0 s (seq %)] (if s (recur (inc n)
 (next s)) n) equals count.

In fact that's an uncomputable can of worms. But detecting identity of 
functions that were defined using exactly the same code is computable, whether 
or not it's advisable or useful (which I don't know).

 -Lee

-- 
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: Source code as metadata

2012-03-30 Thread Cedric Greevey
2012/3/30 Vinzent ru.vinz...@gmail.com:
 Counter-example: one could write if-authenticated macro, which will take
 fixed number of args, but should be indented as normal if.

OK, check the macro structure to see if any args are incorporated as
invokable forms -- so, in arguments in special forms and macros that
are bodies. (Yes, this is obviously sort of recursive.) The first
such arg is treated as the start of a body.

Some static dataflow analysis may be needed in case the macro takes
the arg, processes it in some way, and then inserts it into its output
rather than inserting it directly.

-- 
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: Source code as metadata

2012-03-30 Thread Cedric Greevey
On Fri, Mar 30, 2012 at 6:17 PM, Lee Spector lspec...@hampshire.edu wrote:

 On Mar 30, 2012, at 5:11 PM, Cedric Greevey wrote:

 That opens a giant can of worms. How, for example, do we discover that
 (partial * 2) and #(* % 2) and (fn [x] (* 2 x)) and #(+ %1 %1) are all
 equal? Nevermind once we get into situations like #(reduce + (map
 (constantly 1) %) equals #(loop [n 0 s (seq %)] (if s (recur (inc n)
 (next s)) n) equals count.

 In fact that's an uncomputable can of worms.

I was pretty sure it smelled like halting problem; thanks for confirming. :)

-- 
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: Source code as metadata

2012-03-29 Thread Phil Hagelberg
On Thu, Mar 29, 2012 at 9:29 AM, Petr Gladkikh petrg...@gmail.com wrote:
 I am pondering on the idea of having more (or even a lot) of metadata
 that could be useful for debugging and problem resolution.
 Since we can store anything in metadata, can we store not only  source
 file path and line number but whole source code that is associated
 with piece of code?

See https://github.com/technomancy/serializable-fn/ for a
proof-of-concept of this idea.

It's always bothered be that defn puts metadata on the var and not on
the function itself.

Anyway, supposedly Rich is in favour of having dynamicity knobs
according to his Conj 2011 keynote, and this sounds like just the kind
of thing that would fall under that.

-Phil

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