generators...?

2014-03-26 Thread Christopher Howard
Hi. I'm still fairly new to Clojure. I was wondering: What's the
easiest way to make a generator (or something that would be as useful).
In one application, I need something that will return a different color
each time I call it - following a predefined list of colors, and
starting over again at the beginning when colors are exhausted.

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


working with "multiple" return values

2014-03-28 Thread Christopher Howard
In Clojure, what is the easiest (cleanest) way to return "multiple"
values from a function, in order to work with them immediately
afterwards? In Haskell you can return a tuple, and pattern match the
components into variables.

Prelude> let (a, b) = (1 + 4, 2 - 1)
Prelude> a
5
Prelude> b
1

IIRC, Python has something similar.

I know how to return a list or a vector, of course, but I'm imagining
having to put in a bunch of cludgy code to extract the components into
variables, which is not appealing.

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


using contrib functions

2014-03-28 Thread Christopher Howard
Hi. --Insert here the usual caveats about being new to Clojure and
Java.--

I wanted to try out this Contrib function describe on this
page
.
 How
do I get that in my project? Trying to follow documentation, I did
"lein search":
  
code:

my-host:~/my-project$ lein search contrib
Warning: couldn't download index for http://repo1.maven.org/maven2
 == Results from clojars - Showing page 1 / 1 total
[webnf.deps/contrib "0.0.1"] The uber dependency to get a full set of popular
  dependencies. For development or when you have room in your .m2 repo.

my-host:~/my-project$ lein search clojure.contrib.types
Warning: couldn't download index for http://repo1.maven.org/maven2
my-host:~/my-project$ lein search defadt
Warning: couldn't download index for http://repo1.maven.org/maven2


Is that "webnf" package the thing I am supposed to put in my
"dependencies" list? Version 0.0.1 doesn't sound right. Or am I
supposed to download something myself and throw it in my lib
directory?

-- 
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: using contrib functions

2014-03-31 Thread Christopher Howard
On Fri, 28 Mar 2014 20:06:59 -0700
Sean Corfield  wrote:

> BTW, where did you find the references to defadt and
> clojure.contrib.types? Perhaps we can get the original references
> updated so people aren't misled in future...
> 
> Sean
> 

I think it was this old StackOverflow post:

http://stackoverflow.com/questions/5430673/clojure-algebraic-data-types

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


REPL: viewing data structures containing infinite lists

2014-03-31 Thread Christopher Howard
Is there some kind of "safe" function for printing representations of
lazy, infinite data structures? I'm finding I like using them inside
other data structures here and there. However, when I go to play
around with things in the REPL, sooner or later my workflow is
interrupted by 3 million characters streaming across the console.

I don't imagine there would be any way for the REPL to detect that a
lazy sequence was infinite. However, if it would simply refuse to
evaluate lazy sequence (say, represent them by some special identifier) that
would be good enough for 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.


remove first?

2014-04-02 Thread Christopher Howard
Is there some like "remove", but only removing the first item found?
Not exactly an incredibly hard problem, but with all this clojure
stuff about collections and sequences, I'm not quite sure what the
appropriate way is to implement 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
--- 
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: remove first?

2014-04-02 Thread Christopher Howard
On Wed, 2 Apr 2014 14:07:47 -0600
Timothy Baldridge  wrote:

> I don't know of anything built-in, but this should do the trick:
> 
> (defn remove-first [f [head & tail]]
>   (if (f head)
>   tail
>   (cons head (lazy-seq (remove-first f tail)
> 
> Timothy
> 
> 

Thanks. This seems to work for my purposes, although I modified it to
handle the empty vector:

(defn remove-first [f [head & tail]]
  (if (not head) []
  (if (f head)
  tail
  (cons head (lazy-seq (remove-first f tail))

This implementation doesn't seem to work on everything that "remove"
works on:

com.example.myapp=> (remove #(= [1 2] %) {1 2 3 4})
([3 4])
com.example.myapp=> (remove-first #(= [1 2] %) {1 2 3 4})
UnsupportedOperationException nth not supported on this type: 
PersistentArrayMap  clojure.lang.RT.nthFrom (RT.java:835)

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


list all functions in namespace?

2014-04-04 Thread Christopher Howard
Is there some trick Clojure command to list all functions defined in a
namespace?

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


Elementary question about displaying images in an app

2014-04-24 Thread Christopher Howard
This is, I think, as much of a Java question as a Clojure question
(I'm learning both at the same time). I'm writing a small desktop
application, and I need to paint a few images in one part of the
window (contained in PNGs). I'm looking through AWT/Swing/Graphics2D
documentation, but I am a little unclear about the correct/modern way
of doing this.

Is Canvas the component I need? If so, how do I subclass it and
override the paint method (from within Clojure). Or is there a better
way to approach this?

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


seesaw >> canvas >> paint

2014-05-02 Thread Christopher Howard
Suppose one is using seesaw, and wants to have a canvas with lots of
images and whatnot drawn inside it. The github examples pretty well
cover that. However, what if you want the paint function to behave
differently depending on some data elsewhere? (For example, the canvas
is supposed to be a visual representation of model data.) Should you
just have the paint function capture the (modifiable) data variable,
and use that each time? Or...?

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


setting environment variables for all repls?

2014-05-14 Thread Christopher Howard
Hey all, I want

(set! *print-length* 40)

to be run each time I open "lein repl" (regardless of the project,
preferably). I thought that is what the ~/.lein/init.clj file was for,
but apparently not.

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


seesaw: drawing text

2014-06-03 Thread Christopher Howard
Hi. In seesaw, how do you draw text to a graphics 2d object? I see in
seesaw.graphics how to draw circles and lines and such, but want to
draw a line of text. (I'm drawing on a canvas.)

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


arguments passed to a macro

2014-06-05 Thread Christopher Howard
Is there a trick for "pre-expanding" some of the arguments passed to a
macro? Say you wanted to do this

code:

(def swing-imports '(javax.swing JFrame JButton ImageIcon JPanel))

(ns example.myprogram
  (:import swing-imports))
  ...


ns will complain that it can't find the "swing-imports" class.

I've been trying various things I thought might work (like backtick
evaluation and evals) but haven't made progress.

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


using "hidden" parameters?

2014-06-13 Thread Christopher Howard
This might be kind of perverse, but I was wondering if it was possible
to write a function or macro that takes "hidden parameters", i.e.,
uses symbols defined in the scope of use, without passing them in
explicitly.

For example, function "next-number" takes hidden parameter "x", so

=> (let [x 12] (next-number))

Would return 13.

With the whole "code is data" paradigm it seems like this should be
possible, but I haven't figured out how to do this yet without getting
an error.

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


macro question

2014-06-16 Thread Christopher Howard
Disclosure: I'm rather fascinated with macros (the things they are
supposed to allow us to do), but I'm still rather mystified about how
they actually work. It seems like every time I try to write one, it
rarely behaves anything like I expect.

Question: Is there any obvious problems with this seemingly innocent
macro?:

(defmacro if-zero [test-expr true-expr false-expr]
  (if (= test-expr 0) true-expr false-expr))

It doesn't seem to work the way I would expect when used inside other
functions.

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


restarts

2014-06-19 Thread Christopher Howard
Does Clojure have restarts or continuable-errors like in CL? Or
something similiar? If not, is that something that could be
implemented some how?

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


Beginner: let with Java object

2017-05-26 Thread Christopher Howard
When I run

tutorial.core> (let [img (new-image 32 32)] (set-pixel img 10 10 cyan)
(show img))

from the REPL, this returns a javax.swing.JFrame object, and displays
the frame and image as expected. However, if put the same in

(defn -main
  "Generates image."
  [& args]
  (let [img (new-image 32 32)]
(set-pixel img 10 10 cyan)
(show img)))

in more core.clj, and run (-main) from the REPL, I get error

ClassCastException java.awt.image.BufferedImage cannot be cast to
clojure.lang.IFn  tutorial.core/-main (core.clj:11)

Why the difference?

-- 
https://qlfiles.net

-- 
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: Beginner: let with Java object

2017-05-26 Thread Christopher Howard
I restarted the Emacs CIDER REPL, and now it seems to work fine. Maybe I
just don't understand how to use this CIDER REPL properly.

On 05/26/2017 07:58 AM, Gary Trakhman wrote:
> There shouldn't be a difference, I would suspect a typo in your file.
> 
> The error 'ClassCastException java.awt.image.BufferedImage cannot be cast to
> clojure.lang.IFn  tutorial.core/-main (core.clj:11)' would lead me to
> look for things like '(img)' where the object ends up in call position
> of the s-expression.
> 
> On Fri, May 26, 2017 at 11:54 AM Christopher Howard
> mailto:christopher.how...@qlfiles.net>>
> wrote:
> 
> When I run
> 
> tutorial.core> (let [img (new-image 32 32)] (set-pixel img 10 10 cyan)
> (show img))
> 
> from the REPL, this returns a javax.swing.JFrame object, and displays
> the frame and image as expected. However, if put the same in
> 
> (defn -main
>   "Generates image."
>   [& args]
>   (let [img (new-image 32 32)]
> (set-pixel img 10 10 cyan)
> (show img)))
> 
> in more core.clj, and run (-main) from the REPL, I get error
> 
> ClassCastException java.awt.image.BufferedImage cannot be cast to
> clojure.lang.IFn  tutorial.core/-main (core.clj:11)
> 
> Why the difference?
> 
> --
> https://qlfiles.net
> 
> --
> 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 unsubscribe from this group and stop receiving emails from it,
> send an email to clojure+unsubscr...@googlegroups.com
> <mailto:clojure%2bunsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> 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
> <mailto:clojure+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

-- 
https://qlfiles.net

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