Re: Getting slime-edit-definition to work with Clojure

2009-05-08 Thread Baishampayan Ghose

Stephen C. Gilardi wrote:

> I've simplified my .emacs file and clojure launch script to only what's
> required for my slime setup to work with swank-clojure. With this
> simplified setup, I confirmed that slime's repl works and that M-. after
> typing (+ brings me to the definition of + in clojure.core.
> 
> The way I use slime/swank is to handle all Classpath issues myself in my
> "swank-clojure-binary" launch script. I've found that setup to break
> only very rarely with slime/swank/clojure updates. Other strategies may
> perform equally well or better, but I haven't tried them.
> 
> In the setup below, "/sq/ext" is a directory where I keep third party
> source controlled package. I'm running all from the HEAD of their Source
> Control repository. I did a fresh update just now.
> 
> Are you able to duplicate this setup to try?

Many thanks for taking out some time to help me. I have good news, and
bad news.

Bad news first.

I duplicated your setup and even then it didn't work.

And that made me suspect my ~/.emacs file itself. It's working for you
and it's working for Phil (and everybody else), but not me. There must
be something wrong with my config.

The Good news.

I started with a bare .emacs file and it worked! Then I analysed each
and every line of my 5 year old .emacs and finally zeroed in to one line.

(add-to-list 'auto-coding-alist '("." . utf-8))

Yes. That line screwed up everything for me. I removed it and everything
is working fine now.

Now I need to find out why that line was causing the problem.

Thanks a lot Stephen & Phil. You guys (as well as the Clojure community)
made my day.

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



Re: Getting slime-edit-definition to work with Clojure

2009-05-08 Thread Asbjørn Bjørnstad



On Apr 30, 1:47 am, Phil Hagelberg  wrote:

> > (setq swank-clojure-binary "clojure")
>
> > (add-to-list 'slime-lisp-implementations
> >              '(clojure ("/home/ghoseb/bin/clojure") :init
> > swank-clojure-init))
>
> It looks like you're using a wrapper script rather than letting
> swank-clojure construct a "java" command-line invocation. I'm not sure
> why you're doing this; working with the defaults might fix it.

Just speaking for myself, I do this to set up a classpath that
includes all the third-party jars I've downloaded and use in
my projects. I did this long time ago and haven't looked at it
since (Too busy at work.) What's the "proper" way of doing
this in a slime setup where swank-clojure sets up the classpath?

--
  -asbjxrn
--~--~-~--~~~---~--~~
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-05-08 Thread Baishampayan Ghose

Asbjørn Bjørnstad wrote:

> Just speaking for myself, I do this to set up a classpath that
> includes all the third-party jars I've downloaded and use in
> my projects. I did this long time ago and haven't looked at it
> since (Too busy at work.) What's the "proper" way of doing
> this in a slime setup where swank-clojure sets up the classpath?

You can append you classpath to swank-clojure-extra-classpaths after
clojure-slime-config has been called.

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



Re: Getting slime-edit-definition to work with Clojure

2009-05-08 Thread Asbjørn Bjørnstad


On May 8, 6:49 pm, Baishampayan Ghose  wrote:
> Asbjørn Bjørnstad wrote:
> > Just speaking for myself, I do this to set up a classpath that
> > includes all the third-party jars I've downloaded and use in
> > my projects. I did this long time ago and haven't looked at it
> > since (Too busy at work.) What's the "proper" way of doing
> > this in a slime setup where swank-clojure sets up the classpath?
>
> You can append you classpath to swank-clojure-extra-classpaths after
> clojure-slime-config has been called.

Right, the huge superfluous classpath for any small project has
been nagging me a bit, so I ended up gutting the slime-project
function from here:

 http://github.com/dysinger/clojure-pom/tree/master

Basically I have a directory per project, and a jars directory
in that directory containing (symlinks to) external jars the
project depends on.

(defun slime-project (path)
  "Setup classpaths for a clojure project & refresh slime"
  (interactive "GPath: ")
  (when (get-buffer "*inferior-lisp*")
(kill-buffer "*inferior-lisp*"))
  (setq swank-clojure-binary nil
swank-clojure-extra-classpaths
(cons (first swank-clojure-extra-classpaths)
  (mapcar (lambda (d) (expand-file-name d path))
 (directory-files (expand-file-name "jars/"
path) t ".jar$")))
  (save-window-excursion
(slime)))

--
 -asbjxrn
--~--~-~--~~~---~--~~
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: Clojure Community Geography (The Clojure Map)

2009-05-08 Thread Victor Rodriguez

On Thu, May 7, 2009 at 6:22 PM, Stephen C. Gilardi  wrote:
...
> If you'd like to add your marker to the list:
>
>        - open the URL
>        - sign in to Google
>        - at the upper right of the pane on the left that lists all
>          the names, click "edit"
>        - on the map, at the upper left, click the blue marker icon
>        - place the marker and edit the info
>        - save

Shouldn't people leave their email address?  Otherwise how can you get
in contact with local hackers?

Cheers,

Victor Rodriguez.

> Thanks, Graham!
>
> --Steve
>
>

--~--~-~--~~~---~--~~
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: Can "for" be enhanced to not have to take a binding?

2009-05-08 Thread Daniel Lyons


On May 7, 2009, at 4:15 PM, Jarkko Oranen wrote:
> Also, how is a lazy sequence of mouse events supposed to work? does it
> block? What happens when there is no mouse event? does the sequence
> just end? What if you happen to take the last event, and then the
> sequence ends, after which another event comes in? for wouldn't know
> what to do in the general case.


I think a facility like this is part of the underpinning of functional  
reactive programming (FRP), which is an active research area in  
designing interactive systems such as GUIs functionally rather than  
object orientedly (if that's a word).

Consider a trivial demo where you want to continuously update the  
mouse's coordinates in a text box on a window. You could just map a  
function which updates that text box across the potentially infinite  
list of mouse events. Yes, it would block until the next event came  
in, but the UI is in a consistent state while the mouse isn't moving.  
One has to assume that sequences of events are potentially infinite.

Haskell is pretty good at the infinite list part, but it's pretty bad  
at the side-effect part and timing part. I tried pretty hard to read  
Conal Eliot's paper "Simply Efficient FRP" 
 but I never got far enough in Haskell to actually understand what  
it's saying. It looks like something hard to do in Haskell.

It's also been done in Scheme, specifically the FrTime "language" in  
DrScheme. There's a paper about it here: 
 which I haven't even tried to read.

There's also an interesting Javascript implementation called Flapjax,  
which was pretty under-documented when I heard about it, but makes it  
a little easier to get the gist of the idea: 

 From what little I have gathered about the concept, Clojure ought to  
be in a unique position to leverage it, since Clojure has ready access  
to both GUI frameworks and lazy sequences from within an easy-to- 
reason-about strict language. Much of the work in Haskell FRP must be  
to cope with state and time, whereas in other languages it must be to  
introduce the right kinds of laziness and parallelism. Clojure has a  
good mixture of these ingredients already.

There could be extremely novel ways of approaching well-known problems  
hiding within Clojure right now.

—
Daniel Lyons
http://www.storytotell.org -- Tell 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
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
-~--~~~~--~~--~--~---



AIML pattern matcher design

2009-05-08 Thread dhs827

I'm stealing knowledge left and right (just ask me :-) to design me an
AIML pattern matcher. I've compiled a draft list of objects and
behaviors, which I would like to see reviewed for plausibility:

startup
- opens configuration file (e.g. startup.xml)
- passes configuration file to bot-loader object
bot-loader
- loads general input substitutions (spelling, person)
- loads sentence splitters (.;!?)
- looks for enabled bot, takes first one it finds
- reads bot-id; uses it as key (for saving/loading variables and
chatlogs)
- loads bot properties (global constants, e.g. name)
- passes control to aiml-loader object
aiml-loader
- loads list of AIML files to load, and for each file
- opens file
- reads AIML categories (XML) one by one as they appear in the 
file
- parses and stores the content of the match path 
(e.g."BOTID *
INPUTPATTERN * CONTEXT1 * CONTEXT2 *")
- when it reaches the end of the category - the 
template, or leaf
of this branch of the tree
- calls a method to store the elements of the 
match path, together
with the template, in the
pattern-matcher-tree

; First thing to learn is XML parsing with Clojure.

; Though it is probably the easiest thing to do, it is not necessary
for the templates to be stored along with the paths in the tree. They
might as well be left on disc or in a database.

; A function like parser/scan must advance the parse to the next part
of the document (element - element content - processing
instruction...) and tokenize it. I can then use case/switch/if (must
look at what Clojure offers) to make decisions/set variables/call
methods.

; The whole path, with all components, gets created at load time. The
loader combines all elements of the path (e.g. INPUTPATTERN * CONTEXT1
* CONTEXT2 *) into one string, seperating the components using special
context-id strings (e.g. , , )

; The idea of the AIML graphmaster is: take this string, seperate it
into words, then store these words as nodes in a tree.

; A variation of this idea: instead of keying the nodes by their
values, key them first by context, then by value.

; Now that the bot is up and running, the user types something into
the input box and hits Enter. The

pre-processor
- protects sentences
- blocks common attack vectors, e.g. code injection, flooding
- eliminates common spelling mistakes
- for each loaded substitution
- finds and replaces it in the input string
- alternatively, uses a tree to search for them
- removes redundant whitespace
- splits input into sentences (everything that follows is for each
sentence)
pattern-matcher
- combines INPUTPATTERN * CONTEXT1 * CONTEXT2 * into one string
- tokenizes the "path to be matched" into the individual words
(nodes)
- traverses the tree from the root; first
- tries matching underscore (_)wildcards
- matching of wildcards is recursive
- match one word of the current path component
- try remainder against child node
- if the whole remaining input matches
- and if the last node is a leaf
- return the template
- else try 2 words, then 3
- if all words in the string are used up and 
the current node is a
leaf
- return the template
- else stop matching underscores, and
- tries matching exact words in alphabetical order
- if there is a childnode that equals to the input 
word, recurse a
level deeper
- if at the next level there is a leaf, return 
the template
- else
- tries matching the star (*) wildcard
- when a complete path was matched, creates a
match-object
- holds information about the match
- the input (sentence)
- the template
- the strings matched to the wildcards

This first project should end there, with the template just returning
the values in the match-object. From there, the non-AIML aspects - the
new stuff - of the concept would be foregrounded.

Does this make sense to the casual observer?

Which known Clojure libraries should I be learning first?

Other comments, tips, disses?

Dirk
--~--~-~--~~~---~--~~
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+uns

Re: AIML pattern matcher design

2009-05-08 Thread Luke VanderHart

> ; First thing to learn is XML parsing with Clojure.

This is basically done. Use the xml library in core if you just need
to load XML into a map data structure. Use the zip library if you need
to navigate it. Use the xml library in contrib if you need to do xpath-
style navigation.

For the rest of it... it looks very well thought out. I'm not familiar
enough with the problem domain to comment specifically, but obviously
you're putting a lot of thought into it, so I'm pretty sure you won't
have any problems.

-Luke

On May 8, 12:50 pm, dhs827  wrote:
> I'm stealing knowledge left and right (just ask me :-) to design me an
> AIML pattern matcher. I've compiled a draft list of objects and
> behaviors, which I would like to see reviewed for plausibility:
>
> startup
>         - opens configuration file (e.g. startup.xml)
>         - passes configuration file to bot-loader object
> bot-loader
>         - loads general input substitutions (spelling, person)
>         - loads sentence splitters (.;!?)
>         - looks for enabled bot, takes first one it finds
>         - reads bot-id; uses it as key (for saving/loading variables and
> chatlogs)
>         - loads bot properties (global constants, e.g. name)
>         - passes control to aiml-loader object
> aiml-loader
>         - loads list of AIML files to load, and for each file
>                 - opens file
>                 - reads AIML categories (XML) one by one as they appear in 
> the file
>                         - parses and stores the content of the match path 
> (e.g."BOTID *
> INPUTPATTERN * CONTEXT1 * CONTEXT2 *")
>                         - when it reaches the end of the category - the 
> template, or leaf
> of this branch of the tree
>                                 - calls a method to store the elements of the 
> match path, together
> with the template, in the
> pattern-matcher-tree
>
> ; First thing to learn is XML parsing with Clojure.
>
> ; Though it is probably the easiest thing to do, it is not necessary
> for the templates to be stored along with the paths in the tree. They
> might as well be left on disc or in a database.
>
> ; A function like parser/scan must advance the parse to the next part
> of the document (element - element content - processing
> instruction...) and tokenize it. I can then use case/switch/if (must
> look at what Clojure offers) to make decisions/set variables/call
> methods.
>
> ; The whole path, with all components, gets created at load time. The
> loader combines all elements of the path (e.g. INPUTPATTERN * CONTEXT1
> * CONTEXT2 *) into one string, seperating the components using special
> context-id strings (e.g. , , )
>
> ; The idea of the AIML graphmaster is: take this string, seperate it
> into words, then store these words as nodes in a tree.
>
> ; A variation of this idea: instead of keying the nodes by their
> values, key them first by context, then by value.
>
> ; Now that the bot is up and running, the user types something into
> the input box and hits Enter. The
>
> pre-processor
>         - protects sentences
>         - blocks common attack vectors, e.g. code injection, flooding
>         - eliminates common spelling mistakes
>                 - for each loaded substitution
>                         - finds and replaces it in the input string
>                 - alternatively, uses a tree to search for them
>         - removes redundant whitespace
>         - splits input into sentences (everything that follows is for each
> sentence)
> pattern-matcher
>         - combines INPUTPATTERN * CONTEXT1 * CONTEXT2 * into one string
>         - tokenizes the "path to be matched" into the individual words
> (nodes)
>         - traverses the tree from the root; first
>                 - tries matching underscore (_)wildcards
>                         - matching of wildcards is recursive
>                                 - match one word of the current path component
>                                 - try remainder against child node
>                                 - if the whole remaining input matches
>                                 - and if the last node is a leaf
>                                         - return the template
>                                 - else try 2 words, then 3
>                                 - if all words in the string are used up and 
> the current node is a
> leaf
>                                         - return the template
>                                 - else stop matching underscores, and
>                 - tries matching exact words in alphabetical order
>                         - if there is a childnode that equals to the input 
> word, recurse a
> level deeper
>                                 - if at the next level there is a leaf, 
> return the template
>                                 - else
>                 - tries matching the star (*) wildcard
>         - when a complete path was matched, creates a
> match-object
>         - holds information

Re: Using Map

2009-05-08 Thread Luke VanderHart

Do you mean map the function or map the data structure?

If the most natural form of your data is truly "rows", you're probably
best off using a vector data structure. As for which function you use,
that depends whether you're doing something to every element or only
to specific elements, and if you know which position those elements
are in or if you have to search for them, etc.

On May 4, 11:01 am, Emeka  wrote:
> Hello All,
> I want to arrange objects in rows and also being able to manipulate them. By
> manipulation I meant, I could move one object from one row and use it to
> replace another object in another. Should I use Map or something else? I
> need your opinions here
>
> Regards,
> Emeka
--~--~-~--~~~---~--~~
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: Problems with Kevin O'Neills Clojure GitHub Mirror

2009-05-08 Thread Phil Hagelberg

"Kevin O'Neill"  writes:

> Branches and tags are now being mirrored.

Looks like the release_1.0 tag is getting pushed to every hour.

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



CL libraries - Newbie question

2009-05-08 Thread melipone

Hiya,

I understand that you can use Java libraries with Clojure but can you
use Common Lisp libraries for example CXML?

--~--~-~--~~~---~--~~
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: CL libraries - Newbie question

2009-05-08 Thread David Nolen
Not unless you port it ;)
Between what's in clojure-contrib and the fact that you have full access to
Java XML processing libraries you shouldn't have a problem with dealing with
XML.

Depending on your needs you should also give Enlive a spin. It's like
XPath+XSLT but it doesn't suck.

On Fri, May 8, 2009 at 2:00 PM, melipone  wrote:

>
> Hiya,
>
> I understand that you can use Java libraries with Clojure but can you
> use Common Lisp libraries for example CXML?
>
> >
>

--~--~-~--~~~---~--~~
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: Using Map

2009-05-08 Thread Emeka
Luke
I was referring to map the data structure. I later decided to use struct
which is a map. I intend to manipulate elements of each row.

Emeka

On Fri, May 8, 2009 at 6:17 PM, Luke VanderHart
wrote:

>
> Do you mean map the function or map the data structure?
>
> If the most natural form of your data is truly "rows", you're probably
> best off using a vector data structure. As for which function you use,
> that depends whether you're doing something to every element or only
> to specific elements, and if you know which position those elements
> are in or if you have to search for them, etc.
>
> On May 4, 11:01 am, Emeka  wrote:
> > Hello All,
> > I want to arrange objects in rows and also being able to manipulate them.
> By
> > manipulation I meant, I could move one object from one row and use it to
> > replace another object in another. Should I use Map or something else? I
> > need your opinions here
> >
> > Regards,
> > Emeka
> >
>

--~--~-~--~~~---~--~~
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: Question about modifying sexps via macros

2009-05-08 Thread ianp

Hi Christophe,

> hth

Yeah, thanks! I'm not sure what I was thinking when I wrote out
`~sbody in the above code, thanks for pointing that out. I've got that
bit of what I'm trying to do working now, I ended up with code that
looks like this:

(defmacro sequential [layout & cs]
  (let [g (gensym "sequential_group__")]
   `(let [~g (. ~layout createSequentialGroup)]
 ~@(map #(list (first %) layout g (flatten (rest %))) cs)
 ~g)))

where flatten is a fn that flattens a nested structure. So I'm making
progress! I'll write up something a little longer and post about it
over the weekend, in case anybody else is interested.

Cheers,
Ian.


--~--~-~--~~~---~--~~
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: Question about modifying sexps via macros

2009-05-08 Thread ianp

Hi Meikel,

> Please note, that these annotations are wrong. Since
> create-form is a macro, container and components refer
> to Symbols or some other Clojure structure (depending
> on how you pass the later container and map).

Thanks for pointing that out, I didn't realise that. Although, now
that you've mentioned it it does make sense.

In any case, I've taken the approach of stripping out all of the type
annotations for the time being, I'm going to get the code into a state
that I'm happy with and then turn on reflection warnings to identify
where they could be useful.

Cheers,
Ian.
--~--~-~--~~~---~--~~
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: Problems with Kevin O'Neills Clojure GitHub Mirror

2009-05-08 Thread Kevin O'Neill

yeah  ... tags a a bit of a pain as the tags revision can move
underneath me. i took the conservative (and lazy) approach and update
them during the refresh cycle. i might look into improving this a
little over the weekend.

-k.

On Sat, May 9, 2009 at 4:28 AM, Phil Hagelberg  wrote:
>
> "Kevin O'Neill"  writes:
>
>> Branches and tags are now being mirrored.
>
> Looks like the release_1.0 tag is getting pushed to every hour.
>
> -Phil
>
> >
>



-- 
email: ke...@oneill.id.au
web: http://kevin.oneill.id.au/

If you don't test then your code is only a collection of bugs which
apparently behave like a working program.

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



partition improvement

2009-05-08 Thread DiG

Hi all,

Quite often one need to get the last part of partition which is
smaller than the requested partition size. This change also support
another common case where one would like to pad the partition.

Since it is such a small change I am pasting the whole function,
instead of patch, but of cause can produce a patch against core. The
tests are included too.

http://gist.github.com/109002

Regards,
Dimitry Gashinsky (digash)

--~--~-~--~~~---~--~~
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: partition improvement

2009-05-08 Thread Stephen C. Gilardi


On May 8, 2009, at 5:02 PM, DiG wrote:


Quite often one need to get the last part of partition which is
smaller than the requested partition size. This change also support
another common case where one would like to pad the partition.


I like this a lot.

One suggestion:

Keep "coll" as the last argument in all the argument lists

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Launching apps

2009-05-08 Thread Chris Dean


How do folks launch their apps?

For building (and maybe deploying) it seems that most people use the
Java tools (ant, maven, ivy) or have a 10 line shell script.  For pure
Clojure code you don't even necessarily have to have a build step.

But how do you launch your code in a production style setting?

Historically, when using Common Lisp we would write a custom launch
script for each app that started the app and ran a repl.  We would run
that whole thing inside screen or detachtty.  We always deploy on Linux
and we always have screen available.

For some apps we also used to start them and use swank to get a repl,
but we eventually stopped doing that in favor of the above solution.

Cheers,
Chris Dean

--~--~-~--~~~---~--~~
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: Using Map

2009-05-08 Thread James Reeves

On May 8, 8:40 pm, Emeka  wrote:
> Luke
> I was referring to map the data structure. I later decided to use struct
> which is a map. I intend to manipulate elements of each row.
>
> Emeka

Perhaps you could explain in more detail what you intend to do and
why? As Luke says, a "row" suggests a vector, rather than a map, but
it's difficult to say for sure without knowing what you are trying to
achieve.

- James
--~--~-~--~~~---~--~~
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: Using Map

2009-05-08 Thread Stephen C. Gilardi


On May 8, 2009, at 6:40 PM, James Reeves wrote:


Perhaps you could explain in more detail what you intend to do and
why? As Luke says, a "row" suggests a vector, rather than a map, but
it's difficult to say for sure without knowing what you are trying to
achieve.


I'm interested in Emeka's answer to your question as well, but it  
occurs to me that if one is thinking in a database context, column  
names can be keys and rows can be maps or struct-maps mapping those  
keys to a group of values.


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Using Map

2009-05-08 Thread André Thieme

On 4 Mai, 17:01, Emeka  wrote:
> Hello All,
> I want to arrange objects in rows and also being able to manipulate them. By
> manipulation I meant, I could move one object from one row and use it to
> replace another object in another. Should I use Map or something else? I
> need your opinions here

>From what you say I imagine you have something like a matrix
or table, something with rows and columns that form cells.
And you want to be able to grab the contents of one cell and move
it around to another cell.
I don't know how much that fits your plan. But if it is similar
then one idea could be to have your objects being keys of a hashmap
and let the values be vectors of two numbers: for the row and column.
If you want to change the position of an object then you should dissoc
it from its current [r c] (the key) and assoc it to its new [r c] key.
--~--~-~--~~~---~--~~
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: Launching apps

2009-05-08 Thread André Thieme

On 9 Mai, 00:30, Chris Dean  wrote:
> How do folks launch their apps?
>
> For building (and maybe deploying) it seems that most people use the
> Java tools (ant, maven, ivy) or have a 10 line shell script.  For pure
> Clojure code you don't even necessarily have to have a build step.
>
> But how do you launch your code in a production style setting?

Depending on what kind of app it is. If it is a desktop application
then a .jar file that can be doubleclicked to run sounds like the
right thing. An alternative would be applets or Webstart.

For server apps it could be a launch script.
The launch script could be run in a screen.
--~--~-~--~~~---~--~~
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: CL libraries - Newbie question

2009-05-08 Thread André Thieme

On 8 Mai, 20:00, melipone  wrote:
> Hiya,
>
> I understand that you can use Java libraries with Clojure but can you
> use Common Lisp libraries for example CXML?

In principle you could run Clojure and ABCL inside the same VM.
http://common-lisp.net/project/armedbear/

That should allow you to use at least some CL libs.
--~--~-~--~~~---~--~~
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: HTTP clients in clojure

2009-05-08 Thread André Thieme

On 7 Mai, 02:34, Eric Tschetter  wrote:
> Last I checked the various clojure libraries, it seemed like noone has
> publicized a set of wrappers/clojure-native implementation of an http
> client.  I'm wonder if such a thing exists, or has everyone basically
> just rolled their own wrapper on top of their favorite Java HTTP
> client library?

Depending on what you want to do htmlunit may be interesting:
http://htmlunit.sourceforge.net/
It can do a whole lot more than just doing http requests.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Help w/ monadic parser

2009-05-08 Thread Howard Lewis Ship

I've been struggling to create a monadic parser.  I'm parsing XML
documents into a DOM tree.  Step one is to use a SAX parser to create
a stream of XML tokens; each a struct map.  The token types are
:start-element, :attribute, :text and :end-element.

Next I'm feeding this list of tokens into a monadic parser I've
created following
http://intensivesystems.net/tutorials/monads_101.html. The output
should be a DOM tree structure; element nodes will contain an
:attributes key (containing attribute tokens) and a :body key
containing child text and elements nodes.

I've had to make some minor changes to the tutorial's parser-m monad,
to allow for the fact that I'm parsing tokens, not character strings.

As I parse :attribute elements, I take the original element node and
add the attribute token to the :attributes list inside the element
node struct, creating the vector as necessary.

I have this working for the simple case, where I only allow for
at-most one attribute token.

(defmonad parser-m
  [m-result (fn [x]
(fn [tokens]
(list x tokens)))

   m-bind (fn [parser action]
  (fn [tokens]
  (let [result (parser tokens)]
   (when-not (nil? result)
 ((action (first result))
(second result))

   m-zero (fn [tokens]
  nil)

   m-plus (fn [& parsers]
  (fn [tokens]
  (first
(drop-while nil?
(map #(% tokens) parsers)])

; And some actions and parser generators

(defn any-token
  "Fundamental parser action: returns [first, rest] if tokens is not
empty, nil otherwise."
  [tokens]
  (if (empty? tokens)
  nil
  ; This is what actually "consumes" the tokens seq
  (list (first tokens) (rest tokens

; Utilities that will likely move elsewhere

(defn add-to-key-list
  "Updates the map adding the value to the list stored in the indicated key."
  [map key value]
  (update-in map [key] #(conj (or % []) value)))

(with-monad
  parser-m

  (defn token-test
"Parser factory using a predicate. When a token matches the
predicate, it becomes
  the new result."
[pred]
(domonad
  [t any-token :when (pred t)]
  ; return the matched token
  t))

  (defn match-type
"Parser factory that matches a particular token type (making the matched
token the result), or returns nil."
[type]
(token-test #(= (% :type) type)))

  (defn optional [parser]
(m-plus parser (m-result nil)))

  (declare element one-or-more)

  (defn none-or-more [parser]
(optional (one-or-more parser)))

  (defn one-or-more [parser]
(domonad [a parser
  as (none-or-more parser)]
 (cons a as)))

  (defn attribute
"Parser generator that matches attribute tokens, adding them to
:attributes key of the element-node, and returning the new
element-node."
[element-node]
(domonad [attribute-token (match-type :attribute)]
 (add-to-key-list element-node :attributes attribute-token)))

  (defn text
"Parser generator that matches text tokens, adding them to the :body
key of the element-node, and returning the new element-node."
[element-node]
(domonad [text-token (match-type :text)]
 (add-to-key-list element-node :body text-token)))

  (def match-first m-plus)

  (defn body-token
[element-node]
  (match-first
(attribute element-node)
(text element-node)
(element element-node)))

  (defn process-body
[element-node]
(domonad [modified-element (optional (body-token element-node))]
 (or modified-element element-node)))

  (defn element
"Parses an element token into an element-node, and then adds the
fully constructed element-node to the
:body of the containing element node."
[container-element-node]
(domonad [token (match-type :start-element)
  element-node (m-result (struct element-node :element token))
  assembled-node (process-body element-node)
  _ (match-type :end-element)]
 (add-to-key-list container-element-node :body assembled-node)))


  (def template
; Creates a psuedo-element (an empty map) and parses the root
element into it, then extracts the root element.
; Will eventually have to expand to support text and comments,
etc., around the root element."
(domonad [root (element {})]
 (first (root :body
  )


Here's the problem: I need to be able to handle multiple attribute
tokens, as well as :text and sub-elements. To me, that means that
process-body should be recursive, but we need to pass each
modification of the element on each iteration (to accumlate additions
to the :attributes and :body keys).

However, when I do the following:

  (defn process-body
[element-no

Re: Problems with Kevin O'Neills Clojure GitHub Mirror

2009-05-08 Thread Kevin O'Neill

Tags should now be stable and generate new revisions only when/if the
subversion revision changes.

-k.

On Sat, May 9, 2009 at 6:44 AM, Kevin O'Neill  wrote:
> yeah  ... tags a a bit of a pain as the tags revision can move
> underneath me. i took the conservative (and lazy) approach and update
> them during the refresh cycle. i might look into improving this a
> little over the weekend.
>
> -k.
>
> On Sat, May 9, 2009 at 4:28 AM, Phil Hagelberg  wrote:
>>
>> "Kevin O'Neill"  writes:
>>
>>> Branches and tags are now being mirrored.
>>
>> Looks like the release_1.0 tag is getting pushed to every hour.
>>
>> -Phil
>>
>> >>
>>
>
>
>
> --
> email: ke...@oneill.id.au
> web: http://kevin.oneill.id.au/
>
> If you don't test then your code is only a collection of bugs which
> apparently behave like a working program.
>



-- 
email: ke...@oneill.id.au
web: http://kevin.oneill.id.au/

If you don't test then your code is only a collection of bugs which
apparently behave like a working program.

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



Using a monad's m-plus function inside a macro

2009-05-08 Thread samppi

I'm trying to use m-plus inside a macro like this:

  (defmacro alt
[& subrules]
(with-monad parser-m
  `(fn [state#]
 ((m-plus ~...@subrules) state#

Unfortunately, I get the error:
  No such var: my-namespace.fnparse/m-plus

I've been trying various ways, and I think that replacing m-plus with
(:m-plus parser-m) makes it work, but it's ugly and takes advantage of
a library's internals. How can I use m-plus without resorting to the
hackneyed solution?


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



Byte Overflow

2009-05-08 Thread tmountain

I'm working on a project that makes use of a lot of byte arrays, and
I'm having an issue with certain bytes overflowing to negative values.
I know they're being stored properly because I'm also generating hex
dumps from time to time which indicate the real value is there. Can
someone tell me how to go about making comparisons with the actual
values?

user=> (byte 254)
-2

(def my-byte (make-array (Byte/TYPE) 1))
(aset my-byte 0 (byte 254))
(println (format-hex-string (HexByte/byteArrayToHexString my-byte)))
... returns "0xFE" ...

user=> (= (byte 254) 0xFE)
false

Thanks,
Travis
--~--~-~--~~~---~--~~
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: Help w/ monadic parser

2009-05-08 Thread jim

I'm trying to pack to leave town for a week. I'll try to post
something, but Sunday will be the earliest since I'll be spending most
of tomorrow in a small metal tube at 20,000 feet in the air.

Jim

Howard Lewis Ship wrote:
> I've been struggling to create a monadic parser.  I'm parsing XML
> documents into a DOM tree.  Step one is to use a SAX parser to create
> a stream of XML tokens; each a struct map.  The token types are
> :start-element, :attribute, :text and :end-element.
>
> Next I'm feeding this list of tokens into a monadic parser I've
> created following
> http://intensivesystems.net/tutorials/monads_101.html. The output
> should be a DOM tree structure; element nodes will contain an
> :attributes key (containing attribute tokens) and a :body key
> containing child text and elements nodes.
>
> I've had to make some minor changes to the tutorial's parser-m monad,
> to allow for the fact that I'm parsing tokens, not character strings.
>
> As I parse :attribute elements, I take the original element node and
> add the attribute token to the :attributes list inside the element
> node struct, creating the vector as necessary.
>
> I have this working for the simple case, where I only allow for
> at-most one attribute token.
>
> (defmonad parser-m
>   [m-result (fn [x]
> (fn [tokens]
> (list x tokens)))
>
>m-bind (fn [parser action]
>   (fn [tokens]
>   (let [result (parser tokens)]
>(when-not (nil? result)
>  ((action (first result))
> (second result))
>
>m-zero (fn [tokens]
>   nil)
>
>m-plus (fn [& parsers]
>   (fn [tokens]
>   (first
> (drop-while nil?
> (map #(% tokens) parsers)])
>
> ; And some actions and parser generators
>
> (defn any-token
>   "Fundamental parser action: returns [first, rest] if tokens is not
> empty, nil otherwise."
>   [tokens]
>   (if (empty? tokens)
>   nil
>   ; This is what actually "consumes" the tokens seq
>   (list (first tokens) (rest tokens
>
> ; Utilities that will likely move elsewhere
>
> (defn add-to-key-list
>   "Updates the map adding the value to the list stored in the indicated key."
>   [map key value]
>   (update-in map [key] #(conj (or % []) value)))
>
> (with-monad
>   parser-m
>
>   (defn token-test
> "Parser factory using a predicate. When a token matches the
> predicate, it becomes
>   the new result."
> [pred]
> (domonad
>   [t any-token :when (pred t)]
>   ; return the matched token
>   t))
>
>   (defn match-type
> "Parser factory that matches a particular token type (making the matched
> token the result), or returns nil."
> [type]
> (token-test #(= (% :type) type)))
>
>   (defn optional [parser]
> (m-plus parser (m-result nil)))
>
>   (declare element one-or-more)
>
>   (defn none-or-more [parser]
> (optional (one-or-more parser)))
>
>   (defn one-or-more [parser]
> (domonad [a parser
>   as (none-or-more parser)]
>  (cons a as)))
>
>   (defn attribute
> "Parser generator that matches attribute tokens, adding them to
> :attributes key of the element-node, and returning the new
> element-node."
> [element-node]
> (domonad [attribute-token (match-type :attribute)]
>  (add-to-key-list element-node :attributes attribute-token)))
>
>   (defn text
> "Parser generator that matches text tokens, adding them to the :body
> key of the element-node, and returning the new element-node."
> [element-node]
> (domonad [text-token (match-type :text)]
>  (add-to-key-list element-node :body text-token)))
>
>   (def match-first m-plus)
>
>   (defn body-token
> [element-node]
>   (match-first
> (attribute element-node)
> (text element-node)
> (element element-node)))
>
>   (defn process-body
> [element-node]
> (domonad [modified-element (optional (body-token element-node))]
>  (or modified-element element-node)))
>
>   (defn element
> "Parses an element token into an element-node, and then adds the
> fully constructed element-node to the
> :body of the containing element node."
> [container-element-node]
> (domonad [token (match-type :start-element)
>   element-node (m-result (struct element-node :element token))
>   assembled-node (process-body element-node)
>   _ (match-type :end-element)]
>  (add-to-key-list container-element-node :body assembled-node)))
>
>
>   (def template
> ; Creates a psuedo-element (an empty map) and parses the root
> element into it, then extracts the root element.
> ; Will eventually have to expand to support text and comments,
> e

Re: Byte Overflow

2009-05-08 Thread Stephen C. Gilardi


On May 8, 2009, at 10:42 PM, tmountain wrote:


I'm working on a project that makes use of a lot of byte arrays, and
I'm having an issue with certain bytes overflowing to negative values.
I know they're being stored properly because I'm also generating hex
dumps from time to time which indicate the real value is there. Can
someone tell me how to go about making comparisons with the actual
values?

user=> (byte 254)
-2

(def my-byte (make-array (Byte/TYPE) 1))
(aset my-byte 0 (byte 254))
(println (format-hex-string (HexByte/byteArrayToHexString my-byte)))
... returns "0xFE" ...

user=> (= (byte 254) 0xFE)
false


The byte type is always signed in Java. Its range is -128 to 127.

It's documented here:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Byte.html

If you need to compare a byte to another value, one way is coerce both  
to byte for the comparison:


user=> (= (byte 254) (byte 0xFE))
true

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: AIML pattern matcher design

2009-05-08 Thread Adrian Cuthbertson

I found that after a couple of months of working with Clojure, my
whole perspective on thinking about the problem domain and its
possible abstractions changed really significantly. An approach that
might benefit you is to spend a while dabbling with some repl
explorations of some of the key Clojure features. I would start with
really getting to understand maps, vectors, map and reduce, sequences
and lazy-seq. A good grasp of multi-methods would be helpful. Also
check out cond and condp. I also found an understanding of using first
order functions and closures invaluable (e.g storing a function closed
over some arguments in a map entry for dynamic program composition).
There are others, but those are good to start with. In the beginning
avoid recur (leads to too much imperative thinking) and macros (I
found for most things I thought a macro would be needed that they
could be done easily in basic clojure).

After the basics check out the clojure.core source and the source for
the contrib libraries (xml, zip, etc) that you may be using. The
source is a great learning resource. Also Mark Volkmann's guide
(http://java.ociweb.com/mark/clojure/article.html), Stuart Halloway's
book and clojure.org are great resources for getting into Clojure.

Rgds, Adrian.


On Fri, May 8, 2009 at 7:23 PM, Luke VanderHart
 wrote:
>
>> ; First thing to learn is XML parsing with Clojure.
>
> This is basically done. Use the xml library in core if you just need
> to load XML into a map data structure. Use the zip library if you need
> to navigate it. Use the xml library in contrib if you need to do xpath-
> style navigation.
>
> For the rest of it... it looks very well thought out. I'm not familiar
> enough with the problem domain to comment specifically, but obviously
> you're putting a lot of thought into it, so I'm pretty sure you won't
> have any problems.
>
> -Luke
>
> On May 8, 12:50 pm, dhs827  wrote:
>> I'm stealing knowledge left and right (just ask me :-) to design me an
>> AIML pattern matcher. I've compiled a draft list of objects and
>> behaviors, which I would like to see reviewed for plausibility:
>>
>> startup
>>         - opens configuration file (e.g. startup.xml)
>>         - passes configuration file to bot-loader object
>> bot-loader
>>         - loads general input substitutions (spelling, person)
>>         - loads sentence splitters (.;!?)
>>         - looks for enabled bot, takes first one it finds
>>         - reads bot-id; uses it as key (for saving/loading variables and
>> chatlogs)
>>         - loads bot properties (global constants, e.g. name)
>>         - passes control to aiml-loader object
>> aiml-loader
>>         - loads list of AIML files to load, and for each file
>>                 - opens file
>>                 - reads AIML categories (XML) one by one as they appear in 
>> the file
>>                         - parses and stores the content of the match path 
>> (e.g."BOTID *
>> INPUTPATTERN * CONTEXT1 * CONTEXT2 *")
>>                         - when it reaches the end of the category - the 
>> template, or leaf
>> of this branch of the tree
>>                                 - calls a method to store the elements of 
>> the match path, together
>> with the template, in the
>> pattern-matcher-tree
>>
>> ; First thing to learn is XML parsing with Clojure.
>>
>> ; Though it is probably the easiest thing to do, it is not necessary
>> for the templates to be stored along with the paths in the tree. They
>> might as well be left on disc or in a database.
>>
>> ; A function like parser/scan must advance the parse to the next part
>> of the document (element - element content - processing
>> instruction...) and tokenize it. I can then use case/switch/if (must
>> look at what Clojure offers) to make decisions/set variables/call
>> methods.
>>
>> ; The whole path, with all components, gets created at load time. The
>> loader combines all elements of the path (e.g. INPUTPATTERN * CONTEXT1
>> * CONTEXT2 *) into one string, seperating the components using special
>> context-id strings (e.g. , , )
>>
>> ; The idea of the AIML graphmaster is: take this string, seperate it
>> into words, then store these words as nodes in a tree.
>>
>> ; A variation of this idea: instead of keying the nodes by their
>> values, key them first by context, then by value.
>>
>> ; Now that the bot is up and running, the user types something into
>> the input box and hits Enter. The
>>
>> pre-processor
>>         - protects sentences
>>         - blocks common attack vectors, e.g. code injection, flooding
>>         - eliminates common spelling mistakes
>>                 - for each loaded substitution
>>                         - finds and replaces it in the input string
>>                 - alternatively, uses a tree to search for them
>>         - removes redundant whitespace
>>         - splits input into sentences (everything that follows is for each
>> sentence)
>> pattern-matcher
>>         - combines INPUTPATTERN * CONTEXT1

Re: Launching apps

2009-05-08 Thread Adrian Cuthbertson

For production server systems running under Linux, I've used apache
commons daemon to get java apps launched, for example under root to
get port 80 and then su'd to run under the app (non-privileged)
userid. The advantage is these can be automatically restarted when the
server reboots, or services are restarted by operations, etc. Check
Google for "jsvc" or "commons daemon" for details.

I haven't yet used this for Clojure apps yet but intend to when
deploying them for server production. Should be easy to do, but I'll
post on that when I've tried it out.

Regards, Adrian.

On Sat, May 9, 2009 at 1:12 AM, André Thieme
 wrote:
>
> On 9 Mai, 00:30, Chris Dean  wrote:
>> How do folks launch their apps?
>>
>> For building (and maybe deploying) it seems that most people use the
>> Java tools (ant, maven, ivy) or have a 10 line shell script.  For pure
>> Clojure code you don't even necessarily have to have a build step.
>>
>> But how do you launch your code in a production style setting?
>
> Depending on what kind of app it is. If it is a desktop application
> then a .jar file that can be doubleclicked to run sounds like the
> right thing. An alternative would be applets or Webstart.
>
> For server apps it could be a launch script.
> The launch script could be run in a screen.
> >
>

--~--~-~--~~~---~--~~
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: AIML pattern matcher design

2009-05-08 Thread Parth Malwankar

On Fri, 08 May 2009 22:20:13 +0530, dhs827  wrote:

>

>
> ; First thing to learn is XML parsing with Clojure.
>

>
> Other comments, tips, disses?
>
> Dirk

In case you don't expect end users or other languages
to access the configuration, one option you have is
to save the configuration directly as Clojure data.

As Clojure is a lisp, you have access to the reader and
you could read the data (maps, vectors, etc.)
directly from the file.

E.g.:

user=> (def x (read-string "{:a 1 :b 2}"))
#'user/x
user=> x
{:a 1, :b 2}
user=>

See also: (doc read)

If you decide to go ahead with xml, you can use
the xml support in clojure core:

http://clojure.org/api#toc673

Regards,
Parth


--~--~-~--~~~---~--~~
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: Byte Overflow

2009-05-08 Thread tmountain

Ahh, should've looked at the docs. Thanks for the helpful response.

Travis

On May 8, 11:09 pm, "Stephen C. Gilardi"  wrote:
> On May 8, 2009, at 10:42 PM, tmountain wrote:
>
>
>
> > I'm working on a project that makes use of a lot of byte arrays, and
> > I'm having an issue with certain bytes overflowing to negative values.
> > I know they're being stored properly because I'm also generating hex
> > dumps from time to time which indicate the real value is there. Can
> > someone tell me how to go about making comparisons with the actual
> > values?
>
> > user=> (byte 254)
> > -2
>
> > (def my-byte (make-array (Byte/TYPE) 1))
> > (aset my-byte 0 (byte 254))
> > (println (format-hex-string (HexByte/byteArrayToHexString my-byte)))
> > ... returns "0xFE" ...
>
> > user=> (= (byte 254) 0xFE)
> > false
>
> The byte type is always signed in Java. Its range is -128 to 127.
>
> It's documented here:
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Byte.html
>
> If you need to compare a byte to another value, one way is coerce both  
> to byte for the comparison:
>
> user=> (= (byte 254) (byte 0xFE))
> true
>
> --Steve
>
>  smime.p7s
> 3KViewDownload
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Add JNDI lookup support for contrib/sql

2009-05-08 Thread Mark Derricutt
Hi,

Can we add the following to contrib's sql namespace, it simply adds "jndi"
as a db-spec scheme ( I also raised this as
http://code.google.com/p/clojure-contrib/issues/detail?id=39 , which google
decided to set as a defect and I can't change):

Index: src/clojure/contrib/sql/internal.clj
===
--- src/clojure/contrib/sql/internal.clj (revision 776)
+++ src/clojure/contrib/sql/internal.clj (working copy)
@@ -56,17 +56,19 @@
 :subprotocol (required) a String, the jdbc subprotocol
 :subname (required) a String, the jdbc subname
 (others) (optional) passed to the driver as properties."
-  [{:keys [datasource username password classname subprotocol subname]
+  [{:keys [jndi datasource username password classname subprotocol subname]
 :as db-spec}]
   (when classname
 (clojure.lang.RT/loadClassForName classname))
-  (if datasource
-(if username
-  (.getConnection datasource username password)
-  (.getConnection datasource))
-(java.sql.DriverManager/getConnection
- (format "jdbc:%s:%s" subprotocol subname)
- (as-properties (dissoc db-spec :classname :subprotocol :subname)
+  (if jndi
+(.getConnection (.lookup (javax.naming.InitialContext.) jndi))
+(if datasource
+  (if username
+(.getConnection datasource username password)
+(.getConnection datasource))
+  (java.sql.DriverManager/getConnection
+   (format "jdbc:%s:%s" subprotocol subname)
+   (as-properties (dissoc db-spec :classname :subprotocol
:subname))

 (defn with-connection*
   "Evaluates func in the context of a new connection to a database then




-- 
Discouragement is a dissatisfaction with the past, a distaste for the
present, and a distrust of the future - Maree De Jong, Life NZ.
http://www.talios.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
-~--~~~~--~~--~--~---



Re: partition improvement

2009-05-08 Thread Jason Wolfe

See also "partition-all" in clojure.contrib.seq-utils.  It isn't as
feature-complete as your version, but is instead a drop-in replacement
for "partition" that always returns the final part (regardless of
whether or not it's long enough).

-Jason

On May 8, 4:02 pm, DiG 
wrote:
> Hi all,
>
> Quite often one need to get the last part of partition which is
> smaller than the requested partition size. This change also support
> another common case where one would like to pad the partition.
>
> Since it is such a small change I am pasting the whole function,
> instead of patch, but of cause can produce a patch against core. The
> tests are included too.
>
> http://gist.github.com/109002
>
> Regards,
> Dimitry Gashinsky (digash)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---