Re: Order of keys within a map?

2009-08-28 Thread Travis

Is the number 8 just a magic number? Can it be changed with an
environment variable or system variable or binding? I would definitely
like to.

I am particularly annoyed by how the function into changes my array
maps into hash maps when they grow. The type of the first argument is
an array map, so the type of the return value should be also.

,(class (into (array-map :a 1) (array-map :b 2 :c 3 :d 4 :e 5 :f 6 :g
7 :h 8 :i 9)))

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



in-smaller-lists

2009-09-25 Thread Travis

I'm doing some file streaming with a lazy list and I ran into a
problem where I had to process a whole chunk at a time, so I wrote
this function. Just posting to see if I'm reinventing something or if
it might be a good addition to contrib.

(defn in-smaller-lists [the-list smaller-list-size]
  (lazy-seq (let
[[fnbr the-rest] (split-at smaller-list-size the-list)]
(if (first the-rest)
  (cons fnbr (in-smaller-lists the-rest smaller-list-size))
  (list fnbr))
)))

Example:

user=> (in-smaller-lists (range 11) 3)
((0 1 2) (3 4 5) (6 7 8) (9 10))

I do database work and this is very useful for processing a csv n rows
at a time.

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
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: in-smaller-lists

2009-09-29 Thread Travis

Cool, I thought it must exist somewhere, but the "3 3 nil" is,
although obviously enabling, strange for what I would think should be
default behavior. I'll just go ahead and use

(def in-smaller-lists #(partition %1 %1 nil %2))

Thanks for the tip.

On Sep 25, 8:24 pm, Jeff Valk  wrote:
> On Friday 25 September 2009 at 08:46 pm, Travis wrote:
>
> > I'm doing some file streaming with a lazy list and I ran into a
> > problem where I had to process a whole chunk at a time, so I wrote
> > this function. Just posting to see if I'm reinventing something or if
> > it might be a good addition to contrib.
>
> > (defnin-smaller-lists[the-list smaller-list-size] ...
>
> > Example:
>
> > user=> (in-smaller-lists(range 11) 3)
> > ((0 1 2) (3 4 5) (6 7 8) (9 10))
>
> How about:
>
> user=> (partition 3 3 nil (range 11))
> ((0 1 2) (3 4 5) (6 7 8) (9 10))

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



Newspeak

2009-10-06 Thread Travis

I'd like to query the Clojure community for opinions on Newspeak. I
just listened to this netcast, which I recommend:

http://www.se-radio.net/podcast/2009-07/episode-140-newspeak-and-pluggable-types-gilad-bracha

And the website:

http://newspeaklanguage.org/

Since I found Newspeak before Clojure, I'd be writing in that now if I
could have used JVM libraries. But I'm happy with Clojure now that I'm
here, and the two languages have similarities. I'm just sharing the
link because the topics discussed reminded me of some things I like
about Clojure.

--~--~-~--~~~---~--~~
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: Adding meta data to string?

2009-10-06 Thread Travis

I wonder if anyone has tried namespace level metadata hashes rather
than the current approach of putting it on the object itself. I would
do it this way:

tw$ repl
Clojure 1.1.0-alpha-SNAPSHOT
user=> (ns meta-experiment (:import java.util.WeakHashMap))
java.util.WeakHashMap
meta-experiment=> (def meta-var (WeakHashMap.))
#'meta-experiment/meta-var
meta-experiment=> (defn my-with-meta [the-obj the-meta] (do (if (.get
meta-var the-obj) (throw (Exception. "sorry, immutable"))) (.put meta-
var the-obj the-meta) the-obj))
#'meta-experiment/my-with-meta
meta-experiment=> (defn my-get-meta [the-obj] (.get meta-var the-obj))
#'meta-experiment/my-get-meta
meta-experiment=> (def test-obj (my-with-meta "I have meta" {:meta
"data"}))
#'meta-experiment/test-obj
meta-experiment=> ((my-get-meta test-obj) :meta)
"data"
meta-experiment=> (def should-not-work (my-with-meta "I have
meta" {:does-not "get stored"}))
java.lang.Exception: sorry, immutable (NO_SOURCE_FILE:7)


WeakHashMaps are designed for situations like this to avoid memory
leaks. When the object is garbage collected and the association is no
longer in the map, the metadata may be set once again.


On Oct 5, 9:43 am, Jung Ko  wrote:
> On Sat, Oct 3, 2009 at 7:23 AM, pmf  wrote:
>
> > And String is final, making deriving from it impossible.
>
> > One way (most probably not the best way) would be to wrap it in a Var
> > and attach the metadata to the Var, i.e.
>
> >  (def #^{:blah :foo} my-string "some string")
>
> > Note that to access the metadata of the Var later, you have to use var-
> > quote:
>
> >  ^#'my-string
>
> Thanks for the suggestion. Looks like there is no elegant way to add
> meta data to strings. I ended up changing my functions slightly so
> that I don't need to embed the meta data in the string.
>
> Thanks,
> Jung

--~--~-~--~~~---~--~~
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: immutable defs?

2009-10-06 Thread Travis

+1

In my relatively novice opinion, unless there is a reason to make
functions and vars available to code executing in a *different*
namespace, there isn't a lot of reason to def anything at all.

On Oct 2, 11:48 am, Jonathan Smith  wrote:
> I use a let at the top of the file to denote things that I want to
> have as captured and constant.
>
> ... you can do things like
> (let [x 1]
>  (defn foo-that-uses-x [y]
>   (function-here  x y)))
>
> On Oct 2, 10:29 am, Mark  wrote:
>
> > Is there a way to make a declaration in Clojure that cannot be rebound
> > later?  Ideally, I'd like something that fails if I try to do this:
>
> > (def myname "mark")
> > ; ...more code, elided...
> > (def myname "Mark")
>
> > Perhaps this is obvious, but I see a lot of discussion of immutable
> > data structures, but I can't find a way to prevent my bindings from
> > changing.
>
>
--~--~-~--~~~---~--~~
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: Mapping OOPS concepts to Clojure? Doable or Wrong thinking?

2009-12-12 Thread Travis


On Dec 12, 9:21 am, Joost  wrote:
> * Inheritance is overrated. it tends to be abused as a way to share
> implementation details more than anything else. All the points I made
> about interfaces also apply to inheritance. See also traits, for a way
> to really do reuse:http://scg.unibe.ch/research/traits

I haven't read all the literature on traits, but I've begun using a
pattern in Clojure that resembles the concept. This is a pseudocode
sketch (don't try to execute), but I hope gets the pattern across.

(def trait-a {
  :do-something (fn do-something [applied-to & params]
(using applied-to (mutate params)))
  })

(defn apply-trait [trait apply-to]
  (into {} (map
(fn make-applied-trait-method
  [fn-symbol trait-fn]
  [fn-symbol (partial trait-fn apply-to)])
trait)))

You'd use this like:

(let [
  trait-a-data (struct-map struct-i-use
:datafield1 1 :datafield2 2)
  specific-fns (apply-trait trait-a trait-a-data)
  ]
  ((specific-fns :do-something) to-something))

Have other people done similar things, or have an improvement?

-- 
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: globing filenames via clojure

2009-12-12 Thread Travis


On Dec 12, 11:20 am, Scott  wrote:
> Trying to learn clojure via some simple examples.
>
> I would like to use a simple glob expression to open a file using read-
> line
>
> How would I write the equivalent of:
>
> (for [line (read-lines "*.txt")]
>     (print line))
>
> Where *.txt would match only the first file found in the present
> working directory

I haven't tried executing these, but maybe something like this:

(slurp (first (filter #(re-matches #".*\.txt" %) (.list (File.
"directory/path")

Or, more verbose but using Java's standard FilenameFilter

(slurp (first (.list (File. "directory/path")
  (proxy [FilenameFilter] []
(accept [fil nam] (if (re-matches #".*\.txt" nam) true false))

> what I am actually trying to write is a program to read in a CSV,
> apply to a hash-map, and extract some simple data, so the above is
> intentional simplification
>
> very powerful language, thanks to all that have worked on this

I have a function for parsing CSVs that I put to work a lot at my last
job, using the Ostermiller utils. It works for very large CSVs and is
fairly thoroughly tried.
Send me an email directly if you're stuck on that.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure Kata

2010-01-24 Thread Travis
Occasionally things like this remind me of the similarities between
parsing character sequences and dealing with unpredictably ordered
collections. For character sequences, the regular expression mechanism
has been invented. I wonder if any one else has ever wished for the
ability to write a regular expression for a seq of typed objects.

(defn sift [character-sequence]
(lazy-seq (if-let [
[_ firstsection remainder] (re-find #"(\w\d*)(.*)" (apply str
character-sequence))
]
(cons (list (first firstsection) (rest firstsection))
(sift remainder)

The analog to a character class would be a function taking an object
and returning true or false for whether it matches. Something like
this might be an equivalent regular expression for the given problem.

(defn is-delimiter [listitem]
(re-matches #"\w" (str listitem)))
(defn is-data [listitem]
(re-matches #"\d" (str listitem)))
(defn wildcard [listitem] true)
(def regular-expression (list \( is-delimiter is-data \* \) \
( wildcard \) ))

Make sense?


On Jan 24, 12:58 pm, CuppoJava  wrote:
> It's an elegant puzzle. Thanks Sean!
>
> Here's my take:
> (defn sift [pred? s]
>   (lazy-seq
>     (if (seq s)
>       (let [key (first s)
>             [vals remaining] (split-with #(not (pred? %)) (rest s))]
>         (cons [key vals] (sift pred? remaining))
>
> Running:
> (sift string? ["a" 2 "b" 3 4 "c" "d" 4])
>
> Returns:
> (["a" (2)] ["b" (3 4)] ["c" ()] ["d" (4)])
>
> I'm interested in what you came up with. =)
>   -Patrick

-- 
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: Announcement: Vijual Graph Layout Library for Clojure Version 0.1

2010-01-25 Thread Travis
Any plans to add SVG support? Seems it would, if anything, be easier
than formatting ascii. You could then open it up and color/move stuff.
Any ideas about compatibility with graphviz(.org)? Maybe a .dot file
export?

I've considered making a .dot builder myself.

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


java.lang.Double vs double; converting to [D

2010-02-03 Thread Travis
I'm writing an app that will be dealing with large numbers of numbers.
Perhaps I should gloss over the memory problem until it actually
becomes a problem, but I'm coming across really weird behavior.

user=> (type (first r9))
java.lang.Double
user=> (type (first (into-array Double/TYPE r9)))
java.lang.Double
user=> Double/TYPE
double
user=> (= *2 *3)
true
user=> (= *2 *3)
false
user=> (type (into-array Double/TYPE r9))
[D
user=> (type (double-array r9))
[D

Is the problem at the repl? IE, are primitive doubles being boxed to
java.lang.Double when I access the array via first, so I always see a
class type while they really are primitives?

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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure for system administration

2010-02-03 Thread Travis
I would imagine opening a clojure repl and loading the leiningen
library.

http://github.com/technomancy/leiningen/blob/94c675afe6767aa142bfc882298f0f828e476e24/README.md

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


numbers at the end of generated class name using compile

2010-04-13 Thread Travis
I'm just curious where those numbers come from. For example, if I
compile the class bar.clj containing:

(ns bar)
(defn foo []
  nil)

I'll get three classes, one of which is:

bar$foo__5.class

What is that "5" for?

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

To unsubscribe, reply using "remove me" as the subject.


Re: matching symbols in a dictionary

2010-04-13 Thread Travis
You do mean keywords rather than symbols, right? A symbol would be
'hello. A keyword is :hello.
The ruby name for the clojure keyword concept is "symbol". I used to
get the terminology backwards because of that.

(assert (= (name :hello) "hello"))
(assert (= :hello (keyword "hello")))

On Apr 13, 2:34 pm, strattonbrazil  wrote:
> I want to map a dictionary and do different things depending on the
> key.  I was planning on using an if-clause, but I'm not sure how to
> compare symbols to strings.
>
> Something like
>
> (map (fn [k v] (if (== k "hello") ... ...) {:hello 1 :goodbye 2})
>
> How would I normally compare symbols and strings?

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

To unsubscribe, reply using "remove me" as the subject.


Re: numbers at the end of generated class name using compile

2010-04-13 Thread Travis

On Apr 13, 5:14 pm, Alex Osborne  wrote:
> Travis  writes:
> > I'm just curious where those numbers come from. For example, if I
> > compile the class bar.clj containing:
>
> > (ns bar)
> > (defn foo []
> >   nil)
>
> > I'll get three classes, one of which is:
>
> > bar$foo__5.class
>
> The numbers are just a global incrementing counter (the same one used
> for gensym).  The reason for them is to make the names of the classes
> unique, for example you can define your function foo twice:
>
> (defn foo []
>   nil)
>
> (def baz foo)
>
> (defn foo []
>   5)
>
> A more common example is anonymous functions (fn [] ...).  These all
> have the same name "fn", but they obviously need to be written to
> different class files.

Thanks Alex,

I wonder if it would be possible to specify that name with metadata
and allow for throwing an exception if it's not unique.

I found where this seems to happen in the code but it looks like a
real investment to figure it out and make changes. I may come back to
it at some point soon anyway.

http://github.com/richhickey/clojure/blob/4f6fda54954fe7407967d65a5518906453312395/src/jvm/clojure/lang/Compiler.java#LID5877

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

To unsubscribe, reply using "remove me" as the subject.


Re: user math expression evaluation

2013-05-28 Thread Travis Vachon
Incanter has some stuff that does this:

http://data-sorcery.org/2010/05/14/infix-math/

this looks even closer to what you're looking for:

https://github.com/tristan/clojure-infix

On Tue, May 28, 2013 at 2:19 PM, Brian Craft  wrote:
> Are there any existing libs for the evaluation of math expressions? For
> example, if the user enters "x + sin(y)", parse and evaluate the expression,
> given vectors of floats for x and y.
>
> --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Clojure in production

2013-06-13 Thread Travis Vachon
We've used Clojure at Copious (http://copious.com) to build our
activity feed (http://www.youtube.com/watch?v=0l7Va3-wXeI) and a
number of backend services.

We're definitely looking to use it even more in the future: it's the
cat's pajamas.

On Thu, Jun 13, 2013 at 2:07 PM, Deepak Giridharagopal
 wrote:
> On Monday, June 10, 2013 3:47:25 PM UTC-6, Plinio Balduino wrote:
>>
>> Hi there
>>
>> I'm writing a talk about Clojure in the real world and I would like to
>> know, if possible, which companies are using Clojure for production or
>> to make internal tools.
>
>
> Puppet Labs (http://puppetlabs.com) uses Clojure in some of our internal
> tools, commercial projects, and open source stuff. I gave a talk on PuppetDB
> (https://github.com/puppetlabs/puppetdb) at Clojure/West a few months ago.
> It's currently in production at ~10k installations across the planet.
>
>>
>>
>> Thank you
>>
>> Plínio Balduino
>
> --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[ANN] progressbar: easy progress bars in clojure

2013-08-08 Thread Travis Vachon
progressbar transparently wraps any "map"-able object to print
feedback to standard out as items in the seq are processed:


user> (require '[progressbar.core :refer [progressbar]])
user> (doall (map identity (progressbar (range 10) :print-every 2)))
[) # this is animated from [) to [) using \r
(0 1 2 3 4 5 6 7 8 9)


It is designed to make getting feedback about a long running seq-based
computation trivial. More information, and the source, here:

http://eng.copious.com/blog/2013/08/05/progressbar/
https://github.com/travis/progressbar

Enjoy!

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
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Travis Daudelin
Hi all!

I'm current working on a project where I am ingesting events off a stream 
and processing them. There are many many steps involved in the processing 
component, so I am choosing to write the steps as a series of transducers 
(because, hey, they're super cool!). Here's the problem though, after 
writing the first 2 processing steps I'm noticing that all of them are 
going to look very similar:

(defn a-step-transducer
  []
  (fn [reducing-fn]
 (fn
   ([] (reducing-fn))
   ([result] (reducing-fn result))
   ([[guid-state processed-events :as result] event]
;; step-specific logic


Given how many steps I am planning to write, this is a ton of boilerplate! 
So, my first thought was to use a macro to abstract away all this 
boilerplate. Now, I have to admit that Clojure is my first Lisp, so I'm 
really not sure I fully understand when or why to use macros to do things. 
My current understanding is that macros are a kind of "template" for code, 
so something like this where I don't want to write the same function 
structure over and over seems like a decent use case for macros (feel free 
to correct me if I'm totally off on this). Here is my first attempt:

(defmacro deftransducer
[body]
`(fn [reducing-fn]
   (fn
 ([] (reducing-fn))
 ([result] (reducing-fn result))
 ([[guid-state processed-events :as result] event]
  ~@body

The idea here being that in body I can reference the variables defined by 
the macro like reducing-fn, result, event, etc. Of course, I quickly found 
out that this doesn't work:

storm-etl.entry-processing> (deftransducer "something")
CompilerException java.lang.RuntimeException: Can't use qualified name as 
parameter: storm-etl.entry-processing/reducing-function

Some quick googling tells me that the solution to this is to use gensyms 
for these variable names, but that would defeat the whole purpose of this 
because I want to be able to reference those variables from within the code 
that I pass to my macro. Is this an appropriate use case for macros or am I 
way off base? Is there an alternative approach that would be recommended?

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Travis Daudelin

>
> I think you can do what you want with existing transducers. Won't 
> map/filter/keep/etc do the trick?
>

I can't say for sure that it's not possible, but I certainly lack the 
imagination :). The logic I need to write is quite complicated and I'm 
finding it's easier to write my own transducer to have fine-grained control.

My $0.02 is only resort to macros when all else has failed. Can just higher 
> order functions and composition and injection get you closer to what you 
> want?
>

This seems to be very common feedback on this group, and I'll definitely 
take it to heart. Mostly I just wanted to check my understanding of macros 
and verify that what I want to do is / is not possible using them before 
moving on to higher order functions.

You can "capture" symbols from the surrounding context, making them 
> available to the body of your macros, the "tilde tick trick" is what you're 
> looking for there


Ah perfect! This is exactly what I was hoping would be possible. Your 
examples are right on point, thanks for educating me :)

>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Travis Daudelin


On Friday, June 10, 2016 at 11:43:04 AM UTC-7, Bobby Eickhoff wrote:
>
> But maybe the core function completing is very close to what you're 
> looking for...
>

Hmm, looking through its source I'd say it's exactly what I'm looking for. 
Thank you! 

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Travis Daudelin
Actually, I spoke too soon. It looks like completing takes in a reducing 
function and wraps it so that it meets the arity expectations of a 
transducer. While this is still super useful to my needs (thanks again!) I 
wanted to clarify for posterity that completing does not solve the issue in 
my initial post.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Travis Daudelin
On Friday, June 10, 2016 at 3:03:38 PM UTC-7, Francis Avila wrote:
>
> A higher-order function can do what this macro does: 
> https://gist.github.com/favila/ecdd031e22426b93a78f
>

Oh nice! It looks like I came up with an almost identical solution:
(defn transducing
  [f]
  (fn [reducing-fn]
(fn
  ([] (reducing-fn))
  ([result] (reducing-fn result))
  ([result input] (f result input reducing-fn)

It feels like "writing a custom transducer" should be a common use case, is 
there anything like these functions we've written that exists in the core 
library? I didn't see anything like them there or in the reducers library 
when I first started on my project.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Design pattern question: how to decouple data layer from application layer in Luminus service?

2016-11-18 Thread Travis Daudelin
Hello everyone!

I am investigating Clojure and, more specifically, Luminus 
, for a new service my organization will be 
building soon. My team and I are really excited by the prospect of trying 
out something new.

There is a lot that I like about Luminus' design, but I have some concerns 
about its data-layer is implemented. To be clear, what I mean by "data 
layer" is the code that deals with querying a SQL database. As I understand 
it, Luminus uses HugSQL  and Mount 
 to dynamically construct a set of 
functions at run time and injects them into a namespace that the rest of 
the application code can then call to perform DB operations. This is very 
interesting, but I worry that this tightly couples my application code with 
the data code. For example, what if I want to mock these functions in my 
unit tests so that my tests don't need to depend on a database connection, 
or so that I can mock various DB error scenarios to test that my 
application code handles them appropriately?

Coming from a Java background, I would normally place data layer code 
behind an interface and then at run time pass an implementation of that 
interface to my application code. This allows me a lot of freedom during 
unit testing. What would an equivalent design pattern be in Luminus?

Thanks in advance for any insights!

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: what tutorials exist for working at the Repl in Emacs?

2016-12-23 Thread Travis Daudelin

>
> modern setup in Emacs
>

I generally recommend https://github.com/bbatsov/prelude for newcomers to 
emacs, especially if you are interested in Clojure development. As for the 
repl, Prelude comes with CIDER out of the box and the docs for that are 
quite good: http://cider.readthedocs.io/en/latest/ 

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANN] Eastwood, the Clojure lint tool, version 0.2.4 released

2017-05-23 Thread Travis Daudelin
 Hi, thanks for posting this looks great!

Is there any overlap in functionality between Eastwood and Kibit 
? It's not clear to me which tool I should 
prefer nor when.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANN] Eastwood, the Clojure lint tool, version 0.2.4 released

2017-05-31 Thread Travis Daudelin
Awesome replies everyone, thanks for the advice! Will definitely check 
these plugins out

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Spy - Clojure / ClojureScript library for stubs, spies and mocks

2018-05-02 Thread Travis Daudelin
This looks great! Great timing, I was just struggling with some unit tests 
where I need a way to validate if a function was called

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Parsing Clojure with instaparse: how to handle special forms?

2014-02-06 Thread Travis Moy
I'm trying to use instaparse to parse Clojure code so that I can reformat 
it, but I'm having an issue with how to handle special forms. Should I 
attempt to parse special forms such as let and defn into their own rules, 
or should I rely instead on the actual content of the terminal to determine 
what lists should be treated as special forms?

For example, let's say I want to write a function which takes the parse 
tree returned by instaparse and arranges all the let bindings as 
recommended by the Clojure style guide 
(https://github.com/bbatsov/clojure-style-guide#source-code-layout--organization).
 
There are two approaches I could take:

1) Build the recognition into the grammar itself:

S = Form*
>
>  = !SpecialForm List | ReaderMacro | Literal | Vector | Map | 
>  SpecialForm | !SpecialForm Symbol
> 
> List = '(' Form* ')'
>
>...
>
>  = defn | let | try | JavaMemberAccess | JavaConstructor
> defn = '(' "defn" Symbol String? MapMetadata? VectorDestructuring 
> Form* ')'
>
>  = VectorDestructuring | MapDestructuring
> VectorDestructuring = '[' (Symbol | Destructuring)* ('&' (Symbol | 
> Destructuring))? ']'
> MapDestructuring = Map
>

2) Don't try to detect the let bindings in the grammar. Instead, search the 
resulting parse tree for lists with "let" content.

Which of these is a better approach? I sadly didn't take compilers in 
college so I'm kind of playing this by ear; I'm sure if I had I'd have a 
better idea of what the best practice is here.

Thanks!

(Full code for my project is at 
https://github.com/MoyTW/clojure-toys/tree/master/formatter if needed)

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
S = Form*

 = List | ReaderMacro | Literal | Vector | Map | 
 SpecialForm | Symbol

List = '(' Form* ')'

 = Quote | SyntaxQuote | Var | Dispatch | Comment | Metadata | 
QuotedInternal (*TODO - Slash*)
Quote = "'" Form
SyntaxQuote = '`' Form
Dispatch = '#' DispatchMacro
 = Set | Var | Regex | AnonFuncLit (*TODO - 
IgnoreForm*)
Set = '{' Form* '}'
Var = "'" Form
Regex = String
AnonFuncLit = '(' Form* ')'
Comment = ';' #'[^\n]*'
 = SymbolMetadata | KeywordMetadata | StringMetadata | 
MapMetadata
SymbolMetadata = "^" Symbol Form
KeywordMetadata = "^" Keyword Form
StringMetadata = "^" String Form
MapMetadata = "^" Map Form
 = Unquote | UnquoteSplice | GenSym
Unquote = '~' Form (*TODO - This should ONLY be used INSIDE a 
quoted form!*)
UnquoteSplice = '~@' Form (*TODO - This should ONLY be used INSIDE 
a quoted form!*)
GenSym = Symbol '#' (*TODO - This should ONLY be used INSIDE a 
quoted form!*)

Symbol = Division | Custom
 = '/'
 = 
#'[a-zA-Z\*\+\!\-\_\?\=<>%&][a-zA-Z0-9\*\+\!\-\_\?\=\.<>%&]*/?[a-zA-Z0-9\*\+\!\-\_\?\=\.<>%&]*'

 = String | Number | Character | Boolean | Keyword | NilLiteral
String = '"' #'(\\\"|[^"])*' '"' (*Matches \\\" or any char not \"*)
 = Integer | Float | Ratio (* TODO - add in support for hex/oct 
forms*)
Integer = #'[+-]?[0-9]+r?[0-9]*' (*The r is so you can do 8r52 - 8 
radix 52*)
Float = #'[+-]?([0-9]*\.[0-9]+|[0-9]+\.[0-9]*)' | (*Decimal form*)
#'[+-]?[0-9]+\.?[0-9]*e[+-]?[0-9]+' (*Exponent form*)
Ratio = #'[+-]?[0-9]+/[0-9]+'
Character = #'\\.' | '\\newline' | '\\space' | '\\tab' | '\\formfeed' |
'\\backspace' | '\\return'
(* TODO - add in support for unicode character 
representations!*)
Boolean = 'true' | 'false'
Keyword = #'::?[a-zA-Z0-9\*\+\!\-\_\?]*'
NilLiteral = 'nil'

Vector = '[' Form* ']'
Map = '{' (Form Form)* '}'S = Form*

 = VectorDestructuring | MapDestructuring
VectorDestructuring = '[' (Symbol | Destructuring)* ('&' (Symbol | 
Destructuring))? ']'
MapDestructuring = Map

 = !SpecialForm List | ReaderMacro | Literal | Vector | Map | 
 SpecialForm | !SpecialForm Symbol

List = '(' Form* ')'

 = Quote | SyntaxQuote | Var | Dispatch | Comment | Metadata | 
QuotedInternal (*TODO - Slash*)
Quote = 

Re: Parsing Clojure with instaparse: how to handle special forms?

2014-02-07 Thread Travis Moy
That answers my question pretty well, thanks.

On Thursday, February 6, 2014 11:20:42 PM UTC-8, Reid McKenzie wrote:
>
> Okay. So there's one big thing you're doing wrong here just from reading 
> your grammars: you are complecting the datastructures and valid _tokens_ 
> which make up the clojure language with the _meaing_ associated therewith 
> by the language. If you discard such things as destructuring as "part of 
> the grammar" and instead just provide the parse grammars for basic 
> datastructures like symbols, maps, keywords sets and soforth it's trivial 
> to produce a grammar which can _parse_ valid clojure code. _Reading_ 
> clojure code from such a parse tree is and should be an entirely seperate 
> concern, implemented as a pass over the generated parse structure.
>
> - Reid
>
> On Thursday, February 6, 2014 9:28:08 PM UTC-6, Travis Moy wrote:
>>
>> I'm trying to use instaparse to parse Clojure code so that I can reformat 
>> it, but I'm having an issue with how to handle special forms. Should I 
>> attempt to parse special forms such as let and defn into their own rules, 
>> or should I rely instead on the actual content of the terminal to determine 
>> what lists should be treated as special forms?
>>
>> For example, let's say I want to write a function which takes the parse 
>> tree returned by instaparse and arranges all the let bindings as 
>> recommended by the Clojure style guide (
>> https://github.com/bbatsov/clojure-style-guide#source-code-layout--organization).
>>  
>> There are two approaches I could take:
>>
>> 1) Build the recognition into the grammar itself:
>>
>> S = Form*
>>>
>>>  = !SpecialForm List | ReaderMacro | Literal | Vector | Map | 
>>>  SpecialForm | !SpecialForm Symbol
>>> 
>>> List = '(' Form* ')'
>>>
>>>...
>>>
>>>  = defn | let | try | JavaMemberAccess | JavaConstructor
>>> defn = '(' "defn" Symbol String? MapMetadata? 
>>> VectorDestructuring Form* ')'
>>>
>>>  = VectorDestructuring | MapDestructuring
>>> VectorDestructuring = '[' (Symbol | Destructuring)* ('&' (Symbol | 
>>> Destructuring))? ']'
>>> MapDestructuring = Map
>>>
>>
>> 2) Don't try to detect the let bindings in the grammar. Instead, search 
>> the resulting parse tree for lists with "let" content.
>>
>> Which of these is a better approach? I sadly didn't take compilers in 
>> college so I'm kind of playing this by ear; I'm sure if I had I'd have a 
>> better idea of what the best practice is here.
>>
>> Thanks!
>>
>> (Full code for my project is at 
>> https://github.com/MoyTW/clojure-toys/tree/master/formatter if needed)
>>
>>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: unconditional append to end

2014-02-07 Thread Travis Moy
You should use a vector, but it's also possible to use concat. For example, 
(concat '(1 2 3) [4]) will give you (1 2 3 4).

This made me curious as to the best way to get a collection into vector, so 
I played around with it some:

user=> (def r 10)
> #'user/r
> user=> (def coll (range 1))
> #'user/coll
> user=> (def coll-v (into [] coll))
> #'user/coll-v
> user=> (time (dotimes [_ r] (conj (into [] coll) :a)))
> "Elapsed time: 14074.018464 msecs"
> nil
> user=> (time (dotimes [_ r] (conj (apply vector coll) :a)))
> "Elapsed time: 22565.594515 msecs"
> nil
> user=> (time (dotimes [_ r] (conj (vec coll) :a)))
> "Elapsed time: 22424.174719 msecs"
> nil
> user=> (time (dotimes [_ r] (concat coll '(:a
> "Elapsed time: 5.366059 msecs"
> nil
> user=> (time (dotimes [_ r] (concat coll-v '(:a
> "Elapsed time: 5.56465 msecs"
> nil
> user=> (time (dotimes [_ r] (conj coll-v :a)))
> "Elapsed time: 10.65771 msecs"
> nil
> user=> (time (dotimes [_ r] (concat coll coll)))
> "Elapsed time: 6.048041 msecs"
> nil
> user=> (time (dotimes [_ r] (apply conj coll-v coll-v)))
> "Elapsed time: 72414.847105 msecs"
> nil
>

Surprisingly it looks like (concat coll '(:a)) is faster than (conj coll-v 
:a). That's not really what I would expect; does anybody have a good 
explanation for this? Did I just bork the test somehow, or - I mean, 
obviously concat's pretty fast but I was expecting conj to be on the level. 
In fact, if you convert and then conj it's significantly slower than using 
concat.

...not that it'd really matter, in basically all cases, since (into [] ...) 
is definitely still in the "fast enough" category. Still, if you're 
building a sequence, what's the reasoning against using (concat coll ...) 
instead of (conj (into [] ...) ...)? Is it a matter of elegance, or is 
there a specific practical reason?

On Friday, February 7, 2014 8:06:20 PM UTC-8, Armando Blancas wrote:
>
> For efficient appends at the end you need a vector. Using the sequence 
> library can be tricky while you're putting together your data structures 
> because it's likely that you'll not done yet with type-specific functions. 
> You'll need to re-create your vector after using map/filter/etc to be able 
> to keep adding at the end. 
>
> On Friday, February 7, 2014 4:20:09 PM UTC-8, t x wrote:
>>
>> Consider the following: 
>>
>> (cons 1 '(2 3 4)) ==> (1 2 3 4) 
>> (cons 1 [2 3 4])  ==> (1 2 3 4) 
>>
>> (conj '(a b c) 1) ==> (1 a b c) 
>> (conj '[a b c] 1) ==> [a b c 1] 
>>
>>
>>  
>>
>> Now, I would like something that _always_ 
>>   * appends to the end 
>>
>> cons is almost what I want, except it always appends to front. 
>>
>> conj is not what I want -- in fact, I'm afraid of conj. Often times, 
>> I'll run map/filter on something, and suddenly, instead of a vector, I 
>> now have a list -- and conj changes the order of the item added. 
>>
>> Thus, my question: is there a builtin to _unconditinoally_ append to 
>> the end of a list/sequence/vector? 
>>
>> 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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: unconditional append to end

2014-02-07 Thread Travis Moy
Ah! That makes more sense. Yeah, after I forced it to realize the sequence, 
it turned out that concat was a lot slower than sticking it into an array:

#'user/r
> user=> (def coll (range 1))
> #'user/coll
> user=> (def coll-v (into [] coll))
> #'user/coll-v
> user=> (time (dotimes [_ r] (count (concat coll '(:a)
> "Elapsed time: 55803.147526 msecs"
> nil
> user=> (time (dotimes [_ r] (count (conj coll-v :a
> "Elapsed time: 18.591737 msecs"
> nil
> user=> (time (dotimes [_ r] (count (conj (into [] coll) :a
> "Elapsed time: 16224.79319 msecs"
> nil
>

On Friday, February 7, 2014 9:26:05 PM UTC-8, puzzler wrote:
>
> On Fri, Feb 7, 2014 at 9:08 PM, Travis Moy 
> > wrote:
>
>> Surprisingly it looks like (concat coll '(:a)) is faster than (conj 
>> coll-v :a). That's not really what I would expect; does anybody have a good 
>> explanation for this? Did I just bork the test somehow, or - I mean, 
>> obviously concat's pretty fast but I was expecting conj to be on the level. 
>> In fact, if you convert and then conj it's significantly slower than using 
>> concat.
>>
>
> concat is lazy, so it's not really doing any work until you try to realize 
> the sequence -- that's why it is so fast. 
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


alternative syntax for Clojure? Haskell?

2014-04-05 Thread Travis Wellman
When I started learning Haskell after a year or more of Clojure, the syntax 
was refreshing, and I found myself wishing I could write Clojure with 
Haskell syntax.

Later I left Clojure behind for plain Java because of code maintenance 
issues. I had been writing elegant but deeply nested Clojure code that was 
very difficult to read and realized that Clojure nurtures this propensity 
in its users. Though it's possible to write flatter more linear, more 
readable, more maintainable code, I didn't really want to, and other 
languages are designed for such.

Now I'm coming back to those old discoveries again, and thinking about 
Clojure, and wondering how much work it would be to write a new Haskell-ish 
syntax for using Clojure. I was just looking at core.logic tests, which are 
a perfect example of hard-to-read, using single letter variables, few 
newlines, and zero comments.

To be clear, in this topic I'm not interested in the functional purity of 
Haskell, nor it's libraries or type system, but just the syntax.

Has anyone had a similar experience?

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Treating mutable Java objects as values

2014-04-05 Thread Travis Wellman
If it were my project I would simply not modify mutable values. If they're 
modified outside your own code, then model how they change.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: alternative syntax for Clojure? Haskell?

2014-04-05 Thread Travis Wellman
Francois Rey,

Yes I've been following that project. They're going for purity, which means 
reimplementing a lot of standard java stuff in Frege. Cool project, but 
what I really want is Clojure. Everything Clojure without the parens. So 
you'd get lists, and homoiconicity, and all the Clojure libs, but it would 
look different.

Part of posting here is to gauge whether, if I wrote such a thing to 
scratch my own itch, anyone else would like it. So far I'm getting a pretty 
sincere "no" it seems. It's partially a bad survey because the people here 
are the people who like it here.

Greg, Xtext is new to me, I'll look at it. Antlr is used in a project I'm 
getting paid for right now, so I might try that.

Gary, I think this is the essence of the maintainability problem. The 
terseness of Clojure is pleasurable to the programmer, and they don't 
compensate with documentation or longer function names. What you get is a 
short statement that requires detangling levels of macros and abstractions 
to understand. Honestly I wish programmers had to pay $20 to write a macro. 
Macros are great but should very very rarely be used. Granted none of this 
would be fundamentally changed with a new syntax, but I feel like if one 
didn't begin a line with a paren, one might begin more lines instead of 
nesting deeper; I could easily be wrong about that.

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
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: alternative syntax for Clojure? Haskell?

2014-04-05 Thread Travis Wellman


On Saturday, April 5, 2014 5:51:10 PM UTC-7, Jason Felice wrote:
>
> In the original post:
>
> > I had been writing elegant but deeply nested Clojure code that was very 
> difficult to read ...
>
> I focus on expressivity, specifically because of the write-only 
> phenomenom.  This isn't peculiar to clojure; this happened a lot in the 
> Perl days (so much so, that that's where I remember "write-only code" being 
> coined).  I've seen it with Scheme, Lua, and JavaScript as well.  Some 
> people see it as a flaw of the language, but it's actually the flexibility 
> of the language that allows it.
>

Very true. I often compare Clojure to Perl when it comes up in 
conversation. It may not be a flaw of the language itself, but I think I 
can say it's a flaw of most of the code the community has written in the 
language. I try not to make complaints without looking for a hint of a 
solution to present as well, and so I'm thinking about the syntax.
 

>
> And that's why many people have said things like this: "Write your code 
> _first_ for people to read. You needn't worry about the compiler, it will 
> have much less trouble understanding it than the people if it's correct." 
>  (That's my phrasing.)
>

Good advice rarely taken.
 

>
> So, I wouldn't call code "elegant" if _you_ have trouble reading it when 
> you come back to it.  The algorithm could be elegant, but not the code. 
>  This is just how I use the word, though... I don't get to define it.
>

There is beautiful code, and there are elegant solutions. I use the word 
differently, but I get your meaning.
 

>
> > Though it's possible to write flatter more linear, more readable, more 
> maintainable code, I didn't really want to, and ...
>
> What you wrote sounds to me very much like, "I had some pain, and I 
> learned that what I did caused the pain, and I figured out how to fix the 
> pain... but I'd rather not"  That *apparent* contradiction suggests to me 
> that you skipped the important part about what you really like about that, 
> and I'm very curious... Why didn't you want to write the easier-to-read 
> code?
>

There's the meat. I feel like the syntax of nested parens leads me and 
others to think in terms of nested function calls. The fastest way to get 
Clojure from the brain to the file leaves "write only" code, and we're all 
impatient. Certainly I take time to beautify and document sometimes, but 
that will always be secondary to getting it to run.

I appreciate your thoughts Jason.

>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: alternative syntax for Clojure? Haskell?

2014-04-05 Thread Travis Wellman


On Saturday, April 5, 2014 3:04:01 PM UTC-7, Gary Trakhman wrote:
>
> At least in my case, this process of mental macro/functioncall expansion, 
> or 'abstraction-surfing' as I like to call it, got easier over time.  I 
> feel like it's been a general skill to hone for programming in general, and 
> lisp emphasizes this more than anything else I've seen, but maybe I just 
> drank the kool-aid :-).


I'm not too bad at abstraction surfing, but it's always going to be time 
consuming when you didn't design the abstractions yourself, or designed 
them long ago.
 

>  I'd like to warp my brain with Haskell someday.
>

I highly recommend it, even if you don't end up using it daily.
 

>
> On Saturday, April 5, 2014, Tyler Anderson > 
> wrote:
>
>> Without parenthesis you have to resolve ambiguity through other means 
>> such as the off-side rule, additional operators. Clojure makes it easy to 
>> write dense code that is hard to maintain, but some of your trouble might 
>> be resolved by structuring your code differently. One example would be 
>> Prismatic's Plumbing  https://github.com/prismatic/plumbing
>>
>
That's a good one I'll be sure to use next time I write some Clojure.
 

>
>> I haven't looked to see if anyone has written a version of ML for the 
>> JVM, but if they have it may be what you are looking for. 
>> http://en.wikipedia.org/wiki/Category:ML_programming_language_family  
>>
>
There's MLj http://research.microsoft.com/en-us/um/people/nick/mlj.htm 

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to handle configuration in Clojure?

2014-01-13 Thread Travis Vachon
Another option is to use leiningen profiles to change the classpath,
loading different versions of a (eg) config.clj file in different
environments. This lets you `require` the config namespace and refer
to config parameters like `config/the-configured-value`

Travis

On Mon, Jan 13, 2014 at 11:05 AM, Andrey Antukh  wrote:
> https://github.com/james-henderson/nomad can be one option for manage/store
> a configuration ;) (it uses edn...)
>
> Andrey
>
>
> 2014/1/13 Joachim De Beule 
>>
>> There's also this:
>> https://github.com/clojure-cookbook/clojure-cookbook/blob/master/local-io/edn-config/edn-config.asciidoc
>>
>> Joachim
>>
>> --
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
> --
> Andrey Antukh - Андрей Антух -  /
> 
> http://www.niwi.be
> https://github.com/niwibe
>
> --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Effects of diving into Clojure

2014-01-14 Thread Travis Vachon
+1 here. I'm afraid the only solution I've found is to stop writing
Ruby. ¯\_(ツ)_/¯

On Tue, Jan 14, 2014 at 2:39 PM, Mark  wrote:
> I misread the critical piece of your post :)  You are, indeed, a step ahead
> of me
>
>
> On Tuesday, January 14, 2014 11:30:13 AM UTC-8, g vim wrote:
>>
>> It's been the other way round for me. I always felt Ruby was doing too
>> much under the hood. So much so that I bought "Ruby Under A Microscope"
>> just to find out what was going on. I found it very easy to switch to
>> Clojure because everything is so much more transparent. Now Ruby just
>> feels awkward though I still need to use it due to its mindshare in the
>> web development domain.
>>
>> gvim
>>
>>
>> On 14/01/2014 19:18, Mark wrote:
>> > I have felt your pain.  I started life with Smalltalk and more or less
>> > spent the last 15 years in Java.  When I started Clojure, it was very
>> > hard to break my thinking habits.  Particularly, I was lost without
>> > manifest typing.  I didn't realize how much types documented my system
>> > and allowed very lazy thinking on my part.  I had less trouble with
>> > immutability as I had developed the habit of coding immutable objects in
>> > Java.
>> >
>> > I started dabbling in Clojure about a year ago and started coding a
>> > serious project about 3 months ago.  Only recently have I gotten used to
>> > thinking about mapping functions over data as opposed to looping through
>> > a collection although I still find myself coding loop/recur and then
>> > realizing I could use map.  I've also developed very different work
>> > habits due to the REPL.
>> >
>> > In my own case, the particular changes in my thinking that have really
>> > aided me are:
>> >
>> >  1. Being able to visualize the data structure that a function is
>> > operating on
>> >  2. I find that my code falls into two categories:  computing new data
>> > or transforming data structures
>> >  3. Never try to compute new data and transform data at the same time
>> >  4. Much of the time computing new data is either map or reduce.
>> >   Understanding these two (especially the flexibility of reduce) is
>> > huge
>> >  5. 80% of the time that I want to transform data, postwalk is the
>> > answer
>> >
>> > I'm sure that as I get to know the Clojure libraries better, the
>> > specifics around #4 and #5 will change but I bet the first three are
>> > pretty constant.
>> >
>
> --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


lazy maps in Clojure?

2013-01-20 Thread Larry Travis
One of the neat things about Clojure (maybe all functional languages) is 
that functions can be defined either extensionally or intensionally. How 
can one create a Clojure structure that mixes these two types of 
definition?


That is, I would like to define a function f that saves its result the 
first time it is called against any particular argument so that if and 
when f is later called against the same argument, it does a look-up via 
a hash map rather than repeating a possibly expensive computation. I 
think I see how to do this with a ref to a mutable map (where, given an 
argument k, f would first try to find (f k) in the map but, if k is not 
currently a key of the map, the function would compute the value v = (f 
k) and then, in addition to returning v, add the entry  to the map 
as a side effect. But this seems ugly. Is there some way to do what I 
want here without making explicit use of refs?


Lazy-seqs don't give me what I want because the arguments to be given to 
f don't occur in any kind of predictable sequence.


  --Larry

--
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: lazy maps in Clojure?

2013-01-21 Thread Larry Travis
Thanks, all. Memoize appears to be exactly what I was looking for. Is 
there no end to discovering eminently useful capabilities hidden away 
some place in Clojure's API?


For the moment I don't see what Meikel Brandmeyer's lazymap gives me 
that memoize doesn't, but I will look into it.

  --Larry

On 1/21/13 1:55 AM, Jozef Wagner wrote:

Or maybe https://bitbucket.org/kotarak/lazymap ?

On Monday, January 21, 2013 7:38:01 AM UTC+1, Alex Baranosky wrote:

memoize, or delay maybe

On Sun, Jan 20, 2013 at 10:29 PM, AtKaaZ > wrote:

memoize?


On Mon, Jan 21, 2013 at 7:27 AM, Larry Travis
> wrote:

One of the neat things about Clojure (maybe all functional
languages) is that functions can be defined either
extensionally or intensionally. How can one create a
Clojure structure that mixes these two types of definition?

That is, I would like to define a function f that saves
its result the first time it is called against any
particular argument so that if and when f is later called
against the same argument, it does a look-up via a hash
map rather than repeating a possibly expensive
computation. I think I see how to do this with a ref to a
mutable map (where, given an argument k, f would first try
to find (f k) in the map but, if k is not currently a key
of the map, the function would compute the value v = (f k)
and then, in addition to returning v, add the entry 
to the map as a side effect. But this seems ugly. Is there
some way to do what I want here without making explicit
use of refs?

Lazy-seqs don't give me what I want because the arguments
to be given to f don't occur in any kind of predictable
sequence.

  --Larry



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

functions as return values

2013-02-23 Thread Larry Travis
In Clojure, if I have a function call that asks for return of a 
function, for example


user> ((fn [a] (fn [b] (+ (inc a) (* b b 5)

I get the function name

#

But what I would like to get is an expression that defines this 
function, for example


(fn [b] (+ 6 (* b b)))

Is there some way that I can suppress the evaluation of this expression?

  --Larry




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: functions as return values

2013-02-23 Thread Larry Travis

I am afraid I didn't ask my question clearly.


Michael's "solution" would give as output

(fn [b] (+ (inc a) (* b b)))



What I want as output is

(fn [b] (+ 6 (* b b)))


... where those expressions within the inner-lambda scope (of the 
original nested-lambda expression) that can be evaluated by the binding 
of the outer-lambda parameter -- that is, the expressions "a" and "(inc 
a)" -- have been fixed with their values, but what is then output is the 
resulting Clojure function definition determined by the unevaluatable 
remainder of the inner-lambda scope.


It occurs to me that whether what I am asking for is possible at all 
depends on how closures are realized within Clojure, but I think that 
there would be a way of realizing them in terms of source code rather 
than compiled code -- and that this source code wouldn't be compiled 
until values for their open variables become available.

  --Larry




On 2/23/13 5:50 PM, Michael Klishin wrote:


2013/2/24 Larry Travis mailto:tra...@cs.wisc.edu>>

Is there some way that I can suppress the evaluation of this
expression?


((fn [a]
  '(fn [b] (+ (inc a) (* b b 5)
--
MK



On 2/23/13 4:50 PM, Larry Travis wrote:
In Clojure, if I have a function call that asks for return of a 
function, for example


user> ((fn [a] (fn [b] (+ (inc a) (* b b 5)

I get the function name

#user$eval4164$fn__4165$fn__4166@29770daa>


But what I would like to get is an expression that defines this 
function, for example


(fn [b] (+ 6 (* b b)))

Is there some way that I can suppress the evaluation of this expression?

  --Larry 


--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: :use an entire namespace full of protocols or stick with :require?

2013-03-09 Thread Travis Vachon
Speaking strictly for myself, but as someone who spends about half his
professional day writing Clojure: :use is dead, long live :require.

I've found using ":require [foo :refer :all]" rather than ":use foo"
has lead to cleaner, more consistent ns statements in my own code, and
I've made it a policy to convert old :use statements to ":refer :all"
whenever possible.

Travis



On Sat, Mar 9, 2013 at 6:00 PM, Korny Sietsma  wrote:
> [reviving a slightly old thread]
> Note that as of clojure 1.4 you can also do:
>   (:require foo.bar :refer :all)
> in fact from comments I've seen elsewhere there is a general intention to
> remove :use entirely?
>
> It'd be good to have some clarity on this.  The vast majority of code
> samples use :use, some with :only.  The docstring for ns doesn't even
> mention :refer! The clojure cheatsheet points to
> http://clojuredocs.org/clojure_core/clojure.core/ns which _does_ have the
> new syntax, in the last couple of examples; and it links to the tutorial at
> http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html
> which uses 'use' throughout, except for an easily missable update half way
> through that says to use :refer.
>
> So, to what extent are people actually deprecating :use ?  I'm introducing a
> new team to clojure and trying to suggest that :refer is the way to go, but
> it's tricky when every code sample out there uses :use.
>
> Especially for the situation where you actually want to import a whole
> namespace - should we be using:
> (:use midje.sweet)
> or:
> (:require midje.sweet :refer :all)
> ?
>
> - Korny
>
>
> On 15 February 2013 00:26, Jim foo.bar  wrote:
>>
>> I know that using a bare :use in the ns macro is generally frowned upon as
>> it provides no hints about what is actually being used...
>>
>> However, I 've got 2 namespaces 'abstractions.clj' and
>> 'concretions.clj'...concretions.clj will eventually use all the protocols
>> defined in abstractions.clj...at the moment it doesn't but as I work through
>> it I want to provide concrete records for all the protocols...
>>
>> Should I just go and :use the entire thing or should I stick with :require
>> and keep typing 'pro/XXX' a million times? That specific namespace is very
>> central to my work...
>>
>> Jim
>>
>> --
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
>
>
>
> --
> Kornelis Sietsma  korny at my surname dot com http://korny.info
> "We do not quit playing because we grow old, we grow old because we quit
> playing" - O.W. Holmes
>
> --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: What's the point of -> ?

2013-03-11 Thread Travis Vachon
-> can also be used in conjunction with a well designed DSL to
construct values in a very readable fashion. clj-time has some great
examples of this:


http://seancorfield.github.com/clj-time/doc/clj-time.core.html#var-from-now
(-> 30 minutes from-now)

http://seancorfield.github.com/clj-time/doc/clj-time.core.html#var-ago :
(-> 5 years ago)

Note that this takes advantage of the fact that (-> 30 minutes
from-now) is equivalent to (-> 30 (minutes) (from-now))

t

On Mon, Mar 11, 2013 at 12:29 PM, Fogus  wrote:
> I wrote a post about -> and ->> a few years ago that might be helpful.
> http://blog.fogus.me/2009/09/04/understanding-the-clojure-macro/
>
> --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Namespaces, APIs, protocols and records

2013-04-15 Thread Travis Vachon
For what it's worth, I've been refactoring big namespaces out into
small, focused namespaces lately. A rough heuristic I've found useful
is that when I require a namespace I should be able to assign it a
name that aids with readability.

So for example:

(ns foo.book)

(defn search [book term]
  ;;search the book
  )
--
(ns foo.stacks)

(defn search [stacks title]
;; search stacks
)
--
(ns foo.library
  (require [foo.book :as book]
  [foo.stacks :as stacks]))

(defn find-passage [stacks passage title]
  (-> stacks
   (stacks/search title)
   (books/search passage)))
-

This is all pretty contrived, but it seems to work out in the wild
pretty well. YMMV, and I'm still not settled on this myself, but
hopefully that helps.

Travis





On Sun, Apr 14, 2013 at 2:16 PM, Simon Katz  wrote:
> Whoops — when I said "with an extra [namespace] for each protocol", I meant
> "with an extra [namespace] for each protocol implementation".
>
>
> On Sunday, 14 April 2013 18:21:19 UTC+1, Simon Katz wrote:
>>
>> I'm in the process of trying to work out how I want to use namespaces when
>> implementing libraries or subsystems.
>>
>> I'm aware of several approaches:
>>
>> Use a single namespace, making only the API public (either with everything
>> in a single file or breaking things into multiple files and using `load`).
>> Use implementation namespaces and create an API in a separate namespace
>> (perhaps using Potemkin to simplify the creation of the API).
>> Have lots of smaller namespaces and have the client need to know which of
>> the smaller namespaces to use for what.
>> (And some variations.)
>>
>>
>> I'm fairly happy with large namespaces, so I'm leaning towards using a
>> single namespace.
>>
>> There's one thing I've come across that doesn't fit nicely with putting
>> everything into a single namespace, though.  A Google search for "Clojure in
>> the Large" led me to a nice talk by Stuart Sierra
>> (http://vimeo.com/46163090) in which he suggests putting protocols and their
>> implementations in separate namespaces, because, during development
>> reloading a protocol breaks existing instances.  (I know Stuart gave a
>> similarly presentation at Clojure West recently, but I don't think the video
>> of that is available yet.)
>>
>> Having the separate namespaces would be fine if I was heading down the
>> route of having the client know about multiple namespaces, but I don't
>> really want to do that.  With the single namespace approach (with an extra
>> one for each protocol I define), I end up wanting circular dependencies — a
>> namespace containing a protocol implementation needs to refer to the main
>> namespace in order to mention the protocol, and the main namespace needs to
>> refer to the namespaces containing protocol implementations in order to
>> invoke constructors.
>>
>> Maybe I'll just put everything in a single namespace and be careful about
>> reloading the whole thing when I care about existing instances of protocols.
>>
>> Any other suggestions?
>>
>> Simon
>
> --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Namespaces, APIs, protocols and records

2013-04-15 Thread Travis Vachon
>  I definitely like that it keeps things simpler for me (the implementer), but 
> clients have to know about multiple namespaces rather than a single namespace 
> and I don't like that.

Ah, right - I've mostly been working in application code, not
libraries. That said, I think the heuristic still works - I'd
definitely try writing some code that consumes your library, either in
tests or in a dummy project, and apply the same rule: can you give the
namespace a name that makes function calls clearer? Given a single
name, are there pieces that feel out of place?

This is a topic that comes up a lot, and I think that's at least
partially because different domains and library styles call for
different strategies. An ideal library that does one thing really well
might indeed be a good candidate for one big public namespace, but of
course internally it might make a lot of sense to break the
implementation up into focused modules.

You might check out the clojurewerks libraries for some insight from a
group that has written quite a few libraries:

http://clojurewerkz.org/

Travis

On Mon, Apr 15, 2013 at 11:23 AM, Simon Katz  wrote:
> I'm considering going this way.  I definitely like that it keeps things
> simpler for me (the implementer), but clients have to know about multiple
> namespaces rather than a single namespace and I don't like that.
>
> I must say I'm finding it hard to decide which way to go.
>
>
> On Monday, 15 April 2013 15:31:49 UTC+1, travis vachon wrote:
>>
>> For what it's worth, I've been refactoring big namespaces out into
>> small, focused namespaces lately. A rough heuristic I've found useful
>> is that when I require a namespace I should be able to assign it a
>> name that aids with readability.
>>
>> So for example:
>>
>> (ns foo.book)
>>
>> (defn search [book term]
>>   ;;search the book
>>   )
>> --
>> (ns foo.stacks)
>>
>> (defn search [stacks title]
>> ;; search stacks
>> )
>> --
>> (ns foo.library
>>   (require [foo.book :as book]
>>   [foo.stacks :as stacks]))
>>
>> (defn find-passage [stacks passage title]
>>   (-> stacks
>>(stacks/search title)
>>(books/search passage)))
>> -
>>
>> This is all pretty contrived, but it seems to work out in the wild
>> pretty well. YMMV, and I'm still not settled on this myself, but
>> hopefully that helps.
>>
>> Travis
>>
>>
>>
>>
>>
>> On Sun, Apr 14, 2013 at 2:16 PM, Simon Katz  wrote:
>> > Whoops — when I said "with an extra [namespace] for each protocol", I
>> > meant
>> > "with an extra [namespace] for each protocol implementation".
>> >
>> >
>> > On Sunday, 14 April 2013 18:21:19 UTC+1, Simon Katz wrote:
>> >>
>> >> I'm in the process of trying to work out how I want to use namespaces
>> >> when
>> >> implementing libraries or subsystems.
>> >>
>> >> I'm aware of several approaches:
>> >>
>> >> Use a single namespace, making only the API public (either with
>> >> everything
>> >> in a single file or breaking things into multiple files and using
>> >> `load`).
>> >> Use implementation namespaces and create an API in a separate namespace
>> >> (perhaps using Potemkin to simplify the creation of the API).
>> >> Have lots of smaller namespaces and have the client need to know which
>> >> of
>> >> the smaller namespaces to use for what.
>> >> (And some variations.)
>> >>
>> >>
>> >> I'm fairly happy with large namespaces, so I'm leaning towards using a
>> >> single namespace.
>> >>
>> >> There's one thing I've come across that doesn't fit nicely with putting
>> >> everything into a single namespace, though.  A Google search for
>> >> "Clojure in
>> >> the Large" led me to a nice talk by Stuart Sierra
>> >> (http://vimeo.com/46163090) in which he suggests putting protocols and
>> >> their
>> >> implementations in separate namespaces, because, during development
>> >> reloading a protocol breaks existing instances.  (I know Stuart gave a
>> >> similarly presentation at Clojure West recently, but I don't think the
>> >> video
>> >> of that is available yet.)
>> >>
>> >> Having the separate namespaces would be fine if I was heading down the
>

Re: binding funkiness

2013-04-22 Thread Travis Vachon
Hi Daniel

map is creating a lazy seq, which isn't evaluated until the REPL's
forces it to be printed, which is outside the scope of the binding.

This:

(binding [*funkybind* true]
  (doall (map (fn [_] *funkybind*) [1 2])))

forces evaluation inside the binding, and does what you want.

This is something I've been bitten by a few times, but the power that
lazyness brings ends up being worth it, IMHO.

Good luck!

Travis

On Mon, Apr 22, 2013 at 9:41 PM, Daniel Higginbotham
 wrote:
> I've encountered a situation where the binding function doesn't work as I
> expect it:
>
> user> (def ^:dynamic *funkybind* false)
>
> ;; expected
> user> (binding [*funkybind* true]
>   *funkybind*)
> true
>
> ;;expected
> (binding [*funkybind* true]
>   ((fn [] *funkybind*)))
> true
>
> ;;... huh?
> (binding [*funkybind* true]
>   (map (fn [_] *funkybind*) [1 2]))
> (false false)
>
> In the last example, why is the value of *funkybind* false instead of true?
>
> Thanks!
> Daniel
>
> --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Complex type in clojure

2010-06-01 Thread Travis Hoffman
I was curious what it would take to add a complex number type to
Clojure Core. If anyone else is curious, it doesn't take much:

1.) Add clojure.lang.Complex
2.) Add a Pattern and code to match, parse and create complex numbers
in LispReader (parses number of the form 1.0+0.0i)
3.) Add ComplexOps class (and a few related

I tried to follow Ratio's example as closely as I could, though there
is some trickiness things about implementing lt ... there really isn't
an accepted definition for saying one complex number is greater than
another.

I'm a bit new to Git/GitHub and to Clojure, but if you're curious I
think I correctly created a fork of the master branch with my changes.

How would I go about submitting a ticket to add the "Complex" type and
to create a patch to submit my proposed changes?

Cheers,

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
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: Complex type in clojure

2010-06-05 Thread Travis Hoffman
Hi Konrad,

First off, thanks for the advice, steps and link! Secondly, the link
to my fork is:

git://github.com/travis-a-hoffman/clojure.git

I did notice your Complex implementation in clojure-contrib, and I
especially appreciated the effort in the generalizations. I'm a total
n00b to Clojure and functional programming. From what I've read about
the intentional exclusion of reader macros (as an example) it seems
that it is in keeping with the spirit of the language to keep the
basic mathematical operations in the core of the language and to *not*
generalize it.

Also, it seems more elegant to me to be able to simply write a complex
number in a "natural" way i.e. 5+3i. I didn't see a way to do that
without modifying clojure core

I started with "Number" (b in your note), but ran into some trouble
because of a risk a loss of precision so I used BigDecimal for the
real and imaginary parts. This is what Rich does in Ratio for the
numerator and denominator. Your point on having an Imaginary type is
well taken. I 'll add that soon!

Lastly my real motivation was to gain greater familiarity with the
internals and this seemed like an approachable place to start.

Cheers,
Travis

On Jun 2, 12:23 am, Konrad Hinsen  wrote:
> On 1 Jun 2010, at 20:24, Travis Hoffman wrote:
> I did
> > I was curious what it would take to add a complex number type to
> > Clojure Core. If anyone else is curious, it doesn't take much:
>
> > 1.) Add clojure.lang.Complex
> > 2.) Add a Pattern and code to match, parse and create complex numbers
> > in LispReader (parses number of the form 1.0+0.0i)
> > 3.) Add ComplexOps class (and a few related
>
> Two comments:
>
> 1) The first decision concerning complex numbers is what you want to  
> use them for. There at least three reasonable internal  
> representations, depending on the application domains:
> a) (defrecord complex [^Float real ^Float imag])
> b) (defrecord complex [^java.lang.Number real ^java.lang.Number imag])
> c) (defrecord complex [real imag])
>
> The first is good for numerical work as it occurs in science and  
> engineering. It permits the most efficient implementation because all  
> operations can be expressed in terma of Java primitive types. The  
> second is the most consistent with Clojure's numerical stack, allowing  
> real and imaginary parts to be integers, ratios, big integers etc. -  
> but there would need to be a check to prevent complex numbers to be  
> used inside complex numbers. The last one is the most general in that  
> complex numbers are seen as mathematical structures rather than as  
> numbers; it permits complex polynomials and other data structures that  
> are not numbers. As a consequence, it can't be implemented in the  
> number hierarchy.
>
> An implementation equivalent to c) but predating defrecord and deftype  
> can be found in clojure-contrib. I think it is useful to have  
> (otherwise I wouldn't have written it), but I don't think it should be  
> part of the language itself. If I were to choose a representation to  
> be added to clojure.core, I'd pick b).
>
> 2) It is a good idea to provide an "imaginary" type in addition to  
> "complex". There is an old and much-cited paper that explains the  
> reasons very well; it comes down to eliminating needless  
> multiplications and additions with zero when dealing with pure  
> imaginaries, which occur rather frequently. Another advantage is that  
> there is no need for complex literals; just have 1j return an  
> imaginary literal and use addition to construct complex values.
>
> > I tried to follow Ratio's example as closely as I could, though there
> > is some trickiness things about implementing lt ... there really isn't
> > an accepted definition for saying one complex number is greater than
> > another.
>
> I'd even say that it is accepted that there is no such definition:  
> complex numbers have no order relation. You certainly shouldn't try to  
> implement java.lang.Comparable.
>
> > I'm a bit new to Git/GitHub and to Clojure, but if you're curious I
> > think I correctly created a fork of the master branch with my changes.
>
> Could you give the link to your fork?
>
> > How would I go about submitting a ticket to add the "Complex" type and
> > to create a patch to submit my proposed changes?
>
> 1) Join the clojure-dev list and discuss your proposal there.
> 2) Send a contributor agreement to Rich.
> 3) Join the clojure group on assembla.com
> 4) Follow the instructions athttp://clojure.org/contributingto  
> prepare a patch.
>
> But please start with 1), that's the most important step!
&

Re: Complex type in clojure

2010-06-05 Thread Travis Hoffman
I also took a look at Apache Commons Math:

http://commons.apache.org/math/

It seems to be quite good, unencumbered and actively developed, but I
haven't been able to (easily) find any recommendations or comparisons
of the available libraries.

Maybe the first step for a math group is to evaluate and "bless" an
appropriate library? Or, would we do better to try to develop one from
scratch?

Regards,
Travis


On Jun 2, 12:29 am, Konrad Hinsen  wrote:
> On 2 Jun 2010, at 02:38, Daniel wrote:
>
> > This touches upon another subject though: Clojure lacks a good math
> > library (though Liebke might kill me for that).
>
> Incanter is great but it's not a math library in the sense of what you  
> propose. I'd say you have a chance to survive :-)
>
> > Has anybody thought about a wrapper for Apfloat as a starting  
> > point?  Anybody with any
> > experience, good or bad, using that?
>
> Thought about, yes, but no more than that. I don't have any experience  
> with Apfloat either. But I'd happily join a "Clojure maths interest  
> group" to work on such problems!
>
> Konrad.

-- 
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: Complex type in clojure

2010-06-05 Thread Travis Hoffman
Konrad,

> Thanks, I'll look at that...

I should warn that my changes don't quite seem to be working, there's
something running amuck in the code yet that I'm still working on
debugging, but the core is a bit mystifying.

> > Also, it seems more elegant to me to be able to simply write a complex
> > number in a "natural" way i.e. 5+3i. I didn't see a way to do that
> > without modifying clojure core
>
> No. But I wonder if "5+3i" is very natural for a language that doesn't  
> have infix arithmetic. This notation is just a sum of a real and an  
> imaginary number, so in Clojure I'd expect to see (+ 5 3i) instead.

Konrad, I see your point, but it seems that Rich has chosen a less
"lisp purist" perspective on this. Please consider the following
examples:

(class (/ 3 4)) ; legal
(class 3/4) ; legal
(class 3 / 4)   ; illegal
(class 3/ 4); illegal
(class 3 /4); illegal
(class 1.234e+14) ; legal
(class 1.234e-14)  ; legal
(class 1.234 e-14) ; illegal
(class 1.234e -14) ; illegal
(class 1.234 e -14) ; illegal

It seems to be that Rich has the perspective that a Ratio's toString()
output is also valid input as well, even though this appears to be an
infix notated '/'. What I'm proposing is that a number ending with 'i'
is imaginary or complex, and that a '+' with no spaces may be used to
define a complex

I think the "3+5i" form makes more sense *because* there isn't infix
notation in the language. Please also consider the example of an
exponentiated double. It's permissible to have a '+' or a '-' in the
middle of that number, but it isn't to be confused with an infixed '+'
operation.

> What trouble?

I need to reinvestigate what the trouble was. Maybe it was in the
complexity of parsing, or simply because Rich used BigInteger in
Ratio. I'll get back to you on that one!

> Perhaps a good compromise would be to have a thin Clojure wrapper  
> around a good Java library.

This is what I was thinking too.

-- 
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: Complex type in clojure

2010-06-07 Thread Travis Hoffman
Personally, I thinks it would be much more elegant to have a direct
notation. It could be argued that the Ratio type could also be
implemented without a special Ratio type, but where's the fun in that?

Consider:

(* 3.4+7i 15i)
  vs
(complex-multiply (construct-complex 3.4 7) (construct-complex 0 15))

It is a bit of effort and certainly non-trivial, but it's more of a
large hill to climb rather than a mountain. Again, this is for my
personal curiosity and may lead to nothing. Feel free to add
suggestion to an implementation! Already, I've added two things to my
implementation:

1.) using either i/I or j/J
2.) adding an "Imaginary" type for pure imaginary numbers ... as a
performance improvement.

Thanks all!

-Travis

On Jun 7, 10:32 am, Mark Engelberg  wrote:
> Yes, but in (some versions of) Scheme, (sqrt -1) yields i.
>
> Representing complex numbers and just doing math between two complex
> numbers is not the problem.  Retrofitting Clojure math so that all
> operations work on the entire numeric tower, allowing you to
> seamlessly manipulate complex and non-complex numbers together, is
> non-trivial.
>
> On Mon, Jun 7, 2010 at 12:09 AM, Steven Devijver
>
>
>
>  wrote:
> > For what it's worth, I found that working with complex numbers in
> > clojure doesn't require specialist types or notation at all:
>
> > (defn complex-times [[a_re a_im] [b_re b_im]] [(- (* a_re b_re) (*
> > a_im b_im)) (+ (* a_re b_im) (* a_im b_re))])
> > (defn complex-plus  [[a_re a_im] [b_re b_im]] [(+ a_re b_re) (+ a_im
> > b_im)])
> > (defn complex-minus [[a_re a_im] [b_re b_im]] [(- a_re b_re) (- a_im
> > b_im)])
> > (defn complex-abs [[re im]] (Math/hypot re im))
>
> > (prn (complex-abs (complex-plus [1.5 1] (complex-times [1 -2] [2
> > -1]
>
> > --
> > 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: Complex type in clojure

2010-06-08 Thread Travis Hoffman
Steven,

I see your point, however, if we look (again) at Ratio for insight:

user=> (+ (+ 1 2)/(+ 3 4) 5)
java.lang.ClassCastException: clojure.core$_SLASH_ cannot be cast to
java.lang.Number (NO_SOURCE_FILE:0)

The sort of notation for non-literals you suggest would be required
would actually not be required nor, in my humble opinion, advisable.
Or, at least it is not implemented for Ratio.

Perhaps you're thinking of the '+' and '-' as infixed addition or
subtraction, when they're not intended to be, no more than the '/' is
infixed division in a Ratio. Instead, one could do:

user=> (+ 1 2i)
1+2i

Lastly, I'll argue it's not so much literals that are the big need as
are stored values. If you saved a Ratio in a String (say, in a
Database), you can retrieve and read it in "naturally" with it's
toString() format. I suppose java serialized storage does avoid this,
but we still would need to handle the "natural" toString() format of
the output of a complex number, just as Ratio does.

On a side note, I really appreciate all these contrasting opinions.
Ultimately, I'm going to have to convince Rich and the other core
developers to make this change, and I think I'm going to have a much
more well-reasoned and developed argument for the change when I
do! :-)

-Travis

On Jun 8, 6:33 am, Steven Devijver  wrote:
> On 8 jun, 05:47, Daniel  wrote:
>
> > These notation arguments are compelling.
>
> I'm not convinced. The notation would only work for literals, and how
> often would one write literal complex numbers?
>
> For non-literals the notation would need to support this:
>
> (* (my-complicated-algo x)+(my-other-complicated-algo y)i (another-
> algo z)i)
>
> This is no issue at all without this notation:
>
> (complex-times [(my-complicated-algo x) (my-other-complicated-algo y)]
> [0 (another-algo z)])
>
> Implementing this notation would obviously require a serious overhaul
> of clojure for a nice-to-have feature.

-- 
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: Complex type in clojure

2010-06-08 Thread Travis Hoffman
Well, I don't find the question to be irrelevant. It makes me think
about a couple issues:

1.) Should Complex and Imaginary extend java.lang.Number?
2.) What do we do with the standard Java math functions?
3.) Is 'i' by itself, valid input as a number?

First, I do not propose that just "i" or "j" is enough to indicate the
imaginary number, no more than just 'd' means the number 1.0d (the
latter is correct way to write a double in Java and in clojure).

That said, I would expect the same result that clojure gives now:

user=> (Math/pow (Math/E (* 2/5 2 Math/PI i)))
java.lang.Exception: Unable to resolve symbol: i in this context
(NO_SOURCE_FILE:4)

If you use: 1.0i

user=> (Math/pow (Math/E (* 2/5 2 Math/PI 1.0i)))
java.lang.IllegalArgumentException: No matching method: E
(NO_SOURCE_FILE:1)

Oops! You have an extra set of parenthesis!

If you meant (Math/pow Math/E (* 2/5 2 Math/PI 1.0i)), then the answer
depends on whether Imaginary extends Number. If it does logical (but
perhaps confusing) answer is:

user=> (Math/pow (Math/E (* 2/5 2 Math/PI 1.0i))
1.0

Why? Because you're forcing java.lang.Math.pow(double, double). Java
will then force the cast of the Imaginary number to a double by
calling doubleValue() on "2.51327412i" which has no real component,
thus, you're finding E^0.0 = 1.0. This is the exact same behavior you
would have in Java if you were working with a custom Complex Java type
which extends Number.

If, however, we choose the route Commons Math chooses (to not extend
Number), we should get something like we get now if we pass a non-
Number type to Math/pow:

user=> (Math/pow Math/E "cat")
java.lang.ClassCastException: java.lang.String cannot be cast to
java.lang.Number (NO_SOURCE_FILE:0)

So, I would expect something like:

user=> (Math/pow Math/E 5i)
java.lang.ClassCastException: clojure.lang.Imaginary cannot be cast to
a java.lang.Number (NO_SOURCE_FILE:0)

To get something useful, one would have to use a library (a standard
clojure math library) which supports the complex type, just as it is
in Java. This seems to be the preferable approach.

Thanks for the skepticism and the question!

-Travis

On Jun 8, 11:03 am, Mike Meyer  wrote:
> On Tue, 8 Jun 2010 10:27:28 -0700 (PDT)
>
> Steven Devijver  wrote:
> > On 8 jun, 16:38, Mike Meyer  > 620...@mired.org> wrote:
>
> > > Why? It isn't supported for rationals or exponents. Or are you
> > > claiming that because we support "3/4" we should also support
>
> > > (* (my-complicated-algo val)/(my-other-complicated-algo exp)
> > >    1/(another-complicated-algo exp2))
>
> > > with similar problems because we support "1e3"?
>
> > What would (Math/pow (Math/E (* 2/5 2 Math/PI i))) return?
>
> Why is this relevant to a discussion of whether or not support for
> complex literals is desirable? All but "i" is involved with the
> semantics of complex values, not the literal.
>
>          --
> Mike Meyer           http://www.mired.org/consulting.html
> Independent Network/Unix/Perforce 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: Complex type in clojure

2010-06-15 Thread Travis Hoffman
I've almost completed a Complex (and Imaginary) basic type in a fork
of clojure. It turns out that it was a bit more effort that I had
originally indicated. I'll save the implementation details for the
clojure-dev group, but here is a quick run-down of the "interface",
such as it is:

1.) Added two classes: clojure.lang.Complex & clojure.lang.Imaginary
(These do not extend Number)
2.) Added and modified the core java code related to the basic
mathematical operations to allow Complex and Imaginary to
s(cr)eamlessly integrate with the existing Number types. You can +, -,
*, / with the existing types.
3.) Comparison operations are not implemented for Complex & Imaginary.
Note: The exception reported is currently a ClassCastException, which
is the default if you try to compare anything that isn't Comparable.

user=> (< "foo" "bar")
java.lang.ClassCastException: java.lang.String cannot be cast to
java.lang.Number (NO_SOURCE_FILE:0)
user=> (< 3i 4i)
java.lang.ClassCastException: clojure.lang.Imaginary cannot be cast to
java.lang.Number (NO_SOURCE_FILE:0)

4.) Added pattern matching for parsing complex numbers in a very
flexible way. You can use any Number type (even ratios!) as the
imaginary and real parts of the Complex and Imaginary numbers. The
formatting of a complex number is natural:
3+4i, 4/5i, 2.12+2/3i, etc. and you can prepend 'i', 'I', 'j' or 'J'
to indicate the imaginary part. As with properly formatted doubles and
floats, there must be no whitespace between the numbers and the '+' or
'-' sign. The '+' or '-' in the format of a complex is not an infixed
operator! :-)
5.) Results of the real and imaginary parts follow Clojure conventions
for producing Ratios:

user=> (/ 6+6i 5)
6/5+6/5i
user=> (/ 6+6i -5)
-6/5-6/5i
user=> (/ 6+6i 5i)
6/5
user=> (/ 6+6i -5i)
-6/5

This is mostly working, but is beta. There are a few known bugs:
1.) Parsing of floats and doubles with sign included in the mantissa
seems to be a bit off.
2.) 44 tests fail when I run 'ant test'
3.) I need to create tests for correctness of operations.

Overall, I would estimate that I'm about 80% done with a error-free
implementation, but the basic behavior of the Complex type works. I've
put somewhere in the neighborhood of 60 hrs into it so far, so it's
been a relatively small effort but I've had to touch some rather
obtuse code.

I'm a n00b with git (but experienced with cvs and svn); I'm still
trying to figure out how to push my local git repository changes to
the fork I created on github. Can anyone help me there?

The fork on git-hub is:

git://github.com/travis-a-hoffman/clojure.git

I created a branch locally "complex_type", and have done git commit -a
with my changes. I can't, however, seem to push my changes back to
github:

~/Projects/HackingClojure/workspace/clojure> git push
fatal: remote error:
  You can't push to git://github.com/travis-a-hoffman/clojure.git
  Use g...@github.com:travis-a-hoffman/clojure.git

Using  the recommended doesn't help:

~/Projects/HackingClojure/workspace/clojure> git push
g...@github.com:travis-a-hoffman/clojure.git
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

Cheers,

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
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: Complex type in clojure

2010-06-16 Thread Travis Hoffman
We Electrical Engineers are quite annoying in this regard, but
historically, there is much variation out there: Python uses "j",
MATLAB accepts i or j. Apache Commons allows the user to specify the
specific character to use, but defaults to "i" I believe. Eventually,
I would suggest this be a localizable field. Please see:

http://en.wikipedia.org/wiki/Imaginary_unit#Alternative_notations

-Travis

On Jun 15, 4:22 pm, James Reeves  wrote:
> On 15 June 2010 23:26, Carson  wrote:
>
> > Sorry I may have missed the reason for this earlier:  What's the
> > reason for allowing both 'i' and 'j' to indicate the imaginary part?
> > Is the intention to also later have 'k' to support quaternions?  Just
> > curious.  Thanks.
>
> "j" is used by electrical engineers to represent the imaginary part of
> a complex number, because "I" has already been taken to mean
> electrical current. Presumably this is the reason.
>
> - 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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


How to derive a protocol from another protocol?

2010-06-18 Thread Travis Hoffman
I'm trying to develop a hierarchy (of sorts) of protocols and I'm
coming at it in from a Java Perspective, which I fully understand
might be my problem. In Java, I would do something like this:

interace A {
  public void aFoo();
}

interface B {
  public void bFoo();
}

interfacece AB extends A, B {
  public void abFoo();
}

Then, I could have some objects that implement A, or B or AB (for
both). I'm trying to accomplish something similar with protocols in
Clojure, but I don't see how to. I would have expected that I could
have done something like (extend-protocol AB A B) to accomplish this.
It seems, however that I have to provide a concrete implementation in
that case.

I see that there is "satsifies?" function which determines if an
instance meets a protocol. Then, to implement the protocol, we use
"extend-protocol". It seems that it would make sense to implement a
protocol with "satisfy-protocol" -- as extend-protocol does now...and
then to use "extend-protocol" to create a new protocol based upon a
simpler protocol.

Can anyone describe the correct approach for extending protocols?

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


Need help getting Snow Leopard, Aquamacs, Clojure, and Slime to work

2010-06-20 Thread Larry Travis
To save my life, I can't get Snow Leopard, Aquamacs, Clojure, and Slime 
to work.  I have installed Aquamacs 2.0, then ELPA, then the packages 
/clojure-mode/, /slime/, and /slime-repl/. (I have also tried to install 
the packages /clojure-test-mode/ and /swank-clojure/, but in each case 
am told "File exists:  /clojure-mode-1.7.1/clojure-mode.el" -- 
apparently indicating that these packages don't install anything not 
already present from the installation of the package /clojure-mode/.)


So far so good. But then when I open a new file, say /foo.clj/ (and 
indeed am presented with a buffer in clojure mode), and do /M-x slime/, 
I get the error message "Symbol's function definition is void: 
define-slime-contrib".  As I understand things, what I should get the 
first time I do /M-x slime/ is something like "Clojure is not 
installed.  Do you want to install it? Yes or No" -- but I don't.


I would surely appreciate it if somebody can tell me what I have failed 
to do or what I am doing wrong.


For what it's worth, when I go through the same series of steps but with 
Carbon Emacs rather than Aquamacs, when I do /M-x slime/, I also get an 
error message but a different one, viz. "Searching for program: No such 
file or directory, lisp".


I hope somebody has an answer for me w.r.t.  Aquamacs, but I will be 
happy if I can get either version of Emacs to work with clojure and slime.


Thanks.

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

Name change proposal for "extend-protocol"

2010-06-21 Thread Travis Hoffman
I notice that there is a "satisfies?" method to determine if something
satisfies a protocol. Also, I see that "extend-protocol" doesn't
actually let one create a protocol which is an extension of another
protocol. Rather, "extend-protocol" really means "implements", in the
Java sense.

When I first learned about this, I found the naming a little confusing
and/or misleading. In my humble opinion, based on my experience, I
would like to propose renaming "extend-protocol" to "satisfy-
protocol", to make the purpose of the "extend-protocol" method clearer
and more consistent with the "satisfies?" method.

Cheers,
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
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: Need help getting Snow Leopard, Aquamacs, Clojure, and Slime to work

2010-06-22 Thread Larry Travis

On 6/21/10 8:07 AM, Joost wrote (shown here as corrected in a 2nd msg):

For core swank-clojure (without the elisp parts), you start a swank
server somewhere (using leiningen or some other script) and connect to
that using slime-connect. This means you need to install swank-
clojure in your clojure project, and can use general  Slime and
clojure-mode in Emacs.
   
Thanks. I'm not sure what you mean by "leiningen" or by a "clojure 
project" (which almost certainly reveals my inexperience with respect to 
clojure installation and/or programming!) but I think I can figure it 
out with some exploration.


  --Larry 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
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: Need help getting Snow Leopard, Aquamacs, Clojure, and Slime to work

2010-06-22 Thread Larry Travis

On 6/21/10 5:31 AM, patrik karlin wrote:

Hello theres a wherry "spartan" screencast on vimeo that install all this with
regular emacshttp://vimeo.com/11844368
   
Thanks.  I'm going to try Joost's advice first and, if that doesn't 
work, I'll study your screencasts -- adapting them to Aquamacs if I can.


  --Larry 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
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: Name change proposal for "extend-protocol"

2010-06-23 Thread Travis Hoffman
Thanks for the clarification Stuart! I think I see how to think about
protocols ... and not as an interface, in the java sense. I think it
makes sense to me now.

 Love your book, btw!

-Travis

On Jun 21, 12:31 pm, Stuart Halloway 
wrote:
> Hi Travis,
>
> The choice of "extend" follows from this reasoning:
>
> (1) Create a protocol. At this point there are no implementations. Protocol 
> functions will fail regardless of arguments passed.
>
> (2) Extend the protocol to a String. The protocol has been *extended* to work 
> with one type, Strings.
>
> The word "implements" would imply that something was happening inside 
> *String*, instead of inside the *protocol*. This is both illegal (in Java), 
> and undesirable: in languages where it is legal, "monkey patching" tends to 
> ruin namespaces.
>
> I agree that the terminology is unfamiliar, but it has to be:  the familiar 
> word "implement" suggests exactly the wrong thing.
>
> satisfies? should be used very rarely (people will be tempted to use it write 
> type-tests), so I like the name being distant from extend-protocol, which 
> will be used often.
>
> Stu
>
>
>
> > I notice that there is a "satisfies?" method to determine if something
> > satisfies a protocol. Also, I see that "extend-protocol" doesn't
> > actually let one create a protocol which is an extension of another
> > protocol. Rather, "extend-protocol" really means "implements", in the
> > Java sense.
>
> > When I first learned about this, I found the naming a little confusing
> > and/or misleading. In my humble opinion, based on my experience, I
> > would like to propose renaming "extend-protocol" to "satisfy-
> > protocol", to make the purpose of the "extend-protocol" method clearer
> > and more consistent with the "satisfies?" method.
>
> > Cheers,
> > 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
> > 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: Need help getting Snow Leopard, Aquamacs, Clojure, and Slime to work

2010-06-23 Thread Larry Travis
Thanks again.  I have to be away from home and my iMac for the next ten 
days so it will be some time before I can work through your suggestions, 
but I will certainly give them a try. I'll let you know what kind of 
success I have.  I very much appreciate your help.

 --Larry Travis

Joost wrote:

On Jun 22, 7:36 am, Larry Travis  wrote:
  

Thanks. I'm not sure what you mean by "leiningen" or by a "clojure
project" (which almost certainly reveals my inexperience with respect to
clojure installation and/or programming!) but I think I can figure it
out with some exploration.



Leinging is a build/dependencies tool for clojure that should make it
fairly easy to include swank-clojure in your project (I mean, clojure
program).

But really, all you need is swank.swank and the rest of the .clj code
from swank-clojure in your class path, and some code like this:

(ns your-namespace
  (:require [swank.swank]))

(defn run-swank []
  (swank.swank/start-repl 4005 :host "localhost"))

Calling (your-namespace/run-swank) will start a server that you can
connect to with M-x slime-connect from Emacs.

HTH,
Joost.

  


--
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: SAFETY CRITICAL SOFTWARE

2010-07-12 Thread Travis Hoffman
I think the first, most important, step is to identify a JVM which is
designed for safety critical systems. The only JVM I know of that has
even bothered to consider SC Java is Atego's (formerly Aonix)
UltraPERC, and I don't think they've qualified it to the level you
seek.

To get qualified for Safety Critical, you need to strip a lot of what
Java is to remove the uncertainty in execution (namely multi-threading
and garbage collection). For Clojure to achieve that would require top-
to-bottom redesign and rewrite, and likely would have to directly
compile to machine code. It would have to lose many of the dynamic
typing features that make it what it is.

Basically, there's no way for Clojure to be Safety Critical.

Sorry!

-Travis

On Jul 11, 8:59 pm, lprefonta...@softaddicts.ca wrote:
> Hmm.. I would give it a try for a critical app.
> We have sever apps in Clojure running for months non-stop now without
> unscheduled down time. Clojure has not been a source of problems, we
> had more problems with the customer networks and other site specific
> conditions.
>
> We run redundant components by up to now it's been mostly used to safely
> upgrade the system while it's running or cope with the bad network conditions
> mentioned above.
>
> However meeting a paper certification is a significant process and
> has nothing to do with the "readiness" of the language itself.
> Clojure runs on the JVM (or CLR) it certainly has an impact on the
> certification. If I remember Sun had some disclaimers about what
> Java and the JVM should be used for.
>
> I would certainly board on a plane with computers running Clojure on
> properly tuned environments.
> Of course the wings may still fall apart :
>
> Luc P.
>
> Neil Mock  wrote ..
>
>
>
> > call me crazy but I think any organization planning to use clojure as such 
> > should
> > be able to independently evaluate it's readiness for the proposed task(s).
>
> > On Jul 10, 2010, at 10:55 PM, David Blubaugh  
> > wrote:
>
> > > To All,
>
> > > I was wondering if it was possible to utilize Clojure for safety
> > > critical software development.  This would include development for
> > > guidelines within both DO-178B level A and DO-254 certification.  I am
> > > also wondering if it was possible to utilize Clojure for space-borne
> > > applications??  Also is it possible to utilize Clojure for programming
> > > microcontrollers??
>
> > > Thanks,
>
> > > David Blubaugh
>
> > > --
> > > 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

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


Confusing compiler error in defrecord and deftype.

2010-07-20 Thread Travis Hoffman
Hello, I've come across the following compiler error in defrecord and
deftype:

java.lang.RuntimeException: java.lang.ClassCastException:
clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol
(test.clj:0)

To generate the error, evaluate the following code:

(ns test)

(defrecord TestRecord [afield bfield cfield]
  (printc [_] (println cfield)))

(deftype TestType [afield bfield cfield]
  (printc [_] (println cfield)))

The error I believe I should be getting is something like this:

java.lang.IllegalArgumentException: Can't define method not in
interfaces: printc (test.clj:8)

Which can be generated with the following code:

(ns test)

(defprotocol TestProtocol
  ""
  (printa [testtype] "")
  (printb [testtype] ""))

(defrecord TestRecord [afield bfield cfield]
  TestProtocol
(printa [_] (println afield))
(printb [_] (println bfield))
(printc [_] (println cfield)))

(deftype TestType [afield bfield cfield]
  TestProtocol
(printa [_] (println afield))
(printb [_] (println bfield))
(printc [_] (println cfield)))

I haven't found, on Assembla, to submit a ticket, otherwise I would
have done so. :-)

Cheers,
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
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: Complex type in clojure

2010-07-21 Thread Travis Hoffman
I'm still working on it. I've been waiting for the 1.2 release to
branch, and also for the other work on the basic types to settle down.
Also, I need a little free time. I'll try to get back to it this week.

-Travis

On Jul 20, 11:09 am, Mike Benfield  wrote:
> The lack of complex numbers is keeping me on the fence about Clojure.
> I could (and partially have) implement them in Clojure itself, but
> this is not as satisfying as having them built in with reader syntax
> and so on. I don't have the will right now to learn enough about
> Clojure internals and how to contribute to do that.
>
> It's quite strange to me that after 15 years and with all the gunk in
> Java's libraries, Java doesn't come with complex numbers.
>
> Anyway, I just wondered if anyone is still working on this?
>
> Mike

-- 
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: Complex type in clojure

2010-07-21 Thread Travis Hoffman
I'm still working on it. I was waiting for 1.2 to branch, and to for
some other changes to the basic types to happen. Really, I just need a
little free time and a kick-in-the-pants!

I'll try to get it done this week.

-Travis

On Jul 20, 11:09 am, Mike Benfield  wrote:
> The lack of complex numbers is keeping me on the fence about Clojure.
> I could (and partially have) implement them in Clojure itself, but
> this is not as satisfying as having them built in with reader syntax
> and so on. I don't have the will right now to learn enough about
> Clojure internals and how to contribute to do that.
>
> It's quite strange to me that after 15 years and with all the gunk in
> Java's libraries, Java doesn't come with complex numbers.
>
> Anyway, I just wondered if anyone is still working on this?
>
> Mike

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


Two convenience methods

2010-07-21 Thread Travis Hoffman
I've found two convenience methods to be of use to me in my project,
and I'm not certain where I ought to share them. So, I thought I'd
share them here, for your consideration. Sorry, I'm a bit of a n00b to
Clojure. :-)

The first I would suggest for inclusion in core.clj; it is very
similar in behavior to "some", but returns a boolean like "every?".

(defn any?
  "Returns true if (pred x) is logically true for one x in coll, else
false."
  {:added "1.3" :tag Boolean}
  [pred coll]
  (when (seq coll)
(or (pred (first coll)) (recur pred (next coll)

The second function is suggested as an addition to clojure.set. The
"disjoint?" function decides if two sets have no elements in common.
This can easily be done using:

  (not (nil? (intersection s1 s2)))

but this implementation should be more efficient (I think) and is more
readable, imho:

(defn disjoint?
  "Is set1 disjoint from set2?"
  {:added "1.3" :tag Boolean}
  [set1 set2]
  (if (<= (count set1) (count set2))
(recur set2 set1)
(not-any? (fn [item] (contains? item set1)) set2)))

Feel free to use these, or, how best should I submit these?

Cheers,
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
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: Two convenience methods

2010-07-22 Thread Travis Hoffman
*sigh* ... it was a typo. Good catch!

On Jul 21, 10:16 pm, B Smith-Mannschott  wrote:
> On Wed, Jul 21, 2010 at 23:45, Travis Hoffman 
> wrote:
>
> ...
>
>
>
>
>
> > The second function is suggested as an addition to clojure.set. The
> > "disjoint?" function decides if two sets have no elements in common.
> > This can easily be done using:
>
> >  (not (nil? (intersection s1 s2)))
>
> > but this implementation should be more efficient (I think) and is more
> > readable, imho:
>
> > (defn disjoint?
> >  "Is set1 disjoint from set2?"
> >  {:added "1.3" :tag Boolean}
> >  [set1 set2]
> >  (if (<= (count set1) (count set2))
> >    (recur set2 set1)
> >    (not-any? (fn [item] (contains? item set1)) set2)))
>
> so, when set1 and set2 are the same size, we recur, swapping the order
> of the two arguments, which means set2 and set1 are the same size, so
> we recur, swapping the two arguments, which means ...
>
>   (if (< (count set1) (count set2))
>     (recur set2 set1)
>     ...)
>
> would be better, no?
>
> // ben

-- 
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: Two convenience methods

2010-07-22 Thread Travis Hoffman
Frederick,

I agree with all you said; perhaps this is as much my personal coding
style. Also, I'm seeing Clojure through beginner's eyes. What I love
about Clojure is the readability and the "naturalness" of the names of
functions.

While skimming the API, I was looking for the natural opposite of (not-
any? pred coll) function. My initial though was, "Aha! There must be a
function (any? pred coll)". That only seems "natural" to me, since
there is both (every? pred coll) and (not-every? pred coll). It took
me quite a bit of searching to realize that (some pred coll) does what
I need. So, to me, (any? pred coll), just seems natural, even if it is
little more than sugar.

Also, comparing these two statements:

(disjoint? s1 s2)
(empty? (intersection s1 s2))

To me, the simpler the better, and therefore the more readable. So,
again, personally, I find the former to be easier, simpler, more
direct and to the point.

Thanks for the link too!

Cheers,

-Travis

On Jul 21, 6:14 pm, Frederick Polgardy  wrote:
> Oops, you already said that, my bad. :)
>
> --
> Science answers questions; philosophy questions answers.
>
> On Jul 21, 2010, at 8:13 PM, Frederick Polgardy wrote:
>
>
>
> > Or [using clojure.set] (empty? (intersection s1 s2)).
>
> > --
> > Science answers questions; philosophy questions answers.
>
> > On Jul 21, 2010, at 4:45 PM, Travis Hoffman wrote:
>
> >> The second function is suggested as an addition to clojure.set. The
> >> "disjoint?" function decides if two sets have no elements in common.
> >> This can easily be done using:
>
> >> (not (nil? (intersection s1 s2)))
>
> >> but this implementation should be more efficient (I think) and is more
> >> readable, imho:
>
> >> (defn disjoint?
> >> "Is set1 disjoint from set2?"
> >> {:added "1.3" :tag Boolean}
> >> [set1 set2]
> >> (if (<= (count set1) (count set2))
> >>   (recur set2 set1)
> >>   (not-any? (fn [item] (contains? item set1)) set2)))

-- 
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: A newbie's summary - what worked, what didn't

2011-03-28 Thread Larry Travis

Kasim:
I just discovered ClojureW, and it looks promising. I will report my 
reaction after I get time to thoroughly test it for the kinds of things 
I am doing.


In the meantime, a request:

When you work 'on a "Just Works" emacs setup' for Mac Os X consider 
whether you can create such a setup for the Aquamacs version of emacs 
that many of us Mac Os X users prefer (because it gives us the power and 
versatility of emacs without having to learn dozens of non-obvious key 
chords).


Thanks.

  --Larry





On 3/28/11 12:46 AM, Kasim wrote:

Hi,

I am the guy who did ClojureW. I just updated the instruction to get a 
REPL with Jline. Thank you for reporting. I am also working on a "Just 
Works" emacs setup for all platforms and would be happy to hear your 
opinion. I really want to make it as simple as ClojureW.


Have fun,

Kasim

 


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

possible bug in cl-format (rounding floating-point number)

2011-06-02 Thread Travis Treseder
I didn't see this as an open issue on the JIRA bug list, so I thought
I would ask about it here.

> (cl-format nil "~,5f" -434343.867071)
"-434343.86707"
> (cl-format nil "~,5f" -434343.867072)
"-434343.86707"
> (cl-format nil "~,5f" -434343.867075)

For input string: "43434386707"
  [Thrown class java.lang.NumberFormatException]

Backtrace:
  0: 
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
  1: java.lang.Integer.parseInt(Integer.java:461)
  2: java.lang.Integer.valueOf(Integer.java:554)
  3: clojure.pprint$round_str.invoke(cl_format.clj:585)


After looking at the round-str function, it appears that if round-char
>= 5, then result is parsed by Integer.valueOf(result), which causes
an exception if result is too large.  I rewrote part of it to use
BigInteger, and it seemed to fix the problem, but I didn't test it
extensively.  It might be a valid solution in any case.

Incidentally, I love using clojure.pprint.  It's powerful, and after
diving into the CLM spec I have new appreciation for the daunting task
it must be to test it.

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


can't set up Clojure 1.2.1

2011-07-14 Thread Larry Travis
I need to upgrade from the older version of Clojure I have been using so 
I downloaded Version 1.2.1 and followed these instructions from 
http://clojure.org/getting_started:


In the directory in which you expanded clojure.zip, run:

java -cp clojure.jar clojure.main

This will bring up a simple read-eval-print loop (REPL).

==
But this is what I get:

bash-3.2$ java -cp clojure.jar clojure.main
Exception in thread "main" java.lang.NoClassDefFoundError: clojure/main
Caused by: java.lang.ClassNotFoundException: clojure.main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)



I don't know how to find my way around in the Java world. What should I 
do differently?


Thanks for your help.

  --Larry

--
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: can't set up Clojure 1.2.1

2011-07-14 Thread Larry Travis

Jonathan:
Thanks.  When the instructions said "the directory in which you expanded 
clojure.zip" I took that to mean the directory I was in when I expanded 
clojure.zip, not the directory that was created to hold the zip-file 
contents.

  --Larry

On 7/14/11 10:05 PM, Jonathan Cardoso wrote:

Weird =S.

That only happens when you're not on the folder containing the 
clojure.jar or when you try to call clojure from a different folder 
without setting the classpath.

--
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: can't set up Clojure 1.2.1

2011-07-15 Thread Larry Travis
Thanks, Sergey.  The problem was indeed a classpath problem. The part of 
my ignorance about Java that seems to cause me the most trouble is my 
ignorance about Java classpaths. I think some Clojurians underestimate 
the difficulties involved in learning Clojure without knowing Java 
first.  I wish that the Clojure books available, most of which are quite 
excellent otherwise, did not assume a previous knowledge of Java on the 
reader's part but included an early section covering what it is 
essential to know about Java and the JVM before one can fully understand 
Clojure and become proficient in it.


Of course, the best response to such a criticism is "Don't just 
criticize. Write such a book." It will be a while before I know enough 
to do so!

  --Larry

On 7/15/11 9:16 AM, Sergey Didenko wrote:
Larry, it seems that the current folder "." is not in your default 
classpath. Either try "...-cp ./clojure.jar ..." or add "." into your 
default CLASSPATH.



--
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: can't set up Clojure 1.2.1

2011-07-16 Thread Larry Travis

Phil:
You ask whether, if I had found it, the following web page would have 
helped:


http://dev.clojure.org/display/doc/Getting+Started+with+Emacs

The answer: Definitely yes.

The page advises me to use for bringing up a Clojure REPL

java -cp path/to/clojure.jar clojure.main

whereas the page

http://clojure.org/getting_started

advises

java -cp clojure.jar clojure.main

I followed the latter advice blindly because I didn't know what "-cp" 
was doing.


What I have now done is follow the Confluence advice for setting the 
value of the Aquamacs variable 'inferior-lisp-program, and so far things 
are working well. Some time soon I want to set up a Slime plus Swank 
Clojure plus Leiningen environment instead, but right now I prefer to 
spend the time I have for such things digging deeper into Clojure proper.


By the way, I don't want to come across as unhappy with Clojure and 
Clojurians.  Starting with the creation of the language itself, I very 
much appreciate what you guys have done and are doing, and I predict 
that that creation and the subsequent evolution of the language will 
ultimately go down as a major development in the history of computer 
science -- at least, for the very important areas of programming 
multi-processor systems and of experimental programming (so important, 
for example, for artificial intelligence research).

  --Larry


On 7/16/11 10:10 AM, Phil Hagelberg wrote:

On Fri, Jul 15, 2011 at 11:29 PM, Larry Travis  wrote:

Thanks, Sergey.  The problem was indeed a classpath problem. The part of my
ignorance about Java that seems to cause me the most trouble is my ignorance
about Java classpaths. I think some Clojurians underestimate the
difficulties involved in learning Clojure without knowing Java first.

I updated the Confluence getting started page to address this last week:

 Clojure is unlike most language in that you don't generally install Clojure
 itself; it's just a library that's loaded into the JVM. You don't
interact with
 it directly, you use a build tool and editor/IDE integration instead.

 * IDEs and Editors
   [...]
* Build Tools
   [...]

http://dev.clojure.org/display/doc/Getting+Started

Would this have helped if you had found it? Using the jar file
directly is really not very common or convenient which is why it's not
well-documented, but people coming from other languages naturally
assume that the first step is to "install Clojure".

It's unfortunate that the Getting Started page on clojure.org is in
such an embarrassing state of disarray, but according to Clojure Core
they can't spare any resources to fix it at the present time. The
community-editable pages are generally much more helpful, but they
aren't as prominent or easy to find.

-Phil



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: What's the efficient functional way to computing the average of a sequence of numbers?

2012-03-30 Thread Larry Travis
I too think this is interesting because because it serves to illustrate 
some important general aspects of Clojure with a very simple problem.


I wrote four Clojure programs contrasting different ways of solving the 
problem, and then timed the application of each ten times to a 
million-item sequence /mill-float-numbs/ of floating-point random 
numbers.  Here are the interesting results:


(defn average1
  [seq1]
  (/ (reduce + seq1) (count seq1)))

(defn average2
  [seq1]
  (loop [remaining (rest seq1)
cnt 1
accum (first seq1)]
(if (empty? remaining)
  (/ accum cnt)
  (recur (rest remaining)
(inc cnt)
(+ (first remaining) accum)

(defn average3
  [seq1]
  (letfn [(count-add
 [ [cnt accum] numb]
 [(inc cnt) (+ accum numb)] ) ]
(let [result-couple (reduce count-add [0 0] seq1)]
  (/ (result-couple 1) (result-couple 0)

(defn average4
  [seq1]
(let [result-couple (reduce
  (fn [ [cnt accum] numb]
[(inc cnt) (+ accum numb)] )
  [0 0]
  seq1)]
  (/ (result-couple 1) (result-couple 0

user=> (time (dotimes [i 10] (average1 /mill-float-numbs/)))
"Elapsed time: 526.674 msecs"

user=> (time (dotimes [i 10] (average2 /mill-float-numbs/)))
"Elapsed time: 646.608 msecs"

user=> (time (dotimes [i 10] (average3 /mill-float-numbs/)))
"Elapsed time: 405.484 msecs"

user=> (time (dotimes [i 10] (average4 /mill-float-numbs/)))
"Elapsed time: 394.31 msecs"

  --Larry

On 3/30/12 1:31 AM, Benjamin Peter wrote:

I think this topic is interesting. My guess would be, that the
sequence would have been traversed completely by the reduce call and
therefore clojure could know it's size and provide a constant time
count.

Could this be implemented? Is it?


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Leiningen-noobie question

2012-04-28 Thread Larry Travis
I have installed Leiningen not so much to manage projects but to enable 
use of /clojure-jack-in/ as a means of getting Swank and Slime to work.  
And they do work for me.  But now I have a question that I can't find an 
answer for in any  Leiningen documentation I know about. I have a 
largish, previously created group of /clj/ local files that exist on my 
system and whose function definitions I want to use in my further work.  
Is there a way to specify such local files in a project :dependencies 
declaration -- or do I have to do a /load-file/ on each of them once I 
get a Slime REPL running for the project (or maybe insert them all into 
the /src/core.clj/ file of the project and do a single /load-file/ on it)?


That question is surely complicated enough to indicate how badly 
confused I am! Thanks for help.

  --Larry


--
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: Leiningen-noobie question

2012-04-28 Thread Larry Travis

Sean,
Your advice makes good sense, but I can't make it work. Per that advice, 
I paste some of my function definitions into the core.clj file of the 
project "prjctOne" and proceed thusly:


larrytravis$ lein install
Copying 1 file to /Users/larrytravis/prjctOne/lib
No namespaces to :aot compile listed in project.clj.
Created /Users/larrytravis/prjctOne/prjctOne-1.0.0-SNAPSHOT.jar
Wrote pom.xml
[INFO] Installing 
/Users/larrytravis/prjctOne/prjctOne-1.0.0-SNAPSHOT.jar to 
/Users/larrytravis/.m2/repository/prjctOne/prjctOne/1.0.0-SNAPSHOT/prjctOne-1.0.0-SNAPSHOT.jar


But when I create a new project prjctTwo, I can't figure out what 
dependency declaration for it gives a prjctTwo Slime REPL access to the 
functions in prjctOne.  That is, what would correspond to the [utilities 
"0.0.1-SNAPSHOT"] vector in your example?

  --Larry

On 4/28/12 4:46 AM, Sean Corfield wrote:

On Sat, Apr 28, 2012 at 12:21 AM, Larry Travis  wrote:

I have installed Leiningen not so much to manage projects but to enable use
of clojure-jack-in as a means of getting Swank and Slime to work.  And they
do work for me.  But now I have a question that I can't find an answer for
in any  Leiningen documentation I know about. I have a largish, previously
created group of clj local files that exist on my system and whose function
definitions I want to use in my further work.  Is there a way to specify
such local files in a project :dependencies declaration -- or do I have to
do a load-file on each of them once I get a Slime REPL running for the
project (or maybe insert them all into the src/core.clj file of the project
and do a single load-file on it)?

Once possibility is to put all those files into a project together,
let's called it utilities and assume it has a 0.0.1-SNAPSHOT version.

Then you can run 'lein install' and it'll package them up and put them
in your local repository.

Then, wherever you want to use them in another project, just declare a
dependency on [utilities "0.0.1-SNAPSHOT"] and Leiningen will
automatically pull them in (from your local repo).

Then you just use/require the namespace(s) containing the relevant functions.

Does that help?


--
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: Leiningen-noobie question

2012-04-28 Thread Larry Travis

Sean:
Your suggestion doesn't work.  The Slime REPL comes up fine when I use 
the dependency vector you suggest (some of the vectors I have tried 
prevent the Swank server from starting), but the REPL doesn't know 
anything about the functions defined in prjctOne or about the name-space 
in which they exist.


So I guess for the nonce I'll just use load-file commands in the Slime 
REPL to make use of my local stash of clj files, and I'll worry some 
time later about getting Leiningen to construct dependencies on those 
files.  I'd rather spend my time on getting my programs to work than on 
getting my programming environment to work.


If you get any more ideas about how I might try to solve my problem, let 
me know.  Thanks.

  --Larry

On 4/28/12 5:07 PM, Sean Corfield wrote:

On Sat, Apr 28, 2012 at 2:41 PM, Larry Travis  wrote:

  That is, what would correspond to the [utilities
"0.0.1-SNAPSHOT"] vector in your example?

Try [prjctOne "1.0.0-SNAPSHOT"]


--
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: Leiningen-noobie question

2012-04-28 Thread Larry Travis

Neale:
Indeed, that's exactly the dependency vector I needed.  I'm impressed by 
your expertise. Thanks very much to both you and Sean.

  --Larry


On 4/28/12 7:01 PM, Neale Swinnerton wrote:

leiningen relies on maven dependency resolution...

the dependency entry is of the form

[groupId/artifactId "version"]

You have the groupId and the artifactId both set to prjctOne. You can 
tell this from the path it's installed into your local repo. I believe 
this is default behaviour if you specify a simple project name in 
project.clj (i.e one without a /)


This is the key entry in your logging:

[INFO] Installing 
/Users/larrytravis/prjctOne/prjctOne-1.0.0-SNAPSHOT.jar to 
/Users/larrytravis/.m2/repository/prjctOne/prjctOne/1.0.0-SNAPSHOT/prjctOne-1.0.0-SNAPSHOT.jar


So you need...

[prjctOne/prjctOne "1.0.0-SNAPSHOT"]

Neale
{t: @sw1nn <https://twitter.com/#%21/sw1nn>, w: sw1nn.com 
<http://sw1nn.com/> }




On Sun, Apr 29, 2012 at 12:42 AM, Larry Travis <mailto:tra...@cs.wisc.edu>> wrote:


Sean:
Your suggestion doesn't work.  The Slime REPL comes up fine when I
use the dependency vector you suggest (some of the vectors I have
tried prevent the Swank server from starting), but the REPL
doesn't know anything about the functions defined in prjctOne or
about the name-space in which they exist.

So I guess for the nonce I'll just use load-file commands in the
Slime REPL to make use of my local stash of clj files, and I'll
worry some time later about getting Leiningen to construct
dependencies on those files.  I'd rather spend my time on getting
my programs to work than on getting my programming environment to
work.

If you get any more ideas about how I might try to solve my
problem, let me know.  Thanks.
 --Larry


On 4/28/12 5:07 PM, Sean Corfield wrote:

On Sat, Apr 28, 2012 at 2:41 PM, Larry
Travismailto:tra...@cs.wisc.edu>>  wrote:

 That is, what would correspond to the [utilities

"0.0.1-SNAPSHOT"] vector in your example?

Try [prjctOne "1.0.0-SNAPSHOT"]


-- 
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
<mailto: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
<mailto:clojure%2bunsubscr...@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

ClassCastException clojure.lang.Var$Unbound Help

2012-04-30 Thread Travis Smith
What does 'java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be 
cast to clojure.lang.IDeref' mean. I'm getting this a lot and I want to 
understand it better, make it easier for me to avoid this. Most of the time 
I just end up adjusting my def/defn's around until it works. This is hardly 
optimal. 

(this is all on clojure 1.3.0)

An example...

(ns app-admin.models.current-user
  (:require [noir.session :as session]
[app-admin.models.users :as users]))

(def get-id
  (session/get :uid))

(defn set-user! [user] 
  (session/put! :uid {:_id user}))

Give me an exception for get-id

ClassCastException clojure.lang.Var$Unbound cannot be cast to 
clojure.lang.IDeref  clojure.core/deref (core.clj:2078)

So set-user! binds correctly, but get-id doesn't seem to...

=> (get-id)
llegalStateException Attempting to call unbound fn: 
#'app-admin.models.current-user/get-id  clojure.lang.Var$Unbound.throwArity 
(Var.java:43)

Then I check it...

=> (meta #'get-id)
{:ns #, :name get-id}

So it's there, the fn is bound; I'm not exactly sure what's going on and 
nor what I'm missing about how this works to help me avoid problems like 
this in future. Just guessing and tweaking has gotten me so far, but that's 
not sustainable. 

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
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: ClassCastException clojure.lang.Var$Unbound Help

2012-04-30 Thread Travis Smith
Thank you for your responses. This was failing for me in the Noir server, 
so I assumed the same error meant the same thing in the REPL. Something was 
different though, changing it to (defn get-id ...) and a couple other minor 
tweaks and it's working. 

On Monday, April 30, 2012 9:31:17 PM UTC-4, Stuart Campbell wrote:
>
> Hi Travis, 
>
>> (def get-id
>>   (session/get :uid))
>>
>> (defn set-user! [user] 
>>   (session/put! :uid {:_id user}))
>>
> Only set-user! is a function here. The value of get-id is evaluated at 
> compile-time.
>
> I don't know about the implementation of noir.session/get, but the error 
> message suggests that it uses some dynamic var that is unbound at 
> compile-time. That makes sense since you couldn't reference a session 
> without an associated request.
>
> Changing get-id to something like:
>
> (defn get-id []
>   (session/get :uid))
>
> will probably do what you expect.
>
> => (meta #'get-id)
>> {:ns #, :name get-id}
>>
>> So it's there, the fn is bound [...]
>>
>
> Actually no, you're looking up the metadata on the var, not the value. 
> Observe the following:
>
> user> (def foo)
> #'user/foo
> user> foo
> #
> user> (meta #'foo)
> {:ns #, :name foo, :line 1, :file "NO_SOURCE_FILE"}
>
> See also http://clojure.org/vars
>
> Regards,
> Stuart 
>

-- 
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: Leiningen-noobie question

2012-04-30 Thread Larry Travis

Phil, Neale, Sean:
You guys are all way ahead of me as to why I am getting the results I am 
getting, but it is only Neale's advice that works.  That is


[prjctOne/prjctOne "1.0.0-SNAPSHOT"]   works, but


[prjctOne "1.0.0-SNAPSHOT"]  does not.

  --Larry


On 4/30/12 11:14 AM, Phil Hagelberg wrote:

Neale Swinnerton  writes:


So you need...

[prjctOne/prjctOne "1.0.0-SNAPSHOT"]

Actually this is incorrect; you never need to specify the group ID if
it's the same as the artifact ID.

-Phil



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Leiningen-noobie question

2012-05-02 Thread Larry Travis

Phil:
I now can't get the behavior to reproduce either.  I have no idea what 
kind of dumb mistake I was making in the first place, and I'm very sorry 
to have wasted your time. (For what it's worth, both dependency-vector 
versions work in my reproduction attempts -- but you probably already 
knew that they would!)

  --Larry




On 5/1/12 11:22 AM, Phil Hagelberg wrote:

On Mon, Apr 30, 2012 at 9:28 PM, Larry Travis  wrote:

Phil, Neale, Sean:
You guys are all way ahead of me as to why I am getting the results I am
getting, but it is only Neale's advice that works.  That is

[prjctOne/prjctOne "1.0.0-SNAPSHOT"]   works, but


[prjctOne "1.0.0-SNAPSHOT"]  does not.

Interesting. I've never seen that behaviour before; it sounds like a bug.

I'm trying to reproduce this problem here but am unable to. Can you
provide steps to reproduce it locally? What version of Leiningen is
this?

-Phil



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Why doesn't doc work in clojure-jack-in slime-repl?

2012-05-04 Thread Larry Travis

A command like

user> (doc hash-map)

in the slime-repl created by clojure-jack-in

results in

Unable to resolve symbol: doc in this context
  [Thrown class java.lang.RuntimeException]

Can this be fixed or do I have to do my doc requests someplace else?

  --Larry


--
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: Why doesn't doc work in clojure-jack-in slime-repl?

2012-05-04 Thread Larry Travis

Thank you, Roberto.  Works like a charm.
  --Larry

On 5/4/12 2:32 PM, Roberto Mannai wrote:

You should "use" it:

user> (use 'clojure.repl)
nil
user> (doc doc)
...


On Fri, May 4, 2012 at 9:27 PM, Larry Travis <mailto:tra...@cs.wisc.edu>> wrote:


A command like

user> (doc hash-map)

in the slime-repl created by clojure-jack-in

results in

Unable to resolve symbol: doc in this context
 [Thrown class java.lang.RuntimeException]

Can this be fixed or do I have to do my doc requests someplace else?

 --Larry


-- 
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
<mailto: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
<mailto:clojure%2bunsubscr...@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 


--
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: Why doesn't doc work in clojure-jack-in slime-repl?

2012-05-04 Thread Larry Travis

Roberto:
This indeed looks like it will be useful. Thanks.

Your require-all-snippet.clj script loaded OK except for:

Attempting to require  clojure.parallel : couldn't require  
clojure.parallel

Exception
 #java.lang.ClassNotFoundException: jsr166y.forkjoin.ParallelArray>


  --Larry


On 5/4/12 3:00 PM, Roberto Mannai wrote:
If you are studying the doc maybe you could find useful this bunch of 
scripts: http://pastebin.com/cXL1wNVC
They are an updated version of what posted here: 
http://www.learningclojure.com/2010/03/conditioning-repl.html





--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Why doesn't doc work in clojure-jack-in slime-repl?

2012-05-04 Thread Larry Travis

Phil:
Thanks.  I obviously need to start doing my Clojure programming with a 
Slime cheatsheet in front of me!

  --Larry

On 5/4/12 4:00 PM, Phil Hagelberg wrote:

Another way to do it is just use C-c C-d C-d for docs lookup.

-Phil



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Best Clojure Learning Resource for Lisper

2012-05-07 Thread Larry Travis

Lee's comments ring true for me so let me extend them.

Before I discovered Clojure, my experience as a programmer had been 
mainly in the area of artificial-intelligence experimental programming.  
I was once a reasonably proficient Lisp programmer, but pre-CL and 
pre-CLOS, that is, mainly using Xerox PARC's Interlisp.


Fast prototyping is central to such experimental programming, and Lisp  
REPL's and IDE's have contributed as much to Lisp's pre-eminent 
usability for experimental programming as has the language itself.


So, when starting to use Clojure, my major frustrations were wrt Java 
interop and (to quote Lee) "... setup, editing environments, build tools 
and configurations, dependencies, classpaths, etc."


What I found of most use to begin with was Clojure Box (see 
http://clojure.bighugh.com), " an all-in-one installer for Clojure 
 on Windows. It's inspired by the Lispbox 
: you simply install and run this 
one thing, and you get a REPL  and all the 
syntax highlighting and editing goodies from clojure-mode and Slime, 
plus all the power of Emacs under the hood." Unfortunately, it has not 
been upgraded to Clojure 1.3.0 and is no longer being maintained -- and, 
anyway, I wanted to work on a Mac.


And something almost as good as Clojure Box is now available for Macs 
(as well as for Windows and Linux systems). See


https://github.com/technomancy/swank-clojure/blob/master/README.md

If you are not into the intricacies of Emacs multi-key chording, using 
Aquamacs helps a bit. (Despite the statement in the README that 
"Swank-clojure and SLIME are only tested with GNU Emacs; forks such as 
Aquamacs  ... are not officially supported", use of the Aquamacs Emacs 
fork does work.)


I agree with Lee that, if you don't know Emacs (or don't want to be 
learning it at the same time you are learning Clojure), the clooj IDE 
should be useful as a starter -- maybe eventually something more as 
features like SLIME's debugging aids are added to it.


There are several excellent books useful as Clojure learning aids. (I 
particularly recommend Halloway and Bedra, "Programming Clojure"; Fogus 
and Hauser, "The Joy of Clojure"; and Emerick, Carper, and Grand, 
"Clojure Programming".) Unfortunately, none of them contain a chapter 
that has yet to be written by somebody: "Everything a Clojure programmer 
who has never used Java needs to know about it."


I hope this helps.
  --Larry




On 5/7/12 9:34 AM, Lee Spector wrote:


On May 7, 2012, at 12:37 AM, HelmutKian wrote:


Hey there,

I'm a fairly experienced Common Lisp programmer.  By that I mean I've read PAIP, On Lisp, 
Let Over Lambda, and written several "real world" CL applications and taught 
the principles of FP using Racket as a TA.

Now I'm looking to learn Clojure. What would be the best resource for someone 
who is already pretty comfortable with Lisp?

For me, coming to Clojure ore from Common Lisp and Scheme than from Java, the biggest 
hurdles weren't the language itself but rather the issues with setup, editing 
environments, build tools and configurations, dependencies, classpaths, etc. Many of the 
concepts underlying these things were foreign to me, at least in their Java-world guises. 
If any of this rings true to you then I'd recommend starting with the clooj lightweight 
IDE, which makes a lot of these issues go away (for me at least), in conjunction with 
leiningen (invoked from the command line after adding dependencies to your project.clj) 
to manage dependencies. You can get clooj here: https://github.com/arthuredelstein/clooj 
-- I'd download the latest "standalone" jar, double click it to launch the IDE, 
create a project, and begin working there. If you do your Lisping in emacs then there's 
great support for that route in Clojure too, and maybe that's where you want to end up, 
but I (and others) have found setup and configuration to be nontrivial. Doubtless others 
on this list will disagree with that :-), and of course YMMV, but that's my 2cents.

On the language itself I recommend watching Rich Hickey's "Clojure for Lisp Programmers" 
talk (part 1 is here: http://blip.tv/clojure/clojure-for-lisp-programmers-part-1-1319721) for 
starters. After that I personally used Stuart Halloway's "Programming Clojure" text but 
there are now several others that are also good.

  -Lee



--
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: Best Clojure Learning Resource for Lisper

2012-05-07 Thread Larry Travis

Sean and Lee:
In general, I have considered the difference between Aquamacs and GNU 
Emacs to be that the former prioritizes computer-user interaction via 
mouse, command-bars and menus (which requires a lot of hand movement 
between keyboard and mouse, but enables the user to dispense with 
memorizing the meanings of dozens of key chords) -- while the latter 
minimizes user need to move hands off the keyboard thus facilitating 
fast touch typing (using key combinations to move point, set mark, copy 
region, etc.)


Whether key bindings (especially those that involve the Apple command 
key) conform to Apple style helps if you are used to them from other Mac 
applications, but is a secondary difference. By the way, I can't find 
just what bindings to the command key Emacs 24 (for Os X) does use. 
(Aquamacs comes with 41!) The Emacs-24 _C-h b_ listing doesn't seem to 
show them.


A difference that I find very useful is the use of tabs in Aquamacs for 
rapidly controlling which buffers are being displayed. (One can create a 
new buffer either in a new frame or under a new tab in an existing frame.)


There are other differences, but none of the differences between 
Aquamacs and GNU Emacs (including the ones just mentioned) are critical 
to what makes a good Emacs-based Clojure IDE, and I will be perfectly 
happy with either Aquamacs or GNU Emacs as the base of a "Mac Clojure 
Box" downloadable as are many Mac applications (from the Mac Apps 
Store?) and installable simply by dragging an icon into the applications 
folder.


Talk about being a parasitic noobie.  I wish I had the expertise to help 
Phil Hagelberg and other swank-clojure and Leiningen contributors toward 
achieving this goal.  What they have developed so far takes us a long 
way toward it  (whether or not it is one of the goals they have 
explicitly in mind).

  --Larry




On 5/7/12 10:40 PM, Sean Corfield wrote:

On Mon, May 7, 2012 at 8:21 PM, Lee Spector  wrote:

My recollection was that Aquamacs had more support for Mac OS native menus and 
other GUI elements too...

Probably, yes. I installed it last year and I seem to recall some
native chrome and a menubar - but then folks recommended using Emacs
24 so I switched and haven't had any problems. I expand Emacs to
near-fullscreen and I like the lack of distractions (lack of chrome)
since I work in it all day.


What I should have said would be "really wonderful," more precisely, is something with 
"close to single click download/install of a complete [emacs] Clojure programming 
environment"

That's certainly true. Any Emacs-based approach is a multi-step setup
right now and everyone seems to have their own favorite way to set
things up. I've helped a number of Mac users get Emacs 24 + Starter
Kit + Leiningen + Swank-Clojure up and running and I always seem to
forget some minor step and have to redo _something_ :)


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

How do I set jvm options for a lein repl

2012-05-20 Thread Larry Travis
How do I set jvm options for a /lein repl/ initiated independently of a 
project?   In particular, I want the heap expansion that results from 
doing "M-x clojure-jack-in" in an emacs /project.clj/ buffer with 
":jvm-opts [ "-Xms4G" "-Xmx4G"]" in its defproject form.

  --Larry

--
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 do I set jvm options for a lein repl

2012-05-21 Thread Larry Travis
I should be switching over to Leiningen 2 shortly in any case, but I am 
curious. How does one "set JVM_OPTS as an environment variable"?

  --Larry


On 5/21/12 11:42 AM, Phil Hagelberg wrote:

On Mon, May 21, 2012 at 5:28 AM, Raju Bitter  wrote:

How do I set jvm options for a lein repl initiated independently of a
project?   In particular, I want the heap expansion that results from doing
"M-x clojure-jack-in" in an emacs project.clj buffer with ":jvm-opts [
"-Xms4G" "-Xmx4G"]" in its defproject form.

Larry is looking for a way to set that value across all projects, not
just for one project.

You can set :jvm-opts in the user profile if you're using Leiningen 2.
Otherwise set JVM_OPTS as an environment variable.

-Phil



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: How do I set jvm options for a lein repl

2012-05-21 Thread Larry Travis
It took me a while to figure out how to put multiple entries into an 
environment variable (that is, settings for both min and max heap sizes, 
to wit, "export JVM_OPTS=\ -Xms4G\ -Xmx4G") but, once I did, Phil's and 
Luc's suggestions have worked well and things have gone swimmingly. They 
work for both bash and eshell. Thanks much to you all.

  --Larry


On 5/21/12 6:16 PM, Softaddicts wrote:

The bash example is

export JVM_OPTS=-Xms4G ...

missed the = ...

Luc

If you are running in a unix shell, something like

JVM_OPTS=-Xms4G ...

Followed by
export JVM_OPTS

Bash allows you to combine the two as in:

export JVM_OPTS-Xms4G ...

In a windows Cmd shell, something like this should work:

set JVM_OPTS=Xms4G ...

before running lein from the command line.

Luc





I should be switching over to Leiningen 2 shortly in any case, but I am
curious. How does one "set JVM_OPTS as an environment variable"?
--Larry


On 5/21/12 11:42 AM, Phil Hagelberg wrote:

On Mon, May 21, 2012 at 5:28 AM, Raju Bitter   wrote:

How do I set jvm options for a lein repl initiated independently of a
project?   In particular, I want the heap expansion that results from doing
"M-x clojure-jack-in" in an emacs project.clj buffer with ":jvm-opts [
"-Xms4G" "-Xmx4G"]" in its defproject form.

Larry is looking for a way to set that value across all projects, not
just for one project.

You can set :jvm-opts in the user profile if you're using Leiningen 2.
Otherwise set JVM_OPTS as an environment variable.

-Phil


--




--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: General subsequence function

2012-06-27 Thread Larry Travis

Something like this will give you what you want:

 (defn subseqx
  [s start end]
(cond
  (instance? clojure.lang.IPersistentVector s)
  (subvec s start end)

  (instance? java.lang.String s)
  (subs s start end)

  :else
  (let [slice (drop start (take end s))]
(cond
 (instance? clojure.lang.IPersistentList s)
 (apply list slice)

 (instance? clojure.lang.PersistentTreeSet s)
 (apply sorted-set slice)

 (instance? clojure.lang.PersistentTreeMap s)
 (apply sorted-map (concat slice))

 :else
 slice

And you can add conditions for other kinds of ordered collections if and 
when a need arises.  This is neither simple nor pretty, but an advantage 
of no-side-effects functional programming is that when you call a pure 
function you don't need to worry about how simple or pretty might be its 
internal details.

  --Larry

On 6/27/12 3:24 PM, Warren Lynn wrote:

Thanks, but this does not keep the concrete type.

On Wednesday, June 27, 2012 3:42:25 PM UTC-4, Ulises wrote:

> I'd forgotten that 'into adds things in the "default" place for
whatever type you're using, hence the reversal on lists. I'm not
sure if there's a simple way to get the same type out again while
preserving order.

How about:

(defn sub-seq [start end coll]
  (take (- end start) (drop start coll)))

U

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

Can I examine the state of a Clojure lazy sequence?

2012-07-08 Thread Larry Travis
(1) Is there any way I can extract from a Clojure lazy sequence at some 
given point in its use those of its members that have so far been 
realized? For example, can I extract the cache of realized members, turn 
it into a vector, and then process that vector independently of further 
use of the lazy sequence?


(2) If I can't extract the cache, is there some way that I can at least 
discover how many realized sequence members have so far been put into 
the cache?


It is obvious that, if all I want is an initial segment of a lazy 
sequence, I can force the initial segment's realization and get hold of 
it for further processing (independent of its source) with the take 
function -- but I want to know how many and what members of the lazy 
sequence have so far been realized independently of my forcing their 
realization -- for example, in order to evaluate and compare success so 
far of alternative solution paths being simultaneously pursued by an AI 
algorithm.


Thanks in advance for any relevant advice.
  --Larry

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


Meaning of "="

2012-10-02 Thread Larry Travis

What is the rationale for this?

user> (=  [1 2 3 4]  '(1 2 3 4))
true

I was quite surprised when this turned out to be the cause of a bug in a 
function I am constructing. Vectors and lists differ so substantially in 
their implementation and in their behavior that a vector and a list 
should not be considered "equal" just because they contain the same 
elements in the same order.


  --Larry


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


What is this function?

2012-10-09 Thread Larry Travis
As participants in this googlegroup have often observed, an excellent 
way to learn Clojure is to study the source definitions of its API 
functions.   This advice works better for learners who know Java, which 
I don't. I sometimes think that, if I were to teach a "Clojure 
Programming" course, I would list a "Java Programming" course as a 
prerequisite (for both teacher and students!). But here is some 
Clojure.core source code that raises a problem for me which surely 
doesn't have anything to do with not knowing Java.


user> (source list*)
(defn list*
  "Creates a new list containing the items prepended to the rest, the
  last of which will be treated as a sequence."
  {:added "1.0"
   :static true}
  ([args] (seq args))
  ([a args] (cons a args))
  ([a b args] (cons a (cons b args)))
  ([a b c args] (cons a (cons b (cons c args
  ([a b c d & more]
 (cons a (cons b (cons c (cons d (spread more)))

--
What is the function _spread_?  It is not in the Clojure API -- and the 
definition of _list*_ seems to me to be complete without it.

  --Larry

--
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: What is this function?

2012-10-09 Thread Larry Travis

Mark, Andy, Tassilo:
Very helpful, gentlemen. You are kind and skillful tutors. Thank you much.
  --Larry

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


  1   2   >