keyword arguments
Hi, This may be a question without hope, but I'm thinking that asking never hurts. So here goes: The closest thing to keyword arguments that I have found is destructuring with a map: (defn myfun [ {:keys [arg1 arg2 arg3] :or {arg1 default-value} :as args}] ...) When I call myfun without specifying value for arg2 or arg3 I get an error, which is great. However, when I do this: (myfun :arg2 2 :arg3 3 :arg15 15) I don't get an error, because of the rest () thing. Do you know if this can be achieved with a nice syntax, and not check args in the code (i.e. checking should be done when evaluating/creating the function, and not when executing). Thanks, Razvan -- 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: Drift 1.4.0 released.
Sadly, there is no improvement. I've made a minimal project to demonstrate. Literally - lein new tdrift - modify project.clj - add migration-config.clj - add appropriate migration directory - lein deps - lein create-migration I've put it up on github (https://github.com/ejackson/tdrift). Perhaps if we can git it to work we can get to the bottom of this ? Thank for the help here, Edmund On 27/11/2011 00:39, Matt wrote: It looks like a bug in Drift. Try adding an init function which takes one argument but doesn't do anything. Your new migrate-config should look something like: (defn migrate-config [] {:init (fn [_] ) :directory /db/migrations :current-version db-version :update-version update-db-version}) Let me know if that does the trick and I'll fix the bug in Drift. On Nov 26, 8:31 am, Edmund edmundsjack...@gmail.com wrote: Hello, Thanks for this library, it'll really help me out. I'm a little stuck on getting bootstrapped, can you perhaps give me some guidance ? Basically I'm stuck at step 5, attempting to create my first migration, what am I missing ? Thanks, Edmund - Steps taken 1. Added to :dev-dependencies in project.clj [drift 1.4.0] [org.drift-db/drift-db-mysql 1.0.4] 2. Created a table to hold the version number inserted 0 create table schema_migrations ( version int not null primary key ) engine InnoDB; 3. Created src/config/migrate_config.clj (ns config.migrate-config (:require [clojure.contrib.sql :as sql])) (defonce DB (atom {:classname com.mysql.jdbc.Driver :subprotocol mysql :subname //mysql-server:3306/bookkeeper :user user :password password :auto-commit true :fetch-size 500})) (defn db-version [] (sql/with-connection DB (sql/with-query-results res [select version from schema_migrations limit 1] (:version (first res) (defn update-db-version [version] (sql/with-connection DB (sql/insert-values :schema_migrations [:version] [version]))) (defn migrate-config [] {:directory /db/migrations :current-version db-version :update-version update-db-version}) 4. Run lein deps to grab the deps 5. Attempted to create a migration, or get something going $ lein create-migration first Listening for transport dt_socket at address: 57528 Exception in thread main java.lang.RuntimeException: java.lang.NoSuchMethodError: clojure.lang.KeywordLookupSite.init(ILclojure/lang/Keyword;)V at clojure.lang.Util.runtimeException(Util.java:165) at clojure.lang.Compiler.eval(Compiler.java:6476) at clojure.lang.Compiler.eval(Compiler.java:6455) at clojure.lang.Compiler.load(Compiler.java:6902) at clojure.lang.RT.loadResourceScript(RT.java:357) at clojure.lang.RT.loadResourceScript(RT.java:348) at clojure.lang.RT.load(RT.java:427) at clojure.lang.RT.load(RT.java:398) at clojure.core$load$fn__4610.invoke(core.clj:5386) at clojure.core$load.doInvoke(core.clj:5385) at clojure.lang.RestFn.invoke(RestFn.java:408) at clojure.core$load_one.invoke(core.clj:5200) at clojure.core$load_lib.doInvoke(core.clj:5237) at clojure.lang.RestFn.applyTo(RestFn.java:142) at clojure.core$apply.invoke(core.clj:602) at clojure.core$load_libs.doInvoke(core.clj:5271) at clojure.lang.RestFn.applyTo(RestFn.java:137) at clojure.core$apply.invoke(core.clj:602) at clojure.core$require.doInvoke(core.clj:5352) at clojure.lang.RestFn.invoke(RestFn.java:421) at drift.generator$eval5$loading__4505__auto6.invoke(generator.clj:1) at drift.generator$eval5.invoke(generator.clj:1) at clojure.lang.Compiler.eval(Compiler.java:6465) at clojure.lang.Compiler.eval(Compiler.java:6455) at clojure.lang.Compiler.load(Compiler.java:6902) at clojure.lang.RT.loadResourceScript(RT.java:357) at clojure.lang.RT.loadResourceScript(RT.java:348) at clojure.lang.RT.load(RT.java:427) at clojure.lang.RT.load(RT.java:398) at clojure.core$load$fn__4610.invoke(core.clj:5386) at clojure.core$load.doInvoke(core.clj:5385) at clojure.lang.RestFn.invoke(RestFn.java:408) at clojure.core$load_one.invoke(core.clj:5200) at clojure.core$load_lib.doInvoke(core.clj:5237) at clojure.lang.RestFn.applyTo(RestFn.java:142) at clojure.core$apply.invoke(core.clj:602) at clojure.core$load_libs.doInvoke(core.clj:5271) at clojure.lang.RestFn.applyTo(RestFn.java:137) at clojure.core$apply.invoke(core.clj:602) at clojure.core$require.doInvoke(core.clj:5352) at clojure.lang.RestFn.invoke(RestFn.java:408) at user$eval1.invoke(NO_SOURCE_FILE:1) at clojure.lang.Compiler.eval(Compiler.java:6465) at clojure.lang.Compiler.eval(Compiler.java:6454) at clojure.lang.Compiler.eval(Compiler.java:6431) at clojure.core$eval.invoke(core.clj:2795) at clojure.main$eval_opt.invoke(main.clj:296) at clojure.main$initialize.invoke(main.clj:315) at clojure.main$null_opt.invoke(main.clj:348) at clojure.main$main.doInvoke(main.clj:426) at clojure.lang.RestFn.invoke(RestFn.java:421) at
Re: Drift 1.4.0 released.
My guess would be a clojure version mismatch, based on the stacktrace. Have you tried changing your project to use clojure 1.2.1? - Chris -- 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: Drift 1.4.0 released.
Bingo! Thanks for that, version 1.3.0 incompatibility it is. On 27/11/2011 13:41, Chris Perkins wrote: My guess would be a clojure version mismatch, based on the stacktrace. Have you tried changing your project to use clojure 1.2.1? - Chris -- 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: Drift 1.4.0 released.
I just sent you a pull request to fix the Clojure 1.3 incompatibility. Also, you may want to use the current-version and update-version functions in drift-db.migrate instead of your own home grown functions. Though you would have to create your own initialize function to initialize the drift-db flavor to mysql. -Matt On Nov 27, 9:25 am, Edmund edmundsjack...@gmail.com wrote: Bingo! Thanks for that, version 1.3.0 incompatibility it is. -- 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: keyword arguments
You can use the :pre and :post assertions on functions. Something like the following would do what you are asking: (defn myfun [ {:keys [arg1 arg2 arg3] :or {arg1 default-value} :as args}] {:pre [(every? #{:arg1 :arg2 :arg3} (keys args))]} (println arg1 arg2 arg3 args: args)) Also, another way to take keyword arguments is: (defn foo [ opts] (let [opts (apply hash-map opts)] (println opts))) - Mark On Sun, Nov 27, 2011 at 5:57 AM, Razvan Rotaru razvan.rot...@gmail.com wrote: Hi, This may be a question without hope, but I'm thinking that asking never hurts. So here goes: The closest thing to keyword arguments that I have found is destructuring with a map: (defn myfun [ {:keys [arg1 arg2 arg3] :or {arg1 default-value} :as args}] ...) When I call myfun without specifying value for arg2 or arg3 I get an error, which is great. However, when I do this: (myfun :arg2 2 :arg3 3 :arg15 15) I don't get an error, because of the rest () thing. Do you know if this can be achieved with a nice syntax, and not check args in the code (i.e. checking should be done when evaluating/creating the function, and not when executing). Thanks, Razvan -- 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
[lein] Depending on tools.jar
Is there any way in Leiningen to add a dependency on the JDK's tools.jar? Apparently it is possible with maven [1] I was thinking of porting my liverepl[2] utility over to leiningen to make it a bit easier to install, and easier to run without scripts, it uses the JDK's Attach API from tools.jar in order to connect to arbitrary Java processes. [1] http://maven.apache.org/general.html#tools-jar-dependency [2] https://github.com/djpowell/liverepl -- 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
Re: [lein] Depending on tools.jar
On Sun, Nov 27, 2011 at 10:47 AM, David Powell djpow...@djpowell.net wrote: Is there any way in Leiningen to add a dependency on the JDK's tools.jar? Apparently it is possible with maven [1] I was thinking of porting my liverepl[2] utility over to leiningen to make it a bit easier to install, and easier to run without scripts, it uses the JDK's Attach API from tools.jar in order to connect to arbitrary Java processes. You might be able to symlink tools.jar from java.home into ~/.lein/plugins -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
Better way to do this ? deep-merge-with-keys
For a project I'm working on, I wanted some variants of merge-with and deep-merge-with that would also provide information about the keys where collisions were occurring. I have (based on minimal testing) a working implementation, but it feels like there should be a simpler way to do this - I ended up copying and minimally modifying the source for merge-with and deep-merge-with, but I would be interested in any improvements people might suggest. In particular, I feel like what I'm doing with the collect function is possibly a bit obtuse, but nothing more obvious came readily to mind. https://gist.github.com/1398181 -- 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: keyword arguments
On Nov 27, 8:43 am, Mark Rathwell mark.rathw...@gmail.com wrote: Also, another way to take keyword arguments is: (defn foo [ opts] (let [opts (apply hash-map opts)] (println opts))) This is what already happens internally with the {:keys ...} notation. You can actually be rather more concise if you write: (defn foo [ {:as opts}] (println opts)) -- 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: keyword arguments
Yeah, laziness on my part, I was just trying to show that everything after '' comes in as a list, and you can be creative if you need to be. I use this on occasion for macros with multiple different types of optional arguments. On Sun, Nov 27, 2011 at 6:45 PM, Alan Malloy a...@malloys.org wrote: On Nov 27, 8:43 am, Mark Rathwell mark.rathw...@gmail.com wrote: Also, another way to take keyword arguments is: (defn foo [ opts] (let [opts (apply hash-map opts)] (println opts))) This is what already happens internally with the {:keys ...} notation. You can actually be rather more concise if you write: (defn foo [ {:as opts}] (println opts)) -- 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: clojure-jsr223 and shibboleth ScriptedAttributeDefinition
Thank you very much, it works! The correct script is: resolver:AttributeDefinition id=cljattr xsi:type=Script language=Clojure xmlns=urn:mace:shibboleth:2.0:resolver:ad resolver:AttributeEncoder xsi:type=SAML1String xmlns=urn:mace:shibboleth:2.0:attribute:encoder name=urn:mace:dir:attribute-def:cljattr / resolver:AttributeEncoder xsi:type=SAML2String xmlns=urn:mace:shibboleth:2.0:attribute:encoder name=urn:mace:unimore.it:attribute-def:cljattr friendlyName=cljattr / Script ![CDATA[ (import org.slf4j.LoggerFactory) (import edu.internet2.middleware.shibboleth.common.attribute.provider.BasicAttribute) (def logger (. org.slf4j.LoggerFactory getLogger edu.internet2.middleware.shibboleth.resolver.Script.cljattr)) (def cljattr (BasicAttribute. cljattr)) (.add (.getValues cljattr) CLOJURE) (.info logger (str cljattr: (.getValues cljattr))) ]] /Script /resolver:AttributeDefinition Thank you for the quick answer! Francesco -- 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
Want some books or issues about ClojureCLR
I am learning Clojure and I use the CLR version. But I can not find a book about Clojure CLR, just for Clojure and java. I want someone give me suggestions about the book or issues of Clojure CLR. Thanks a lot. -- 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: Lookup on a symbol?
On Nov 24, 2011, at 12:32 AM, Sean Corfield wrote: @lloyda2 posted on Twitter: (reduce 'and '(false true)) = true ...Huh? I must admit, it looked odd to me... but I realized (after some REPL experimentation) this seems to be equivalent to ('some-symbol :some-key :some-default) I saw the tweet too - and after experimenting in REPL - replied to it that in this case 'and is just a symbol and 'foo works just the same. Can someone provide a bit more insight into why clojure.lang.Symbol behaves like a collection and what, if any elements does it have? Also interested in learning more, but I concluded (erroneously?) that it is false that is being indexed into: (:a false) returns nil as does ('and false) and (get false 2); I assumed it was so that it would fail gracefully if encountered where a collection was expected. bill -- 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
ANN: template based web v0.1.0
Hello I've just released the first RC1 of my first Clojure toy project[1]. This is basically old style put tags in HTML and process such tags in your code. I copied the idea from html-template[2]. Because this is my first Clojure coding effort, there might be mistakes. Any comment and suggestion will be appreciated. You can check how to use tbw from an example application[3](copied from Mark McGranaghan's Developing and Deploying a Simple Clojure Web Application[4]) Thanks Jong-won Choi [1]:https://github.com/defstruct/tbw [2]:http://weitz.de/html-template/ [3]:https://github.com/defstruct/tbw/blob/master/examples/adder.clj [4]:http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web- applications.html -- 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: Clojure on PyPy
On Thursday, November 17, 2011 5:09:49 PM UTC+1, tbc++ wrote: I also felt that sticking with the official Java implementation of Clojure would be more practical. It would certainly be fun to put Clojure on PyPy, though. There is one insanely off-the-wall idea I've been thinking about recently, however: 1) Implement a full JVM in PyPy using GNU Classpath. Write a Java bytecode interpreter in PyPy. This way you get the power of PyPy (tracing JIT) with the power of Java (classpath) IMO better to hack on VMKit (llvm) than to start a new one atop of PyPy. -- 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: ClojureScript new branches - feedback please
'prop-lookup'++. First thing that really tricked me up with ClojureScript is (goog.net.XhrIo/send uri #(.getResponseJson (.target %))) blowing up in my face as it isn't using getResponseJson() but rather returning the function. Ended up using (.getResponseJson (...) nil) to work around it. -- 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
Head holding issue
Hi, I have the following code that I'm trying to use to split a sequence of strings into files of approx. x-size (defn split-file ([path strs split-size] (loop [ss (seq strs), part 0] (when-let [more (split-file path ss split-size part)] (recur more (inc part) ([path strs split-size part] (with-open [stream (clojure.java.io/output-stream (str path . part))] (loop [size 0, ss strs] (when ss (if ( split-size size) ss (let [bs (.getBytes (first ss))] (.write stream bs) (recur (+ size (alength bs)) (next ss) When I call it like: (with-open [rdr (clojure.java.io/reader big-file)] (dorun (bw/split-file foo (line-seq rdr) (* 300 1024 1024) 0))) that is to get the first 500 MB split, it runs fine. However, when I run it like: (with-open [rdr (clojure.java.io/reader big-file)] (dorun (bw/split-file foo (line-seq rdr) (* 300 1024 1024 that is when I call the 4 parameter version of split-file, it uses much more memory and runs much slower, even while working on the first split. When the code eventually gets to the second split, memory usage goes back down. So I'm convinced that: ([path strs split-size] (loop [ss (seq strs), part 0] (when-let [more (split-file path ss split-size part)] (recur more (inc part) is holding onto the head, but I thought the clojure (I'm using version 1.3.0) optimizes that out? -- 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: [core.logic] Incorporating a database as a source of facts
As Mark said you can avoid the graph issue with tabling. core.logic has tabling. If you look at the tabling section here - https://github.com/clojure/core.logic, you should see something related to your problem. While defrel/facts are neat - they are really intended for people who don't already have a bunch of data already in memory. If you do then you should probably just write you own goals that can source data from your graph. This can easily be done by returning a Choice from your custom goal. (defn custom-goal [x y z] ... (choice a (fn [] ...)) choice is like a lazy sequence, you have your first value, and then a thunk to produce the remainder of the sequence. You can do whatever you want in the body of the custom-goal to make sure the optimal resultset is operated on. For example, you might have indexed your data on the possible values x, or y, or z. You can check to see if in this call to your custom-goal whether x, y, or z are ground, that is, they are either not logic variables, or they are logic variables that are bound to values. If they are you can use those values to looked at the indexed version of your data. I plan to document this more. If you examine the defrel/fact architecture you can see exactly how this done. David On Thu, Nov 24, 2011 at 3:49 AM, Tassilo Horn tass...@member.fsf.orgwrote: Mark markaddle...@gmail.com writes: Hi Mark, Let's take a specific example: Suppose I have a Person table with id, name and gender columns. Then, I have a Parent-Child table that contains two id columns, both of which are foreign keys back into the Person table. I'd could use the logic system to define a set of rules about family relationships. I could express a query in logic terms which would then be translated into a series of SQL calls to obtain the results (forget any optimization concerns for the moment). I'm pretty much experimenting in the same direction, but not with databases but with graphs. Currently, my approach is to translate the graph's schema (type graph) to a set of relations. For example, if the schema defines a node type Person, I generate a (defrel +Person x) which succeeds if x is a Person vertex. If the schema defines an edge type Knows between Person, I generate a relation (defrel +Knows e a o) which succeeds if e is a Knows edge starting at a node a and ending at a node e. (There are also relations for the attributes of nodes and edges.) Those relations are then populated with facts about the graph. Then I can use core.logic to query the graph in terms of a fact base. For example, here's a query on a graph representing a route map that finds for any County the City being its capital. (with-fresh is only a convenience macro that expands into a `fresh' declaring fresh logic vars for all the ?variables.) (run* [q] (with-fresh (+Locality ?loc) (+ContainsLocality _ ?county ?loc) (+HasCapital _ ?county ?capital) (!= ?capital ?loc) (+name ?capital ?cname) (+name ?loc ?lname) (== q [?cname ?lname]))) Basically, that works pretty well, but there are some issues, which are probably because I take the wrong approach. First, it's very memory intensive. I have the graph in memory anyway, and basically I duplicate it into the relations. That doesn't feel correct. Second, with my simply translation approach, when I'd change the graph, the relations would be out of sync... Basically, I'd like to be able to define the relations that I have right now, at least interface-wise. But instead of duplicating the graph in facts, I'd like to give an own implementation directly on the graph. I mean, for all these relations I can easily tell when they succeed. For examle, for (+ContainsLocality e a b), if b is given, I can tell the valid bindings for e and a in O(degree(b)). Third, it quickly becomes very slow when I define some recursive relations like that: --8---cut here---start-8--- (defn connected Succeeds, if the junctions j1 and j2 are connected by connections (Ways, Streets, AirRoutes). [j1 j2] (with-fresh (conde ((+Connection _ j1 j2)) ((+Connection _ j2 j1)) ((connected j1 ?middle) (connected ?middle j2) (defn connected-locs Succeeds, if the localities l1 and l2 are connected. Localities are connected, if they contain crossroads that are connected by connections (Ways, Streets, AirRoutes). [l1 l2] (with-fresh (conde ((+Airport! l1) (+Airport! l2) (connected l1 l2)) ((+ContainsCrossroad _ l1 ?c1) (connected ?c1 ?c2) (+ContainsCrossroad _ l2 ?c2) ;; What locality is connected with what other locality? (run 250 [q] (with-fresh (+Locality ?l1) (+Locality ?l2) (!= ?l1 ?l2)(connected-locs ?l1 ?l2) (== q [?l1 ?l2]))) --8---cut
Re: examples of using protocols for extending functionality of existing classes?
Thank you very much, Tassilo! Are Graph and Vertex classes from the public API? On 24 ноя, 13:02, Tassilo Horn tass...@member.fsf.org wrote: ru soro...@oogis.ru writes: Can anybody point out good (idiomatic) examples of using protocols for extending functionality of existing classes? Here's one that I have in my code: --8---cut here---start-8--- (defprotocol VSeq Protocol for types supporting vseq. (vseq-internal [this tm] Returns a lazy seq of the graph's vertices restricted by type matcher `tm', or the vertices following this vertex.)) (extend-protocol VSeq Graph (vseq-internal [g tm] (lazy-seq (let [f (first-vertex g tm)] (and f (cons f (vseq-internal f tm)) Vertex (vseq-internal [v tm] (lazy-seq (let [n (next-vertex v tm)] (and n (cons n (vseq-internal n tm))) --8---cut here---end---8--- Graph and Vertex are existing Java classes. Bye, Tassilo -- (What the world needs (I think) is not (a Lisp (with fewer parentheses)) but (an English (with more.))) Brian Hayes,http://tinyurl.com/3y9l2kf -- 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: [core.logic] Incorporating a database as a source of facts
By examining to-stream https://github.com/clojure/core.logic/blob/master/src/main/clojure/clojure/core/logic.clj#L1413and extend-rel https://github.com/clojure/core.logic/blob/master/src/main/clojure/clojure/core/logic.clj#L1527you should be able to see how to turn any Clojure sequence into a stream of facts that you can plug into a core.logic program. I admit this isn't exposed because I haven't thought about an ideal general interface. I will get around to this, but it's not a high priority at the moment - deep in other implementation issues. However I would love to see discussion on this front and will certainly help move things along if someone is willing to do the design work. David On Thu, Nov 24, 2011 at 11:15 AM, David Nolen dnolen.li...@gmail.comwrote: As Mark said you can avoid the graph issue with tabling. core.logic has tabling. If you look at the tabling section here - https://github.com/clojure/core.logic, you should see something related to your problem. While defrel/facts are neat - they are really intended for people who don't already have a bunch of data already in memory. If you do then you should probably just write you own goals that can source data from your graph. This can easily be done by returning a Choice from your custom goal. (defn custom-goal [x y z] ... (choice a (fn [] ...)) choice is like a lazy sequence, you have your first value, and then a thunk to produce the remainder of the sequence. You can do whatever you want in the body of the custom-goal to make sure the optimal resultset is operated on. For example, you might have indexed your data on the possible values x, or y, or z. You can check to see if in this call to your custom-goal whether x, y, or z are ground, that is, they are either not logic variables, or they are logic variables that are bound to values. If they are you can use those values to looked at the indexed version of your data. I plan to document this more. If you examine the defrel/fact architecture you can see exactly how this done. David On Thu, Nov 24, 2011 at 3:49 AM, Tassilo Horn tass...@member.fsf.orgwrote: Mark markaddle...@gmail.com writes: Hi Mark, Let's take a specific example: Suppose I have a Person table with id, name and gender columns. Then, I have a Parent-Child table that contains two id columns, both of which are foreign keys back into the Person table. I'd could use the logic system to define a set of rules about family relationships. I could express a query in logic terms which would then be translated into a series of SQL calls to obtain the results (forget any optimization concerns for the moment). I'm pretty much experimenting in the same direction, but not with databases but with graphs. Currently, my approach is to translate the graph's schema (type graph) to a set of relations. For example, if the schema defines a node type Person, I generate a (defrel +Person x) which succeeds if x is a Person vertex. If the schema defines an edge type Knows between Person, I generate a relation (defrel +Knows e a o) which succeeds if e is a Knows edge starting at a node a and ending at a node e. (There are also relations for the attributes of nodes and edges.) Those relations are then populated with facts about the graph. Then I can use core.logic to query the graph in terms of a fact base. For example, here's a query on a graph representing a route map that finds for any County the City being its capital. (with-fresh is only a convenience macro that expands into a `fresh' declaring fresh logic vars for all the ?variables.) (run* [q] (with-fresh (+Locality ?loc) (+ContainsLocality _ ?county ?loc) (+HasCapital _ ?county ?capital) (!= ?capital ?loc) (+name ?capital ?cname) (+name ?loc ?lname) (== q [?cname ?lname]))) Basically, that works pretty well, but there are some issues, which are probably because I take the wrong approach. First, it's very memory intensive. I have the graph in memory anyway, and basically I duplicate it into the relations. That doesn't feel correct. Second, with my simply translation approach, when I'd change the graph, the relations would be out of sync... Basically, I'd like to be able to define the relations that I have right now, at least interface-wise. But instead of duplicating the graph in facts, I'd like to give an own implementation directly on the graph. I mean, for all these relations I can easily tell when they succeed. For examle, for (+ContainsLocality e a b), if b is given, I can tell the valid bindings for e and a in O(degree(b)). Third, it quickly becomes very slow when I define some recursive relations like that: --8---cut here---start-8--- (defn connected Succeeds, if the junctions j1 and j2 are connected by connections (Ways, Streets, AirRoutes). [j1 j2] (with-fresh
Re: examples of using protocols for extending functionality of existing classes?
Thank you very much, Tassilo! Are Graph and Vertex classes from the public API? On 24 ноя, 12:02, Tassilo Horn tass...@member.fsf.org wrote: ru soro...@oogis.ru writes: Can anybody point out good (idiomatic) examples of using protocols for extending functionality of existing classes? Here's one that I have in my code: --8---cut here---start-8--- (defprotocol VSeq Protocol for types supporting vseq. (vseq-internal [this tm] Returns a lazy seq of the graph's vertices restricted by type matcher `tm', or the vertices following this vertex.)) (extend-protocol VSeq Graph (vseq-internal [g tm] (lazy-seq (let [f (first-vertex g tm)] (and f (cons f (vseq-internal f tm)) Vertex (vseq-internal [v tm] (lazy-seq (let [n (next-vertex v tm)] (and n (cons n (vseq-internal n tm))) --8---cut here---end---8--- Graph and Vertex are existing Java classes. Bye, Tassilo -- (What the world needs (I think) is not (a Lisp (with fewer parentheses)) but (an English (with more.))) Brian Hayes,http://tinyurl.com/3y9l2kf -- 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: Lookup on a symbol?
No that doesn't make any sense, but I (think I) know what is going on there. (:a 1 2) === (get 1 :a 2) Jong-won On Nov 25, 1:35 pm, jaime xiejianm...@gmail.com wrote: But we still don't know why it behaves like this and for what reason. does (:a 1 2) returns 2 make any sense?? -- 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: Lookup on a symbol?
I'd expect the same, but in the code (https://github.com/clojure/ clojure/blob/master/src/jvm/clojure/lang/RT.java) get and getFrom do not raise any error. On Nov 24, 6:30 pm, Sean Corfield seancorfi...@gmail.com wrote: (:a 1 2) yields 2 which surprises me a bit... I'd expect an error because 1 is not a collection that :a can look itself up in. -- 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
How can we Laucnh REPL from java Swing application?
Instead of typing java -cp clojure.jar clojure.main on Cygwin/ console to run some Clojure Script, Is it possible to make a GUI which should show us REPL as myREPL=. There we should be able to write commands and execute. -- 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 1.3 head holding bug
Hi, I've a head holding problem that I believe is a bug in clojure 1.3. I wrote the following function to split a a lazy seq of strings across files of x size: (defn split-file ([path strs size] (trampoline split-file path (seq strs) size 0)) ([path strs size part] (with-open [f (clojure.java.io/writer (str path . part))] (loop [written 0, ss strs] (when ss (if (= written size) #(split-file path ss size (inc part)) (let [s (first ss)] (.write f s) (recur (+ written (.length s)) (next ss) If I call the 3 arg version of the function: (split-file foo (repeat 1 blah blah blah) 1) I see memory usage increases as I'm writing each file with the usual gc slow down, then memory usage goes back down again as I get to a new split file. Memory usage is fine if I call the 4 arg version (which only writes one part of the split file): (split-file foo (repeat 1 blah blah blah) 1 0) I can also avoid the head holding problem by removing trampoline and recursively calling split-file directly, but then those recursive calls use up stack and don't close files until all calls complete -- 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
Using Clojure on a Mac
Hi, I've just installed Clojure 1.3 on a MBP, OSX 10.6.8. After unzipping the download, I'm left with a directory with a few .jar files and two subdirectories. (I'm also a Java newb too) How do I run Clojure? 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
Error running Clojure 1.3 on OSX 10.6.8
When I launch Clojure, the following is displayed java -cp clojure.jar clojure.main Exception in thread main java.lang.NoClassDefFoundError: clojure/main Caused by: java.lang.ClassNotFoundException: clojure.main at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247 Would someone explain what happened? I've followed the directions here http://clojure.org/getting_started -- 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: Using Clojure on a Mac
On Sat, Nov 26, 2011 at 10:15 PM, Clojure NewB cappy2...@gmail.com wrote: I've just installed Clojure 1.3 on a MBP, OSX 10.6.8. ... How do I run Clojure? The best way to get Clojure up and running is to use Leiningen so you don't have to deal with classpaths etc. http://charlie.griefer.com/blog/2011/08/03/clojure-in-3-minutes/ -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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: Error running Clojure 1.3 on OSX 10.6.8
On Sat, Nov 26, 2011 at 10:30 PM, Clojure NewB cappy2...@gmail.com wrote: When I launch Clojure, the following is displayed ... Would someone explain what happened? I've followed the directions here http://clojure.org/getting_started See my other reply: don't worry about the bare Clojure library or trying to run it via Java. Use Leiningen instead. It makes life so much easier. What IDE / editor are you currently using for programming? (that'll give us a better idea of what to suggest for a Clojure IDE / editor for you) -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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: [core.logic] Incorporating a database as a source of facts
David Nolen dnolen.li...@gmail.com writes: Hi David, As Mark said you can avoid the graph issue with tabling. core.logic has tabling. If you look at the tabling section here - https://github.com/clojure/core.logic, you should see something related to your problem. Thanks, I'll have a look. If you do then you should probably just write you own goals that can source data from your graph. This can easily be done by returning a Choice from your custom goal. (defn custom-goal [x y z] ... (choice a (fn [] ...)) choice is like a lazy sequence, you have your first value, and then a thunk to produce the remainder of the sequence. You can do whatever you want in the body of the custom-goal to make sure the optimal resultset is operated on. Great, that looks exactly what I need. Bye, Tassilo -- (What the world needs (I think) is not (a Lisp (with fewer parentheses)) but (an English (with more.))) Brian Hayes, http://tinyurl.com/3y9l2kf -- 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