Re: Executing Future
The problem was elsewhere but I realized that Clojure has support for futures at the level of the language even though it relies on java.util.concurrent. So I have this question. I have heard that Clojure's data structures are immutable and it has support for promises, agents, atoms etc. What exactly is meant by this ? Is it that all of these Clojure language featues are based on java.util.concurrent ? I am still learning FP and Clojure but I want to know if I am assuming something totally wrong here. All of these language featues seem to depend on java.util.concurrent. What about STM ? Is that a new idea based on the same Java library ? -- 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: newbie question
Simple switch from openjdk to sun-java6 problem resolved. On Apr 22, 8:18 pm, lesni bleble wrote: > hello again, > > i have another problem. I'm trying simple applet: > > $ cat src/foo/applet.clj > > (ns foo.applet > (:import (java.awt Graphics2D Graphics Frame Color Image Toolkit)) > (:gen-class > :extends java.applet.Applet)) > > (defn -paint [#^Applet applet #^Graphics2D g] > (.drawString g "Hello from Clojure!" 50 50)) > > $ cat project.clj > > (defproject foo "1.0.0-SNAPSHOT" > :description "FIXME: write description" > :aot [foo.applet] > :warn-on-reflections true > :uberjar-name "foo-full.jar" > :dependencies [[org.clojure/clojure "1.2.1"]]) > > $ cat index.html > > > > archive="foo-full.jar" > code="foo.applet.class" > width="400" > height="400"> > > > > > $ lein uberjar > $ appletviewer index.html > it works nice > > $ firefox index.html > OpenJDK Runtime Environment (IcedTea6 1.8.7) (6b18-1.8.7-2) > OpenJDK Server VM (build 16.0-b13, mixed mode) > Exception in thread "Applet" java.lang.ExceptionInInitializerError > at clojure.lang.Namespace.(Namespace.java:34) > at clojure.lang.Namespace.findOrCreate(Namespace.java:176) > at clojure.lang.Var.internPrivate(Var.java:94) > at foo.applet.(Unknown Source) > at > sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) > at > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java: > 57) > at > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java: > 45) > at java.lang.reflect.Constructor.newInstance(Constructor.java: > 532) > at java.lang.Class.newInstance0(Class.java:372) > at java.lang.Class.newInstance(Class.java:325) > at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java: > 588) > at net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:548) > at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java: > 729) > Caused by: java.lang.RuntimeException: > java.security.AccessControlException: access denied > (java.lang.RuntimePermission getClassLoader) > at clojure.lang.RT.(RT.java:305) > ... 13 more > Caused by: java.security.AccessControlException: access denied > (java.lang.RuntimePermission getClassLoader) > at > java.security.AccessControlContext.checkPermission(AccessControlContext.java: > 393) > at > java.security.AccessController.checkPermission(AccessController.java: > 553) > at > java.lang.SecurityManager.checkPermission(SecurityManager.java:549) > at > net.sourceforge.jnlp.runtime.JNLPSecurityManager.checkPermission(JNLPSecurityManager.java: > 250) > at java.lang.Thread.getContextClassLoader(Thread.java:1338) > at clojure.lang.RT.baseLoader(RT.java:1560) > at clojure.lang.RT.load(RT.java:387) > at clojure.lang.RT.load(RT.java:381) > at clojure.lang.RT.doInit(RT.java:416) > at clojure.lang.RT.(RT.java:302) > ... 13 more > java.lang.NullPointerException > at net.sourceforge.jnlp.NetxPanel.runLoader(NetxPanel.java:99) > at sun.applet.AppletPanel.run(AppletPanel.java:380) > at java.lang.Thread.run(Thread.java:636) > java.lang.NullPointerException > at sun.applet.AppletPanel.run(AppletPanel.java:430) > at java.lang.Thread.run(Thread.java:636) > > signing is needed? I found this examplehttp://chouser.n01se.net/misc/tree.html > which doesn't seems to be signed but it works. I'm confused -- 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: How to determine a function name at runtime
There should be a way to print the currently executing function and the calling function logging purposes ? I believe Java has StackTraceElement[] to do this. Thanks, Mohan -- 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: Executing Future
"So I have this question. I have heard that Clojure's data structures are immutable and it has support for promises, agents, atoms etc." It's not that clojure's data structures support promises, agents ... It's more like promises, agents ... support clojure's data structures. "Changing" something in an agent doesn't actually change the data itself, it only changes where the agent "points", so to speak. For example: (def a 3) (def b (agent a)) (send b inc) a => 3 ; a is never changed! @b => 4 ; instead, a new value is created, which b now points to. Atom source: https://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/Atom.java About STM: http://java.ociweb.com/mark/stm/article.html#PersistentDataStructures On Thu, Apr 28, 2011 at 11:20 AM, MohanR wrote: > The problem was elsewhere but I realized that Clojure has support for > futures at the level of the language even though it relies on > java.util.concurrent. > > So I have this question. I have heard that Clojure's data structures > are immutable and it has support for promises, agents, atoms etc. > > What exactly is meant by this ? Is it that all of these Clojure > language featues are based on java.util.concurrent ? > > I am still learning FP and Clojure but I want to know if I am assuming > something totally wrong here. All of these language featues seem to > depend on java.util.concurrent. > > What about STM ? Is that a new idea based on the same Java library ? > > -- > 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: Executing Future
Another great resource for Clojure is ClojureDocs. The doc for 'future' has a simple example: http://clojuredocs.org/clojure_core/clojure.core/future Not only does it show you the doc string and an example, if your scroll down you can see the source code for the function. You'll see that lot of language level constructs (future, promise, etc) use some form of the java.util.concurrent stuff, but add on to it. Some stuff (agents, atoms, etc) can be found here: https://github.com/clojure/clojure/tree/master/src/jvm/clojure/lang if you want to look through the entire source (I definitely recommend it!) Paul On Apr 28, 6:46 am, Jonathan Fischer Friberg wrote: > "So I have this question. I have heard that Clojure's data structures > are immutable and it has support for promises, agents, atoms etc." > > It's not that clojure's data structures support promises, agents ... > It's more like promises, agents ... support clojure's data structures. > > "Changing" something in an agent doesn't actually change the data itself, it > only changes where the agent "points", so to speak. > For example: > (def a 3) > (def b (agent a)) > (send b inc) > a => 3 ; a is never changed! > @b => 4 ; instead, a new value is created, which b now points to. > > Atom > source:https://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lan... > > About > STM:http://java.ociweb.com/mark/stm/article.html#PersistentDataStructures > > On Thu, Apr 28, 2011 at 11:20 AM, MohanR wrote: > > > > > > > > > The problem was elsewhere but I realized that Clojure has support for > > futures at the level of the language even though it relies on > > java.util.concurrent. > > > So I have this question. I have heard that Clojure's data structures > > are immutable and it has support for promises, agents, atoms etc. > > > What exactly is meant by this ? Is it that all of these Clojure > > language featues are based on java.util.concurrent ? > > > I am still learning FP and Clojure but I want to know if I am assuming > > something totally wrong here. All of these language featues seem to > > depend on java.util.concurrent. > > > What about STM ? Is that a new idea based on the same Java library ? > > > -- > > 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: (just) emacs mode
On Apr 28, 6:23 am, Phil Hagelberg wrote: > On Apr 27, 6:07 am, John V wrote: > > > So, I would include info about using -*- in > > the .clj file and how to modify the auto-mode-alist and enable or > > disable fontifying the buffer. > > This is the kind of thing that package.el does for you, (along with > autoloading and byte-compiling) which is why doing it manually is not > explained. Ah, ok. That could be handy. It is pretty awkward the old-fashioned way. But how does it do it? By writing out files into .emacs or .emacs.d? > It's more awkward right now because package.el is not included in > Emacs 23, but once Emacs 24 is released, you won't have to install > package.el yourself. > > -Phil OK, but that wasn't my issue. I did install package.el myself. The problem was the functionality of package.el, not the installation. There's definitely something to be said for a simple "do it all" installation, but the details shouldn't be completely hidden. I'd like to have the ability to understand what I'm downloading and what the installation will change. In any case, clojure-mode.el is working fine for me, so for now, I'm happy. :) 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
Logos -> core.logic
Logos has been accepted into Clojure contrib: https://github.com/clojure/core.logic. There's a considerable amount of work still to do but I'm excited to see how the Clojure community might take advantage of a logic programming library. Two things I'd like to see: 1) Make it faster (it's pretty darn fast, but I like faster) 2) Use to write Clojure programs/extensions that would otherwise be unnecessarily difficult to implement As far as 2, I'm currently brainstorming efficient predicate dispatch, but I also think there are some opportunities to add an a la carte type system to Clojure as well. Feel free to ask any questions- from what I can tell, logic/relational programming is a paradigm that is not nearly as well known as functional programming. I'll probably create a step-by-step tutorial soon to help out on this front. For over-achievers who just want to dive in two texts make it quite clear how this library works - The Reasoned Schemer ( http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10663) and William Byrd's dissertation ( http://pqdtopen.proquest.com/#abstract?dispub=3380156) David -- 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: dead simple compile to jar file
On Wed, 27 Apr 2011 10:45:58 -0700 (PDT) cej38 wrote: > Hi, > I would like the simplest method to compile a few lines of clojure > code into a jar file that I can distribute to some fellow scientists > that don't know much (if anything) about java or clojure. Since I am > not creating a huge product that I will be updating often, maven and > Lenningen seem like overkill. The compiled jar file should contain > the relevant clojure and clojure.contrib stuff within it, so that the > other users don't have to worry about downloading clojure/contrib. > > Also, I would rather not unpack jar files from libraries that I used, > if possible. > > Clojure's compile function is tantalizing, but then everyone would > need to have the same versions of the libraries that I used, not just > clojure and contrib. This is one of the holes in the Clojure/Java infrastructure - things that should be simple aren't. So there isn't anything simpler than a project except the bare file manipulation commands. To use those commands, you need to compile all your clojure files to class files (via the clojure "compile" command), then use the jar command to create the "uberjar" (still a .jar) file that contains all the relevant .class files, and also the contents of the .jar files that your program depends on. Unlike most compiled languages, there isn't a "driver" program available that will take a list of files on the command line and compile them, then put the results together to what you want. Instead, you have to rely on project manipulation tools like ant, lein or maven to take a file describing the project and do all that for you. While I agree with you that things like lein are overkill for this kind of thing, they're still probably the simplest solution you're going to find. It's probably easier to figure out how to use lein to build your uberjar than to figure out how to get jar to create the same thing. Sadly, I don't see this situation changing. Java people seem to think this is normal, and suggest that "Clojure isn't the right language" (what they mean is that Java isn't the right environment) when it gets pointed out. So even if someone wrote a "jc" command that knew how to compile Java, Clojure, Scala, Groovy, JRuby, Jython, etc. and which jar files to add for each of them, I suspect it wouldn't get any mind share in those communities because there isn't a lot of interest in tools to make simple things simple. http://www.mired.org/consulting.html Independent Software developer/SCM consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- 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: Logos -> core.logic
This is quality work David, that I feel opens up Clojure to even more exciting domains. I'd love to get involved in helping your second goal. As ideas and projects come up, please advertise them on the list or email me directly. Paul On Apr 28, 8:59 am, David Nolen wrote: > Logos has been accepted into Clojure > contrib:https://github.com/clojure/core.logic. > > There's a considerable amount of work still to do but I'm excited to see how > the Clojure community might take advantage of a logic programming library. > Two things I'd like to see: > > 1) Make it faster (it's pretty darn fast, but I like faster) > 2) Use to write Clojure programs/extensions that would otherwise be > unnecessarily difficult to implement > > As far as 2, I'm currently brainstorming efficient predicate dispatch, but I > also think there are some opportunities to add an a la carte type system to > Clojure as well. > > Feel free to ask any questions- from what I can tell, logic/relational > programming is a paradigm that is not nearly as well known as functional > programming. I'll probably create a step-by-step tutorial soon to help out > on this front. > > For over-achievers who just want to dive in two texts make it quite clear > how this library works - The Reasoned Schemer > (http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10663) and > William Byrd's dissertation > (http://pqdtopen.proquest.com/#abstract?dispub=3380156) > > David -- 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: Logos -> core.logic
This is really exciting! Well done! Looking forward to playing around with this in its new home. Ambrose On Thu, Apr 28, 2011 at 11:59 PM, David Nolen wrote: > Logos has been accepted into Clojure contrib: > https://github.com/clojure/core.logic. > > There's a considerable amount of work still to do but I'm excited to see > how the Clojure community might take advantage of a logic programming > library. Two things I'd like to see: > > 1) Make it faster (it's pretty darn fast, but I like faster) > 2) Use to write Clojure programs/extensions that would otherwise be > unnecessarily difficult to implement > > As far as 2, I'm currently brainstorming efficient predicate dispatch, but > I also think there are some opportunities to add an a la carte type system > to Clojure as well. > > Feel free to ask any questions- from what I can tell, logic/relational > programming is a paradigm that is not nearly as well known as functional > programming. I'll probably create a step-by-step tutorial soon to help out > on this front. > > For over-achievers who just want to dive in two texts make it quite clear > how this library works - The Reasoned Schemer ( > http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10663) and > William Byrd's dissertation ( > http://pqdtopen.proquest.com/#abstract?dispub=3380156) > > David > > -- > 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: Serialising functions...
well spotted :-) I have ported it up to 1.3.0-alpha5 - alpha6 gave me some trouble that I haven't had time to sort out. [BTW - the following is from memory] You set the JVM's UID via a sys property. If this property is set it is incorporated into the names of new classes created in this JVM. The DynamicClassLoader maintains a map of classname : bytecode. I run a Jetty in this JVM which knows how to respond to URLClassLoader requests for class bytecode by looking them up in this map. I think I hacked DynamicClassLoader (which ?inherits? from URLClassLoader) so that you can optionally set a system property that is a URL from which it can request classes that it cannot find locally. So you do this on client JVMs Putting this all together, you can basically create types/fns on the-fly in a one JVM, serialise instances of these and send them to another JVM, then deserialise them (transparently pulling their class over from their parent JVM) and use them as if they had been created at compile rather than runtime. This plugs what I have found to be a bit of a hole in Clojure, namely dynamism is great, but I want to use it in a distributed app... The patches are not prodction ready, but I have been using them for some time with no problem. I'd be very happy to find other people with similar interest, improve the patches and see if we can persuade the powers that be to accept them or something providing similar fn-ality into e.g. Clojure-1.4 :-) If you need any help getting this stuff to work, just shout. Jules -- 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: Serialising functions...
BTW... Here is the code that runs Jetty : https://github.com/JulesGosnell/dada/blob/master/dada-core/src/main/clojure/org/dada/web.clj I have also found that I need to explicitly set up a DCL in my client : https://github.com/JulesGosnell/dada/blob/master/dada-swt/src/main/clojure/org/dada/swt/client.clj see the line : (.setContextClassLoader (Thread/currentThread) (clojure.lang.RT/makeClassLoader)) Thinking about it, the URL used to pull foreign classes should be on a per class/deserialisation basis (I'm pretty sure that you can do this) rather than a per-client-JVM basis. This would enable a proper p2p architecture where classes can be created in any node, rather than a client-server arch where only the central server is allowed to create them. I'll investigate. regards, Jules -- 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: Logos -> core.logic
Hallo David, Very cool that this is moving to contrib. I saw that you gave a presentation at NYC Clojure User Groupe. Was that tapped? If not I think it would be very cool if you could do a screencast with simular content. The videos of rich showing of clojure a reason why some of use are here (including me) and I think it would be great if we had something like this for your library (and logic programming spezially). Like you sad logic programming is not well known yet and its hard to tell people what it is spezially if your not an expert yourself. It would be great to just be able to send somebody a link of a video expmlaing a little bit about it (in clojure). Nick On Apr 28, 5:59 pm, David Nolen wrote: > Logos has been accepted into Clojure > contrib:https://github.com/clojure/core.logic. > > There's a considerable amount of work still to do but I'm excited to see how > the Clojure community might take advantage of a logic programming library. > Two things I'd like to see: > > 1) Make it faster (it's pretty darn fast, but I like faster) > 2) Use to write Clojure programs/extensions that would otherwise be > unnecessarily difficult to implement > > As far as 2, I'm currently brainstorming efficient predicate dispatch, but I > also think there are some opportunities to add an a la carte type system to > Clojure as well. > > Feel free to ask any questions- from what I can tell, logic/relational > programming is a paradigm that is not nearly as well known as functional > programming. I'll probably create a step-by-step tutorial soon to help out > on this front. > > For over-achievers who just want to dive in two texts make it quite clear > how this library works - The Reasoned Schemer > (http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10663) and > William Byrd's dissertation > (http://pqdtopen.proquest.com/#abstract?dispub=3380156) > > David -- 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: Logos -> core.logic
On Thu, Apr 28, 2011 at 3:05 PM, Nick Zbinden wrote: > Hallo David, > > Very cool that this is moving to contrib. > > I saw that you gave a presentation at NYC Clojure User Groupe. Was > that tapped? If not I think it would be very cool if you could do a > screencast with simular content. The videos of rich showing of clojure > a reason why some of use are here (including me) and I think it would > be great if we had something like this for your library (and logic > programming spezially). > Sadly it wasn't recorded, but it went over very well. > > Like you sad logic programming is not well known yet and its hard to > tell people what it is spezially if your not an expert yourself. It > would be great to just be able to send somebody a link of a video > expmlaing a little bit about it (in clojure). > > Nick Well I wouldn't consider myself an expert in any of these matters, but I'm interested in making the library more accessible so tutorials and screencasts are something I'm thinking about. David -- 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: dead simple compile to jar file
Before maven, I used the repl and jar. My root dir had src\myapp \*.clj, ... and "classes". 1-In directory classes: "jar xf path\to\clojure.jar", same for any other deps. 2-In root, "java -cp src;classes clojure.main"; -> "(compile 'myapp.main)" 3-Back to classes: "jar cfe myapp.jar myapp.main *.*" 4-To run: java -jar myapp.jar That's probably not dead simple but I could live with it 'til the time came to learn a build tool. On Apr 27, 10:45 am, cej38 wrote: > Hi, > I would like the simplest method to compile a few lines of clojure > code into a jar file that I can distribute to some fellow scientists > that don't know much (if anything) about java or clojure. Since I am > not creating a huge product that I will be updating often, maven and > Lenningen seem like overkill. The compiled jar file should contain > the relevant clojure and clojure.contrib stuff within it, so that the > other users don't have to worry about downloading clojure/contrib. > > Also, I would rather not unpack jar files from libraries that I used, > if possible. > > Clojure's compile function is tantalizing, but then everyone would > need to have the same versions of the libraries that I used, not just > clojure and contrib. > > Thanks. > > Chad -- 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: Who's using Clojure?
We've got a good start to the list going http://dev.clojure.org/display/community/Clojure+Success+Stories Any more we should get listed? -- 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: Serialising functions...
Thats some serious hacking. Definitely agree that distributed clojure would be awesome. Two points/questions: 1) Is this just a bug in DynamicClassLoader? Why doesn't it call super.defineClass instead of falling back on the URLClassLoader?: public Class defineClass(String name, byte[] bytes){ return defineClass(name, bytes, 0, bytes.length); } If it simply called super, then I believe I can pass in the right "bytecode preserving" class with the context class loader, thus avoiding modifications to the clojure source. 2) Do you know how to serialize an entire namespace? This largely avoids the issue of closures. Right now I'm serializing the classes, and serializing all the vars in the NS, and then containing them in some ad-hoc format on disk. Obviously this somehow can be done with a single class, but how the compiler does it is too hairy for me to understand. On Thu, Apr 28, 2011 at 9:28 AM, Jules wrote: > well spotted :-) > > I have ported it up to 1.3.0-alpha5 - alpha6 gave me some trouble that I > haven't had time to sort out. > > [BTW - the following is from memory] > > You set the JVM's UID via a sys property. > > If this property is set it is incorporated into the names of new classes > created in this JVM. > > The DynamicClassLoader maintains a map of classname : bytecode. > > I run a Jetty in this JVM which knows how to respond to URLClassLoader > requests for class bytecode by looking them up in this map. > > I think I hacked DynamicClassLoader (which ?inherits? from URLClassLoader) > so that you can optionally set a system property that is a URL from which it > can request classes that it cannot find locally. So you do this on client > JVMs > > Putting this all together, you can basically create types/fns on the-fly in > a one JVM, serialise instances of these and send them to another JVM, then > deserialise them (transparently pulling their class over from their parent > JVM) and use them as if they had been created at compile rather than > runtime. > > This plugs what I have found to be a bit of a hole in Clojure, namely > dynamism is great, but I want to use it in a distributed app... > > The patches are not prodction ready, but I have been using them for some > time with no problem. I'd be very happy to find other people with similar > interest, improve the patches and see if we can persuade the powers that be > to accept them or something providing similar fn-ality into e.g. Clojure-1.4 > :-) > > If you need any help getting this stuff to work, just shout. > > > Jules > > -- > 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: How to determine a function name at runtime
On Thu, Apr 28, 2011 at 6:36 AM, MohanR wrote: > There should be a way to print the currently executing function and > the calling function logging purposes ? > > I believe Java has StackTraceElement[] to do this. And therefore so does Clojure: user=> ((fn foo [] (map #(.getClassName %) (.getStackTrace (Throwable.) ("user$eval1738$foo__1739" "user$eval1738" "clojure.lang.Compiler" "clojure.lang.Compiler" "clojure.lang.Compiler" "clojure.core$eval" "user$eval1736" "clojure.lang.Compiler" "clojure.lang.Compiler" "clojure.core$eval" "clojure.main$repl$read_eval_print__5624" "clojure.main$repl$fn__5629" "clojure.main$repl" "clojure.lang.RestFn" "org.enclojure.repl.main$create_clojure_repl$repl_thread_fn__1247" "clojure.lang.AFn" "java.lang.Thread") You can get the "foo" out of the first element with enough regexp hackery I expect, but if handed a random function object it won't be as easy as if you are *inside* the function. If the function can be relied on to call one you pass it, then maybe you can: pass it a function that generates a traceback and stores it somewhere you can retrieve it, then look for a stack trace element below yourself. Even then it's tricky: (def st (atom nil)) (defn save-st [& _] (reset! st (map #(.getClassName %) (.getStackTrace (Throwable.) (defn get-mangled-name [f p-template] (apply f (map #(if (= % :here) save-st %) p-template)) (first (filter identity (map #(if (> (.indexOf %2 "get_mangled_name") -1) %1) @st (rest @st) (defn callifier [x f] (f x)) user=> (get-mangled-name callifier [3 :here]) "clojure.core$apply" Argh. user=> @st ("user$save_st" "clojure.lang.RestFn" "user$callifier" "clojure.lang.AFn" "clojure.lang.AFn" "clojure.core$apply" "user$get_mangled_name" ...) WTF? Seems a bit inefficient, but OK. (defn get-mangled-name [f p-template] (apply f (map #(if (= % :here) save-st %) p-template)) (first (filter identity (map #(if (> (.indexOf %2 "get_mangled_name") -1) %1) @st (drop 4 @st) user=> (get-mangled-name callifier [3 :here]) "user$callifier" Aha! user=> (get-mangled-name map [:here [1 2 3]]) "user$callifier" WTF??! user=> (reset! st ["foo" "bar" "baz" "quux" "get_mangled_name"]) ["foo" "bar" "baz" "quux" "get_mangled_name"] user=> (get-mangled-name map [:here [1 2 3]]) "foo" O-Damn: map is lazy, so save-st never gets called to overwrite the atom contents. OK, then: (defn get-mangled-name [f p-template] (let [x (apply f (map #(if (= % :here) save-st %) p-template))] (if (instance? clojure.lang.LazySeq x) (doall x))) (first (filter identity (map #(if (> (.indexOf %2 "get_mangled_name") -1) %1) @st (drop 4 @st) user=> (get-mangled-name map [:here [1 2 3]]) "clojure.lang.RT" AAA http://tinyurl.com/argggh> RRRGH! user=> @st ("user$save_st" "clojure.lang.RestFn" "clojure.core$map$fn__3695" "clojure.lang.LazySeq" "clojure.lang.LazySeq" "clojure.lang.RT" "clojure.core$seq" "clojure.core$dorun" "clojure.core$doall" "user$get_mangled_name" ...) (defn get-mangled-name [f p-template] (let [x (apply f (map #(if (= % :here) save-st %) p-template))] (if (instance? clojure.lang.LazySeq x) (doall x))) (let [a (fn [n] (first (filter identity (map #(if (> (.indexOf %2 "get_mangled_name") -1) %1) @st (drop n @st) y (a 4) n (if (= y "clojure.lang.RT") (a 7) y) ; mega hack! n (.substring n (inc (.indexOf n "$"))) i (.indexOf n "$")] (if (> i -1) (.substring n 0 (.indexOf n "$")) n))) user=> (get-mangled-name callifier [3 :here]) "callifier" user=> (get-mangled-name map [:here [1 2 3 4 5]]) "map" user=> (get-mangled-name filter [:here [1 2 3 4 5]]) "filter" It works! It w... user=> (get-mangled-name reduce [:here [1 2 3 4 5]]) "r" ...orks? user=> (get-mangled-name (fn foo [f z] (f z)) [:here [1 2 3 4 5]]) "eval2194" user=> (get-mangled-name #(+ %1 (%2 %1)) [3 :here]) # *sob* So, it won't work if it's not a HOF that calls one of its arguments. It won't work if the fn is not top-level. It won't work if the function throws up when it sees save-st's output, though wrapping a catch-all try around (let [x ...]) might fix that. And of course if the function has side effects God help you. I don't think this approach is very workable for getting the names of arbitrary functions -- only yourself and functions that have called you. Better to just use the metadata, which works on every function for which get-mangled-name works, and won't mangle - to _. -- 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
Re: Who's using Clojure?
This fractal video claims to have been made using Clojure: http://vimeo.com/22725635 I stumbled on it earlier today while bored and was quite surprised to see the word "Clojure" about halfway down the lengthy description text. I doubt it was very idiomatic Clojure. The described use, interpolating between video frames of some sort, would probably involve a loop/recur full of Java2D and ImageIO interop calls. Nor does it seem to be a large organization, but an individual hobbyist. Still, the more Clojure is in the public eye, the better. -- 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
Aw: Re: How to determine a function name at runtime
Hi, or just use the class name, which is what the stacktrace gives you anyway. user=> (class (fn [x] x)) user$eval1$fn__2 user=> (class (fn foo [x] x)) user$eval5$foo__6 user=> (defn bar [x] x) #'user/bar user=> (class bar) user$bar user=> (defn frob [f] (prn (class f))) #'user/frob user=> (frob (fn [x] x)) user$eval13$fn__14 nil user=> (frob (fn foo [x] x)) user$eval17$foo__18 nil user=> (frob bar) user$bar nil Sincerely Meikel -- 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: Re: How to determine a function name at runtime
On Fri, Apr 29, 2011 at 2:06 AM, Meikel Brandmeyer wrote: > Hi, > > or just use the class name, which is what the stacktrace gives you anyway. > > user=> (class (fn [x] x)) > user$eval1$fn__2 > user=> (class (fn foo [x] x)) > user$eval5$foo__6 > user=> (defn bar [x] x) > #'user/bar > user=> (class bar) > user$bar > user=> (defn frob [f] (prn (class f))) > #'user/frob > user=> (frob (fn [x] x)) > user$eval13$fn__14 > nil > user=> (frob (fn foo [x] x)) > user$eval17$foo__18 > nil > user=> (frob bar) > user$bar > nil Yeah, that works if you have the object in hand and it's not wrapped or anything. Of course it has the same problem: which component are you interested in? I guess in this case you might strip everything before the last $, and anything starting with __ at the end, to get a more meaningful name, though you'll sometimes get "fn" that way. It would definitely be nice if (fn foo [...] ...) put :name foo in the object's metadata. You could make your own version of fn that did this, e.g. (ns foo (refer-clojure :exclude (fn))) (defmacro fn [& args] (let [x (first args)] (if-not (symbol? x) `(clojure.core/fn ~@args) `(with-meta (clojure.core/fn ~@args) {:name '~x} but this wouldn't magically attach name metadata to fns generated elsewhere. -- 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