On 23.05.2009, at 02:13, Mark Engelberg wrote:
> OK, after looking at deftemplate with macroexpand, it's starting to
> make more sense. I suppose one downside to this versus load is that
> it's probably much more difficult to debug (just because all your code
> is wrapped in a macro), but basica
OK, after looking at deftemplate with macroexpand, it's starting to
make more sense. I suppose one downside to this versus load is that
it's probably much more difficult to debug (just because all your code
is wrapped in a macro), but basically I like the idea.
--~--~-~--~~--
On 22.05.2009, at 11:01, Mark Engelberg wrote:
> I was thinking that if you have:
> (def a 2)
> (def b 3)
> (defn f [] a)
>
> and you set it up with your deftemplate macro where f is the thing
> that is parameterized, then if you try to pass in a new value for f,
> like:
> (fn [] b), it macro exp
On Fri, May 22, 2009 at 1:37 AM, Konrad Hinsen
wrote:
> As long as it uses the same variables as the template, it would still
> work, but (like the load-and-redefine method) it would fail as soon
> as the template author decides to change the names of his variables.
> I suppose that to some exten
On 22.05.2009, at 10:03, Mark Engelberg wrote:
> However, there seems to be one way that this solution falls short of
> the load-and-redefine technique.
I don't think it can ever fall short of the load-and-redefine
technique because you can emulate it completely (unless I overlooked
somethin
On Wed, May 20, 2009 at 8:14 AM, Konrad Hinsen
wrote:
> Here is another solution that I consider preferable to the use of
> load.
Konrad, this is an interesting approach, and it does feel like a
better way to organize similar modules than using load.
However, there seems to be one way that this
On 20.05.2009, at 17:14, Konrad Hinsen wrote:
> Here is another solution that I consider preferable to the use of
> load. It requires you to specify explicitly which vars you want to be
> replaceable (which I consider an advantage)
That's actually not true: it doesn't require a specification of
On 17.05.2009, at 21:24, Mark Engelberg wrote:
> I don't want to post my actual code here, so let's run with this
> *gravity* example based off of what Adrian posted as a simple
> illustration.
Here is another solution that I consider preferable to the use of
load. It requires you to specify e
2009/5/18 Mark Engelberg :
>
> On Mon, May 18, 2009 at 4:23 AM, Laurent PETIT
> wrote:
>> The most modular I can think of right now is just about creating a
>> gravity type and using multimethods for all your functions.
>>
>> This way you would have dynamic resolution of methods that do not work
On Tue, May 19, 2009 at 9:08 PM, George Jahad
wrote:
]> It seems like what you are really trying to do is simulate
> inheritance/overriding in clojure. What's wrong with using
> gen-class and proxy for that?
I guess it's still an open question as to whether gen-class and proxy
are mainly for Ja
On May 18, 9:56 am, Mark Engelberg wrote:
>
> So how to do this? As far as I can tell, these various modules are
> all "hard-linked" to point at one another, and I don't see how to make
> this linkage more dynamic. To change one file, I'd have to create new
> versions of ALL the files. It wou
On 19.05.2009, at 23:44, maxsu wrote:
> There, it's well defined and mathematical, and pretty neat; for
> example, we can have a equality module where all we have to do is give
> it a '<' function that knows how to compare a certain kind of data,
> and and we get back shiny and correct >, <=, >=
Don't call it monkey patching! We'll start to feel like we're in ruby,
writing code that relies on modifications to Object :).
In certain languages you can create modular units which are
incomplete, and require that the user supply custom functions and
constants in order to create an 'instance' o
>
> So how to do this? As far as I can tell, these various modules are
> all "hard-linked" to point at one another, and I don't see how to make
> this linkage more dynamic. To change one file, I'd have to create new
> versions of ALL the files. It would be great if each file could store
> a va
On Tue, May 19, 2009 at 6:18 AM, Meikel Brandmeyer wrote:
> I think the idea of decoupling is called "inversion of control"
> or "dependency injection". I'm sure it works for you, but it
> sure did in this (admittedly) simple example. There are
> various ways at passing around parameter:
> - glob
Hi,
Am 18.05.2009 um 18:56 schrieb Mark Engelberg:
OK, so let's talk more about what this glue code should look like.
I've been lumping this problem together with the other, because in my
mind they are related, but perhaps there is a clean way to glue
together modules without the incremental ex
On May 17, 3:24 pm, Mark Engelberg wrote:
> Thanks for your questions. I'll try to explain better.
>
> First, I'll explain that my line of work is to build tools to generate
> puzzles. I often have a module which generates the puzzles through
> various random processes, using certain probabil
On Mon, May 18, 2009 at 2:16 AM, Meikel Brandmeyer wrote:
> If that is true, you should maybe consider some glue.
>
> /- Analysis
> Glue -- Solve
> \- Create
>
> The Glue part combines/uses the different modules. There you
> could change parameters easily with binding, swap in another
> a
On Mon, May 18, 2009 at 4:23 AM, Laurent PETIT wrote:
> The most modular I can think of right now is just about creating a
> gravity type and using multimethods for all your functions.
>
> This way you would have dynamic resolution of methods that do not work
> with precompiled fns.
Can you elab
Hi,
The most modular I can think of right now is just about creating a
gravity type and using multimethods for all your functions.
This way you would have dynamic resolution of methods that do not work
with precompiled fns.
2009/5/17 Mark Engelberg :
>
> Thanks for your questions. I'll try to
Hi,
Am 18.05.2009 um 12:42 schrieb Konrad Hinsen:
Such a use of binding will lead to bad surprises as soon as you use
it with lazy sequences:
(map #(lcm % 6) (range 6))
-> (0 6 6 6 12 30)
(binding [clojure.contrib.math/gcd (fn [a b] 1)]
(map #(lcm % 6) (range 6)))
-> (0 6 6 6 12 30)
You ha
2009/5/18 Konrad Hinsen :
>
> On May 18, 2009, at 11:58, Adrian Cuthbertson wrote:
>
>> I know I keep plugging this - sorry - but it just keeps surfacing
>> as a solution;
>>
>> (lcm 4 6)
>> 12
>> (binding [clojure.contrib.math/gcd (fn [a b] 1)] (lcm 4 6))
>> 24
>
> Such a use of binding will lead
Aha! Thank you for clarifying that. Reinforces your point on
monkey-patching :). I will read your blog post with careful attention.
Adrian.
On Mon, May 18, 2009 at 12:42 PM, Konrad Hinsen
wrote:
>
> On May 18, 2009, at 11:58, Adrian Cuthbertson wrote:
>
>> I know I keep plugging this - sorry -
On May 18, 2009, at 11:58, Adrian Cuthbertson wrote:
> I know I keep plugging this - sorry - but it just keeps surfacing
> as a solution;
>
> (lcm 4 6)
> 12
> (binding [clojure.contrib.math/gcd (fn [a b] 1)] (lcm 4 6))
> 24
Such a use of binding will lead to bad surprises as soon as you use
On Mon, May 18, 2009 at 11:29 AM, Mark Reid wrote:
> ...
> test=> (lcm 4 6)
> 24
>
>
> Maybe a variant of ns could be written that allows the overriding of
> specific functions? e.g.,
>
I know I keep plugging this - sorry - but it just keeps surfacing as a solution;
(lcm 4 6)
12
(binding [
> What's wrong with this:
>
> user=> (ns test (:use [clojure.contrib.math :exclude (lcm)]))
> nil
> test=> (sqrt 2)
> 1.4142135623730951
> test=> (lcm 3 6)
> java.lang.Exception: Unable to resolve symbol: lcm in this context
> (NO_SOURCE_FILE:3)
> test=> (defn lcm [a b] 1)
> #'test/lcm
> test=> (l
On Mon, May 18, 2009 at 11:07 AM, Michael Wood wrote:
> On Mon, May 18, 2009 at 9:47 AM, Mark Engelberg
> wrote:
>>
>> On Sun, May 17, 2009 at 11:48 PM, Konrad Hinsen
>> wrote:
>>> It's the approach of "cloning and
>>> mutating" something that smells of "quick and dirty", although I
>>> agree
Hi,
Am 18.05.2009 um 09:47 schrieb Mark Engelberg:
As an example, I authored clojure.contrib.math. Someone came up with
a slightly faster algorithm for one of the functions (which is used in
turn by other functions in the library), but I can't include it unless
he signs a contributor agreement
On Mon, May 18, 2009 at 9:47 AM, Mark Engelberg
wrote:
>
> On Sun, May 17, 2009 at 11:48 PM, Konrad Hinsen
> wrote:
>> It's the approach of "cloning and
>> mutating" something that smells of "quick and dirty", although I
>> agree it is quite convenient in the prototyping phase.
>
> I disagree t
On May 18, 2009, at 9:47, Mark Engelberg wrote:
> On Sun, May 17, 2009 at 11:48 PM, Konrad Hinsen
> wrote:
>> It's the approach of "cloning and
>> mutating" something that smells of "quick and dirty", although I
>> agree it is quite convenient in the prototyping phase.
>
> I disagree that incre
On Mon, May 18, 2009 at 1:17 AM, Adrian Cuthbertson
wrote:
> (alter-var-root (var say-grav) (fn [_] (fn [x] (prn "my-version-grav:" x
But this only works if you only want one variation, and you no longer
care about the original version, right?. If you want to benchmark
your variation agains
> ... signs a contributor agreement. If he wants to create his own
> version of the module for his own personal use, in which he swaps out
> my function for his faster one, there appears to be no good way to do
> this, short of copying my entire file, commenting out my function, ...
I think Stua
On Sun, May 17, 2009 at 11:48 PM, Konrad Hinsen
wrote:
> It's the approach of "cloning and
> mutating" something that smells of "quick and dirty", although I
> agree it is quite convenient in the prototyping phase.
I disagree that incremental extension of a module is a "quick and
dirty" prototy
On 18.05.2009, at 08:05, Mark Engelberg wrote:
> David, that seems to work. I think I can achieve my objectives with
> this strategy.
David provided a much better implementation of the idea that I had
for this. I hadn't thought of the "load" function.
> However, I must admit, I find it rath
BTW, for those of you interested in reading academic papers about
modules in functional programming langs, I found this list of
articles:
http://www.readscheme.org/modules/
I remember reading about PLT Scheme's units several years ago, and I
think it's pretty much what I'm looking for, with the a
On 17.05.2009, at 21:24, Mark Engelberg wrote:
> For many years, my primary language for doing these sorts of programs
> has been Python. In my first pass, I just have a bunch of functions
> in a file with global variables at the top. For exploring simple
> changes, I can just import a file and
David, that seems to work. I think I can achieve my objectives with
this strategy.
However, I must admit, I find it rather unsettling that collections of
functions written inside of namespaces are fundamentally less
composable than those that are not. It means that to remain
extensible, I need
Oops your right. Perhaps this will work for you then.
;; gravity.clj (note we don't define an ns)
;; ===
(def *gravity* 1.0)
(defn say-grav [grav]
(prn "Gravity is:" grav))
(defn halve-grav []
(/ *gravity* 2.0))
(defn mult-grav [x]
(* *gravity* x))
On Sun, May 17, 2009 at 8:12 PM, David Nolen wrote:
> Have you looked at the immigrate function in Compojure? This imports public
> vars from a different namespace into a namespace as if they were defined
> there. Maybe this is enough to get the behavior that you want?
Not really. Consider the
Have you looked at the immigrate function in Compojure? This imports public
vars from a different namespace into a namespace as if they were defined
there. Maybe this is enough to get the behavior that you want?
On Sun, May 17, 2009 at 9:12 PM, Mark Engelberg wrote:
>
> On Sun, May 17, 2009 at 2:
On Sun, May 17, 2009 at 2:18 PM, mikel wrote:
> I'm still not quite clear on exactly what you're trying to accomplish.
> You showed how to accomplish your purpose in Clojure, but then
> suggested that the result was not 'clean'. It's not quite clear what
> you mean by 'clean'--that is, what featu
Hi Mark,
Not sure if this helps, but I've found it useful to mediate access to
global vars through a single function. Then I can swap in another
function to change the behavior. Here's an example from
http://tinyurl.com/qm8pj4
(defn get-property-function [name]
(System/getProperty name))
(d
On May 17, 2:24 pm, Mark Engelberg wrote:
> Thanks for your questions. I'll try to explain better.
I'm still not quite clear on exactly what you're trying to accomplish.
You showed how to accomplish your purpose in Clojure, but then
suggested that the result was not 'clean'. It's not quite cl
Thanks for your questions. I'll try to explain better.
First, I'll explain that my line of work is to build tools to generate
puzzles. I often have a module which generates the puzzles through
various random processes, using certain probabilities and parameters.
Then, I have another module that
On May 16, 10:45 pm, Mark Engelberg wrote:
> So I've built a file/namespace with several functions. There are
> several globals defined at the top of the file (for example,
> *gravity*) which many of the functions refer to. I made them globals
> precisely because it would have been a pain to
Hi Mark, I've used the following macro to achieve something like what
you're doing;
In the file/namespace module (say eg_globs/fns.clj);
(ns eg-globs.fns)
(declare *gravity*)
(defmacro with-grav
[grav & body]
`(let [gr# ~grav]
(binding [*gravity* gr#]
~...@body)))
(defn say-gra
So I've built a file/namespace with several functions. There are
several globals defined at the top of the file (for example,
*gravity*) which many of the functions refer to. I made them globals
precisely because it would have been a pain to thread them through
every single function that uses th
47 matches
Mail list logo