2008-08-11
| 02:42 | mada | hi! |
| 02:42 | mada | I am trying to use `pr' to print objects to a file but I must be doing something wrong. |
| 02:43 | mada | Here is the latest piece of code I have tested with: |
| 02:43 | mada | (with-open *out* (new java.io.FileOutputStream "/home/mathias/txt/.tags") |
| 02:43 | mada | (pr "Hello!")) |
| 02:43 | mada | I tried with a `let' as well, temporarily overriding the value of *out*. |
| 02:44 | mada | The file is created when the stream is instantiated but I get no data in it when printing to it. |
| 02:47 | kotarak | try something like this: (let [writer blabla] (binding [*out* writer] ....)) |
| 02:47 | kotarak | see: with-out-str in boot.clj for an example |
| 02:50 | kotarak | pr sees the global *out*. Defining with let a new *out* shadows this for the forms in the let, but not for pr. (This is the nature of a closure.) Binding modifies the global *out* which is seen by pr. |
| 03:25 | mada | kotarak: aha |
| 03:25 | mada | to me the doc is a bit confusing: "Prints the object(s) to the output stream that is the current value of *out*." |
| 03:25 | mada | and sounds like it would work with a let |
| 03:26 | mada | anyway, I will try according to what you replied. thx! |
| 03:40 | mada | kotarak: worked :) |
| 07:30 | albino | /window 12 |
| 07:30 | albino | sorry |
| 07:45 | rhickey | Chouser: finally getting to look at gen-interface. One thing - I would prefer there to be some grouping around each method spec, in case we need to extend it at some point. |
| 08:32 | Chouser | ok, that was something I wondered about -- thought I'd start with the minimal structure. |
| 08:33 | Chouser | So, list of vectors instead of series of triples? Or do you want a named list (:methods [...]) like gen-class has? |
| 08:34 | rhickey | list of vectors is probably fine |
| 08:39 | Chouser | I guess we can non-method options with :keyword prefixes as needed later. |
| 08:40 | rhickey | Chouser: I'm fine with following genclass too, this is not something to get overly succinct with |
| 08:41 | Chouser | hm. |
| 08:41 | Chouser | what did you think of having load-and-save as the default? |
| 08:42 | rhickey | Oh yeah - that's neat, but wouldn't it be more useful if it checked to see if already loaded? |
| 08:43 | rhickey | then could work at dev and run times |
| 08:44 | Chouser | if it's already loaded, would you want the (possibly updated) version being attempt to fail silently? |
| 08:44 | Chouser | "being attempted" |
| 08:45 | rhickey | There's no updating in any case |
| 08:45 | rhickey | so I guess yes |
| 08:46 | Chouser | right, updating is impossible. I guess it's just a question of silent or noisy failure. |
| 08:46 | Chouser | I don't have a grasp of the real use cases for this thing, so I'll just follow your instructions. :-) |
| 08:47 | rhickey | I guess the question is, if there was a version that only dynamically loaded, and failed noisily if already loaded, and a version that checked for already loaded and did nothing if so, which would you use in source files (i.e. non-interactively)? |
| 08:48 | Chouser | I guess the .class file *can* be updated though, even if an old version is already loaded. Should we let the .class file and loaded interface get out of sync? |
| 08:48 | rhickey | People are going to get a grip on "If I change loaded Java types I need to restart" at some point |
| 08:50 | Chouser | yep. Although I think a lot of the coming-from-Java people are actually in more danger of erring the other way, and "rebuilding" everything after any change. |
| 08:51 | rhickey | that's why gen-class separates the two parts, but no analogy in gen-interface |
| 08:54 | rhickey | you do have the tools to determine if it is an incompatible reload, just look up the methods in the existing class - see non-private-methods in genclass |
| 08:55 | Chouser | hm... so would it be good to do a silent "failure" if there're the same, and issue a warning or exception if they difffer? |
| 08:56 | rhickey | there's no failure if they are the same |
| 08:56 | Chouser | right, hence the quotes. |
| 08:58 | rhickey | that's the feature I am requesting, so a single file can gen and consume an interface, will work when loaded the first time, and will work at runtime. If different - throw |
| 08:59 | Chouser | ok, I'm on it. |
| 10:36 | Chouser | Is there any way to bind all the args of a fn? Like :as, but for the whole arg list. |
| 10:37 | rhickey | no |
| 10:38 | rhickey | short of just taking an & arg and destructuring that |
| 10:38 | Chouser | ok. ..and doing that messes up any useful doc references to arg names. |
| 10:41 | rhickey | you can use :arglists to map however you want - see the definition of defn |
| 10:42 | rhickey | (where docs don't agree with actuals) |
| 10:42 | Chouser | thanks, I had forgotten about that. |
| 11:34 | gruenero | hi everybody |
| 11:35 | gruenero | i am a clojure newbie |
| 11:35 | Chouser | hi |
| 11:35 | drewr | gruenero: Welcome! |
| 11:36 | gruenero | could anybody explain to me how one can correctly invoke clojure libraries into a clojure program? |
| 11:36 | gruenero | is it "refer" or "load-file" |
| 11:36 | gruenero | i dont get it from the mailing list or from clojure.org |
| 11:37 | gruenero | i am comming from the haskell world |
| 11:37 | gruenero | there it is "import MyModule" |
| 11:39 | Chouser | (load-file "foo.clj") will just load and run that file. Chances are it will create a namespace "foo". |
| 11:40 | Chouser | then you can use foo/this and foo/that, or you can alias foo to something else, or you can say (refer 'foo) to allow you to leave off the namespace entirely. |
| 11:43 | gruenero | okay, so the first step to correctly invoke a clojure file is "load-file" |
| 11:43 | gruenero | and then one has to care about the namespace |
| 11:43 | gruenero | right? |
| 11:43 | Chouser | yes |
| 11:44 | gruenero | thanx a lot |
| 11:44 | Chouser | there's a lib.clj in clojure-contrib that handles that and also finds .clj files anywhere in your classpath. |
| 11:44 | gruenero | I am just trying to achieve some clean modularity |
| 11:45 | Chouser | lib.clj is nice, but it's not part of Clojure proper quite yet, so you still have to you load-file or something to get started with it. |
| 11:45 | gruenero | okay |
| 11:46 | gruenero | another question: has anybody tried out the parallel.clj stuff |
| 11:46 | gruenero | ? |
| 11:47 | rhickey | I have |
| 11:47 | Chouser | I think there have been a couple posts to the forum with examples. |
| 11:47 | gruenero | :) |
| 11:47 | gruenero | one hast to invoke jsr166.jar when starting the repl right? |
| 11:47 | rhickey | yes, that has to be in your classpath |
| 11:48 | gruenero | okay |
| 11:49 | gruenero | i am trying to write some Tensor multiplication which uses parallelism from the get go... |
| 11:52 | gruenero | okay, thank you very much guys |
| 12:14 | Chouser | I can't think of a better way to do this than to convert both the interface specs given by the user and the existing class into a common format (which is neither the bytecode nor the raw specs). |
| 12:15 | Chouser | so instead of just api->bytecode I also need api->comparable and class->comparable. |
| 12:15 | Chouser | tedious. |
| 12:27 | rhickey | (set/index (set (map (fn [[name params ret]] |
| 12:27 | rhickey | {:name name :params params :ret ret}) |
| 12:27 | rhickey | (map first (non-private-methods java.util.Map)))) [:name]) |
| 12:28 | rhickey | then a similar set from your gen-interface method list, then use = |
| 12:30 | rhickey | indexing will group by method names, mapped to sets of sigs, so the entire index is comparable with = |
| 12:44 | Chouser | Currently you can gen interfaces that refer to non-loaded classes (by passing in a symbol or string instead of a class). Is that worth keeping? |
| 12:44 | Chouser | It complicates this process by requiring I resolve everything to something like strings instead of using equality directly on methods or classes. |
| 12:46 | rhickey | It's an outstanding feature request on gen-class that it support not-yet-loaded classes |
| 12:46 | Chouser | ok |
| 13:04 | Chouser | I need to consider the extends list too, right, not just the method list? |
| 13:04 | rhickey | for gen-interface? |
| 13:05 | Chouser | yes, when comparing old and new interfaces. |
| 13:06 | rhickey | I thought you were only doing this when already loaded, in which case you can call non-private-methods on the already-loaded interface class |
| 13:08 | rhickey | oh, yes I see, if the interface extends multiple interfaces - I guess, although likely to be different method lists |
| 13:08 | Chouser | yes, *very* likely to be different method lists. But swapping out one base interface for an identical one with a different name is still different. |
| 13:09 | rhickey | right |
| 13:10 | rhickey | I imagine you wish you had chosen silent failure on reload at this point :) |
| 13:10 | Chouser | hehe |
| 13:18 | Modius | Matthew Lamari |
| 14:12 | Chouser | does it matter in what order the base interfaces are given? |
| 15:14 | rhickey | Chouser: no |
| 16:31 | rhickey | anyone here have any experience with the IRIS Reasoner? |
| 18:02 | wwmorgan | is there a way to resolve specific symbols before passing them to a macro? |
| 18:07 | Chouser | wwmorgan: can you explain that more? maybe an example? |
| 18:08 | wwmorgan | I have a macro foo that does symbol manipulation, but I also want to be able to do (let [a 1] (foo a b c)) and have it resolve a, but leave b and c alone |
| 18:11 | Chouser | oh, you want the macro to resolve it? can you just splice it into your result and let it be resolved later, after expansion? |
| 18:14 | wwmorgan | yeah, that would work as long as I had a way of telling the macro which symbols to leave alone |
| 19:46 | Chouser | how are primitive parameter types specified for genclass? |
| 19:48 | rhickey | Float/TYPE etc |