Re: Is it possible to implement break or return in Lisp?

2009-11-04 Thread Christopher Wilson

On Tue, Nov 3, 2009 at 10:58 PM, rob  wrote:
>
> I'm pretty sure there was an example of this using continuations in
> Dybvig's book on Scheme.  I just flipped through it and didn't readily
> find it, but I think that is where I saw it.

You can do something like this (PLT Scheme):

#lang scheme

(define (foo n)
  (define (foo-helper return)
(if (> n 0)
(return n)
(* -1 n)))
  (call/cc foo-helper))

(display (foo 10))

-- 
Chris Wilson 

--~--~-~--~~~---~--~~
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: ClojureQL confusion: getting a hold of the results

2009-08-11 Thread Christopher Wilson

It looks like (speaking without having looked at the ClojureQL source)
the results are being returned as a lazy sequence.  In the first case
the sequence isn't being realized but it is in the second.

On Tue, Aug 11, 2009 at 2:15 PM, Maximilian
Karasz wrote:
> Hi,
>
> i've been wanting to play with clojureql for a while and now it seems i'm
> pretty much stuck at the entry point...
>
> a simple example:
>
> ; set up includes, db connection info etc
> (require '[dk.bestinclass.clojureql :as cql])
> (cql/load-driver "com.mysql.jdbc.Driver")
> (def *connection* (cql/make-connection-info "mysql" "//path_to/db" "user"
> "password"))
>
>
> so far so good. let's assume i have a table baned people and want to fetch
> the first five entries:
>
> user=> (cql/run [*connection* result] (cql/query * people) (take 5 result))
> java.sql.SQLException: Operation not allowed after ResultSet closed
>
>
> this is kind of unexpected... interestingly, the following works just fine:
>
>
> (cql/run [*connection* result] (cql/query * people) (dosync (println (take 5
> result
>
> ... prints 5 people...
>
> The ResultSet always seems to be closed unless i print it right away... what
> am i doing wrong?
>
> cheers,
>
> -Max
>
> >
>



-- 
Chris Wilson 

--~--~-~--~~~---~--~~
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: Package manager proposal

2009-08-07 Thread Christopher Wilson

+1 on ".car" here too. Plus, I imagine the icon to be a 1950's-era
muscle car; a nod to Lisp's age.

On Fri, Aug 7, 2009 at 8:13 AM, Justin Johnson wrote:
>> car: "Clojure Archive"  (half-assed pun on Lisp's car, plus you can
>> imagine the icon!)
>
> +1
>
> >
>



-- 
Chris Wilson 

--~--~-~--~~~---~--~~
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: Ant build.xml snippet: compile

2009-07-22 Thread Christopher Wilson

Sorry if this is a bit OT, but has anyone created an ant or maven jar
task (maven: is 'goal' the correct term)? In the few jars that I've
created I've AOT compiled my .clj files and hand-created the jar file.
The way that I do this is compile to the default clojure "classes"
directory, I then pull the two sub directories (in my case usually a
'com/' and 'clojure/') out into the project root, leaving me with
something like this:

project/
  com/
  clojure/
  clojure.jar

In the manifest I then specify the Main-Class as 'com.sencjw.project'
and the Class-Path as just '.' (dot). I've been unable to do it any
other way. Do others have a better method? Thanks!

On Wed, Jul 22, 2009 at 6:04 AM, Laurent PETIT wrote:
>
>
> 2009/7/22 Michael Wood 
>>
>> 2009/7/22 Howard Lewis Ship :
>> >
>> > On Tue, Jul 21, 2009 at 3:17 PM, Laurent PETIT
>> > wrote:
>> >> Hi,
>> >>
>> >> so far my examples were more based on issues with namespaces separated
>> >> into
>> >> multiple pieces than on a namespace / script dichotomy.
>> >>
>> >> So while I understand the interest of separating source files to be
>> >> delivered to production from test files, I don't see how this would
>> >> solve
>> >> both problems I reported ? (unless in your source directory you stick
>> >> to the
>> >> one namespace / one file rule).
>> >
>> > Yes, I absolutely stick to that rule. Files are cheap, use lots!
>>
>> Yes, but Laurent is asking about using MORE files than there are
>> namespaces.  You're implying files are not quite as cheap as Laurent
>> thinks :)
>
> I agree with Michael, there's something I don't understand about your last
> answer.
>
>
> >
>



-- 
Chris Wilson 

--~--~-~--~~~---~--~~
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: jar handling

2009-06-21 Thread Christopher Wilson

In Java 6 you can do a wildcard for jar files in a directory:

java -cp /opt/jars/*:. clojure.main

this will find all the jar files in /opt/jars/ and put them on the classpath.

On Sun, Jun 21, 2009 at 9:10 PM, Wilson MacGyver wrote:
>
> Hi,
>
> Does clojure have any way to handle jar loading without having to
> specify it in command line?
>
> I'm looking for something like groovy, where if you place a jar file
> in ~/.groovy/lib. it's
> available to any groovy code.
>
> Thanks
>
> --
> Omnem crede diem tibi diluxisse supremum.
>
> >
>



-- 
Chris Wilson 

--~--~-~--~~~---~--~~
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: Weird Issue Reading Socket

2009-06-01 Thread Christopher Wilson

I don't know how relevant this is to what you're trying to do, but
I've recently written something that sounds like what you're doing. My
approach was to always send the size of the file (this involves
sending chunks of a file around) to the server before sending the
file. Since read() will block if there are no bytes to read, I wrap it
in a "dotimes":

(defn- transfer
 "Helper transfer routine."
 [#^InputStream from #^OutputStream to num-bytes]
 (let [arrsize 1024
       buff (make-array Byte/TYPE arrsize)
       loops (long (Math/ceil (/ num-bytes arrsize)))]
   (dotimes [i loops]
     (.read from buff)
     (.write to buff

I pre-calculate how many iterations of read/write I'll have to do up
front. This works for me.

On Mon, Jun 1, 2009 at 10:56 AM, tmountain  wrote:
>
> I'm not sure if that's related to the problem either, but it may very
> well improve performance. Thanks for the suggestion. I will try
> opening the streams ahead of time and see where that takes me.
>
> On Jun 1, 10:20 am, MikeM  wrote:
>> I don't know if this is part of the problem, but you appear to be
>> calling getInputStream repeatedly on the socket. I think more
>> typically the socket connnection is established, input and output
>> streams are obtained one time only, then the streams are used as
>> needed for the duration of the connection.
> >
>

--
Chris Wilson 

--~--~-~--~~~---~--~~
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 and VisualVM

2009-05-28 Thread Christopher Wilson

I found an interesting article on Hacker News:
http://news.ycombinator.com/item?id=631085 "The Best Kept Secret in
the JDK: VisualVM" and the article here:
http://java.dzone.com/articles/best-kept-secret-jdk-visualvm

I fired it up and in no time at all, was profiling some clojure code.
Definitely worth a look.

-- 
Chris Wilson 

--~--~-~--~~~---~--~~
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
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: compilation and classpath

2009-05-22 Thread Christopher Wilson

You probably need to set (and create!) the correct compilation
(output) directory. This defaults to a "classes" directory as a
subdirectory of your current working directory. So if you had:

test/main.clj

you'd need

classes/

also make sure that this directory is on your classpath. I think this
is what I needed to do to get everything working.

--
Chris

On Fri, May 22, 2009 at 10:34 AM, tsuraan  wrote:
>
> I'm having some trouble getting clojure to generate .class files.  I
> have a directory layout like this:
>
> test/
>    main.clj
>
> where main.clj is the same file as from
> http://clojure.org/compilation, but with the 'clojure.examples.hello
> replaced with 'test.main .  I've tried running clojure a few different
> ways:
>
> from the parent dir of the test dir, as java -cp
> ~/src/clojure/clojure.jar:`pwd`/ clojure.main
> from within the test dir, as java -cp ~/src/clojure/clojure.jar:`pwd`/..
>
> In both cases, I can successfully (use 'test.main) and call (-main
> "foo"), and it works, but when I try to call (compile 'test.main) I
> get java.io.IOException: No such file or directory (main.clj:1).  What
> do I need to do to get compilation to work?
>
> >
>



-- 
Chris Wilson 

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Speed up network transfers?

2009-05-15 Thread Christopher Wilson

Hi there,

I'm working on a project that involves transferring large files over
the network (100+MB) and wondering what would work better. I'm newer
to Java than I am to lisp, so I've just grabbed the most obvious
things from the API that I thought could possibly work:

(ns misc-ports
  (:import (java.io BufferedReader InputStreamReader BufferedOutputStream
PrintWriter FileInputStream BufferedOutputStream
FileOutputStream)
   (java.net Socket ServerSocket)))

(defn net-to-file
  "Listen on a port, when accepted dump data to named incoming file."
  [port filename]
  (with-open [sock (.accept (ServerSocket. port))
  ins (BufferedReader. (InputStreamReader. (.getInputStream sock)))
  outf (FileOutputStream. filename)]
(loop [c (.read ins)]
  (when-not (== -1 c)
(.write outf c)
(recur (.read ins))

(defn file-to-net
  "Take the name of a file and a waiting ip and port, send named file
  on socket."
  [filename ipaddr port]
  (with-open [sock (Socket. ipaddr port)
  outs (BufferedOutputStream. (.getOutputStream sock))
  ins (FileInputStream. filename)]
(loop [c (.read ins)]
  (when-not (== -1 c)
(.write outs c)
(recur (.read ins))

But it turns out that this is rather slow. What would be some methods
to speed this up?

Thanks!

--
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
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: Getting slime-edit-definition to work with Clojure

2009-04-29 Thread Christopher Wilson

Here's a .emacs snippet that works for me:

;; SLIME setup (clojure)
(add-to-list 'load-path "~/.emacs.d/slime/")  ; your SLIME directory
(add-to-list 'load-path "~/.emacs.d/") ; clojure-mode.el is here
(add-to-list 'load-path "~/.emacs.d/swank-clojure") ; swank-clojure directory
(setq swank-clojure-binary "~/bin/clojure") ; shell script that invokes clojure
(require 'clojure-mode)
(require 'swank-clojure-autoload)
(require 'slime)

(eval-after-load "slime"
  '(progn
 (add-to-list 'load-path "~/.emacs.d/slime/contrib")
 (slime-setup '(slime-fancy slime-banner))
 (setq slime-complete-symbol*-fancy t)
 (setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)))

You can of course remove the "slime-fancy" and the "slime-banner" if
you wish. I hope this helps

--Chris

On Tue, Apr 28, 2009 at 1:28 PM, Baishampayan Ghose
 wrote:
>
> Phil,
>
>> I suspect the problem might have to do with the fact that you're
>> configuring slime for both SBCL and Clojure. I know it's possible to
>> get this working, but it's a lot more complicated that way. I'd
>> suggest having one file for clojure slime config and one for sbcl, and
>> only load one of them per Emacs instance.
>>
>> I'm sure someone who's more familiar with SLIME and Common Lisp could
>> figure out a solution, but this seems like simplest solution.
>
> My eyes lit up for a second! I removed all SBCL support from SLIME and
> it still doesn't work :(
>
> Can you kindly share your working dotfiles and enlighten me?
>
> My current .emacs has this:
> ;;;
>
> (require 'slime)
> (slime-setup '(slime-fancy slime-banner slime-mdot-fu))
>
> (defvar slime-net-coding-system
>  (find-if 'slime-find-coding-system
>           '(utf-8-unix iso-latin-1-unix iso-8859-1-unix binary)))
>
> ;;; Clojure specific
> (defvar clj-root (concat (expand-file-name "~") "/clojure/"))
> (setq load-path (append
>                 (list (concat clj-root "clojure-mode")
>                       (concat clj-root "swank-clojure"))
>                 load-path))
>
> (setq swank-clojure-binary "clojure")
>
> (require 'swank-clojure-autoload)
>
> (add-to-list 'slime-lisp-implementations
>             '(clojure ("/home/ghoseb/bin/clojure") :init
> swank-clojure-init))
>
> (require 'clojure-mode)
> (eval-after-load 'clojure-mode '(clojure-slime-config))
>
> (autoload 'clojure-mode "clojure-mode" "A major mode for Clojure" t)
> (add-to-list 'auto-mode-alist '("\\.clj$" . clojure-mode))
>
> (defun lisp-enable-paredit-hook ()
>  (paredit-mode 1))
>
> (add-hook 'clojure-mode-hook 'lisp-enable-paredit-hook)
>
> (defun clj ()
>  "Starts Clojure in Slime"
>  (interactive)
>  (slime 'clojure))
> ;;;
>
> Regards,
> BG
>
> --
> Baishampayan Ghose 
> oCricket.com
>
> >
>

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---