Clojure.java.jdbc alias

2012-05-10 Thread WoodHacker
I'm working with leiningen for the first time and trying to use
clojure.java.jdbc. All the docs I see use 'sql' before the jdbc
commands. How do I set up the sql symbol. Nothing I've tried seems to
work.

Bill

-- 
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: Books on Java Objects and Primitives

2011-05-24 Thread WoodHacker
I think I understand what you're looking for.   I have the same
concern.
There very best Java book I have found is The Java Developer's
Almanac
by Patrick Chan.   Volume 2 covers Swing and Volume 1 covers
everything
else.  No nonsense, just answers with great examples.

Bill


On May 23, 12:16 pm, octopusgrabbus octopusgrab...@gmail.com wrote:
 I apologize for not being clearer in why I asked this question. While
 learning Clojure, I thought it would be helpful to have some Java
 objects/primitives documentation to know what I can call in Clojure.
 Thanks and sorry for the too brief original post.

 On May 23, 10:01 am, octopusgrabbus octopusgrab...@gmail.com wrote: What 
 are some recent books that cover Java objects and primitives?

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


Strange error

2011-04-25 Thread WoodHacker
Can anyone help me with this?  I get the following error:

Exception in thread main java.lang.IllegalArgumentException:
Parameter declaration dosync should be a vector (jjJack.clj:22)

Line 22 is the ns statement - no other error line in my program is
listed.   I've used dosync many times.  Every one here looks
correct.   No parens are off.   Where should I look?

Bill

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

2011-03-17 Thread WoodHacker
Bluefish does not work that way.It will indent to the last
indentation in all cases.   I've never used EMacs, but all the editors
I've ever used work indenting the same way.   All I can suggest is
that you ask the Bluefish users group if there is a way to do what you
want.



On Mar 16, 9:16 am, Lee Spector lspec...@hampshire.edu wrote:
 I have Smart auto indenting on in the preferences, and the language is set 
 to Clojure, but I don't see any smarts. If I type:

 (defn foo

 and hit return the cursor goes to the beginning of the next line, not 
 indented. If I hit the tab key it tabs in, but it'll tab anything in further 
 each time I hit tab; it's not sensitive to the syntax or at least it's not 
 going to a reasonable place for the syntax. Within a definition if I type:

      (cons (first x)

 and hit return the cursor goes beneath the first (, not beneath the second 
 ( (which is the behavior of emacs modes, which I prefer) or even under the 
 o (which is the current behavior of Counterclockwise). Again, I can move 
 things around with tab but it's not syntax aware.

 I've tried doing this in parentheses-balanced expressions as well, but still 
 no smarts. I use this feature not only to keep my code neat but also to make 
 syntax errors visually obvious; it won't help for this if the indentation 
 isn't automatically aware of the language's syntax.

 What am I missing?

 Thanks,

  -Lee

 On Mar 16, 2011, at 8:38 AM, WoodHacker wrote: Check preferences from the 
 toolbar or the Bluefish dropdown.    There
  are checks for Smart Auto Indenting and Highlighting block
  delimiters.    There's very little this editor doesn't do.    You just
  have to make sure all the checks you want are set.

  Bill

  On Mar 14, 10:06 pm, Lee Spector lspec...@hampshire.edu wrote:
  The Clojure mode activates for me, and I get a little bit syntax coloring, 
  autocompletion, and () matching. But I don't get language aware 
  indentation. Should I, or isn't this supported? (It's a really important 
  feature IMHO.) Also, no matching of [] or {} (less important 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


Re: Clojure Editor

2011-03-16 Thread WoodHacker
Check preferences from the toolbar or the Bluefish dropdown.There
are checks for Smart Auto Indenting and Highlighting block
delimiters.There's very little this editor doesn't do.You just
have to make sure all the checks you want are set.

Bill

On Mar 14, 10:06 pm, Lee Spector lspec...@hampshire.edu wrote:
 The Clojure mode activates for me, and I get a little bit syntax coloring, 
 autocompletion, and () matching. But I don't get language aware indentation. 
 Should I, or isn't this supported? (It's a really important feature IMHO.) 
 Also, no matching of [] or {} (less important for me).

 Thanks,

  -Lee

 On Mar 14, 2011, at 8:06 AM, WoodHacker wrote: The file you need should be 
 there.   First look under the Document/
  Language Support menu item.   You should see and entry for Clojure.
  Try checking it.    The syntax file is called clojure.bflang2 and it
  should be in a Bluefish directory somewhere on your system.   I am
  using a MAC, so the file is under the /Applicatiions directory.    If
  you need to adjust the bflang2 file for some reason, the file that
  explains how to do it is Sample.bflang2.    If none of this makes
  sense and you can't find clojure.bflang2, try contacting the Bluefish
  people by sending and email to bluefish-us...@lists.ems.ru.

  On Mar 13, 9:49 am, Shantanu Kumar kumar.shant...@gmail.com wrote:
  Do I need a plugin? I downloaded the stock 2.0.3-1 version of the
  editor and it doesn't even seem to syntax-highlight the Clojure code.

  Regards,
  Shantanu

  On Mar 13, 5:09 pm, WoodHacker ramsa...@comcast.net wrote: If you are 
  looking for a very good editor for Clojure try Bluefish.
  It's been around for ever, is very stable, and does everything you
  would want an editor to do.   And it now works with Clojure.

     http://bluefish.openoffice.nl

  Bill

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

2011-03-14 Thread WoodHacker
The file you need should be there.   First look under the Document/
Language Support menu item.   You should see and entry for Clojure.
Try checking it.The syntax file is called clojure.bflang2 and it
should be in a Bluefish directory somewhere on your system.   I am
using a MAC, so the file is under the /Applicatiions directory.If
you need to adjust the bflang2 file for some reason, the file that
explains how to do it is Sample.bflang2.If none of this makes
sense and you can't find clojure.bflang2, try contacting the Bluefish
people by sending and email to bluefish-us...@lists.ems.ru.

On Mar 13, 9:49 am, Shantanu Kumar kumar.shant...@gmail.com wrote:
 Do I need a plugin? I downloaded the stock 2.0.3-1 version of the
 editor and it doesn't even seem to syntax-highlight the Clojure code.

 Regards,
 Shantanu

 On Mar 13, 5:09 pm, WoodHacker ramsa...@comcast.net wrote: If you are 
 looking for a very good editor for Clojure try Bluefish.
  It's been around for ever, is very stable, and does everything you
  would want an editor to do.   And it now works with Clojure.

     http://bluefish.openoffice.nl

  Bill

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


Clojure Editor

2011-03-13 Thread WoodHacker
If you are looking for a very good editor for Clojure try Bluefish.
It's been around for ever, is very stable, and does everything you
would want an editor to do.   And it now works with Clojure.

   http://bluefish.openoffice.nl

Bill

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


Reference Variables Question

2011-03-12 Thread WoodHacker
Hi,

I have a simple general question about variables used in Clojure.
Often you have an object that must be referenced because it is
established at run time and not known beforehand.   Lets say we have
an block object and it has a certain height.   We create a reference
to the block's height and use it throughout the program.   But there
are many cases where we have to know HALF the height of the block.
My question is, is it more efficient to create another reference for
half the block's height or to calculate the half height value every
time it is needed?

Bill

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


Help with Java arrays

2011-01-28 Thread WoodHacker
Hi,

I'm trying to get the midi sound class in Java to work in Clojure.
Everything seems to work fine except for the conversion of the
following Java code:

 MidiChannel[] channels = synthesizer.getChannels;

I've tried just dumping the channels into a Clojure object -
  (let [channels (.getChannels @synthesizer)]
but I get the following error:

Exception in thread main java.lang.IllegalArgumentException: Can't
call public method of non-public class: public
javax.sound.midi.MidiChannel[]
com.sun.media.sound.AbstractPlayer.getChannels()

There seems to be no way to find out how many channels there are
beforehand.

I'm sure there's a solution, but I can't figure it out.   Any ideas?

Bill

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


Map keys

2011-01-23 Thread WoodHacker
Is it possible to create a map key from an integer or string to be
used for retrieving data dynamically from a map?

Bill

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


Help with java conversion

2011-01-21 Thread WoodHacker
I'm converting the java code examples in Killer Game Programming in
Java by Andrew Davison to Clojure and am having great fun doing it.
But I've hit wall where I can't seem to get the code to work.

The following code moves an animated gif strip to a java array:

  public BufferedImage[] loadStripImageArray(String fnm, int number)
  {
if (number = 0) {
  System.out.println(number = 0; returning null);
  return null;
}

BufferedImage stripIm;
if ((stripIm = loadImage(fnm)) == null) {
  System.out.println(Returning null);
  return null;
}

int imWidth = (int) stripIm.getWidth() / number;
int height = stripIm.getHeight();
int transparency = stripIm.getColorModel().getTransparency();

BufferedImage[] strip = new BufferedImage[number];
Graphics2D stripGC;

// each BufferedImage from the strip file is stored in strip[]
for (int i=0; i  number; i++) {
  strip[i] =  gc.createCompatibleImage(imWidth, height,
transparency);   =

  // create a graphics context
  stripGC = strip[i].createGraphics();
=
  // stripGC.setComposite(AlphaComposite.Src);

  // copy image
  stripGC.drawImage(stripIm,
  0,0, imWidth,height,
  i*imWidth,0, (i*imWidth)+imWidth,height,
  null);
  stripGC.dispose();
}
return strip;
  } // end of loadStripImageArray()

The problem I'm having is with the for loop.   If I create an abject
array of say 6 buffered images,  how do I reference the indexed image
array to match the lines pointed to?  In other words what is the
equivalent of strip[i] in Clojure?

I'm not exactly a beginner, but this has stumped me.

Bill


-- 
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: Multidimensional Float arrays

2011-01-12 Thread WoodHacker
This is a much better solution.   It's shorter and is easier to read.
Thanks for tip!

Bill

On Jan 10, 11:49 pm, Sunil S Nandihalli sunil.nandiha...@gmail.com
wrote:
 Hi Bill ,
 the following is one way of doing it ..

 (into-array (map float-array  [[1.0 1.0 2.0 2.0] [3.0 2.2 4.0 0.0]]))

 Sunil.

 On Mon, Jan 10, 2011 at 8:32 PM, WoodHacker ramsa...@comcast.net wrote:
  Hi,

  Can anybody explain to me how to create a multidimensional array of
  floats such as:

    [[1.0 1.0 2.0 2.0] [3.0 2.2 4.0 0.0]]

  Anything I try gives me errors.

  Bill

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


Re: Multidimensional Float arrays

2011-01-11 Thread WoodHacker
When all else fails, read the directions.

Thanks for the help.

On Jan 10, 4:44 pm, Ken Wesson kwess...@gmail.com wrote:
 On Mon, Jan 10, 2011 at 4:40 PM, WoodHacker ramsa...@comcast.net wrote:
  The question was how to place data in the array, not create it.   I've
  been
  doing that.   How do you populate it?    The doc shows:

  user= (doc aset-float)
  -
  clojure.core/aset-float
  ([array idx val] [array idx idx2  idxv])

  If I try that I get:

  user= (def wa (make-array Float/TYPE 4 4))
  #'user/wa
  user= wa
  #float[][] [...@4cb533b8
  user= (aset-float wa 0 0  1.0)
  java.lang.Exception: Unable to resolve symbol:  in this context
  (NO_SOURCE_FILE:5)
  user=

  What am I missing?

 That that's not a literal ampersand expected by aset-float; just that
 it can take a variable number of indices. Try (aset-float wa 0 0 1.0).

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


Multidimensional Float arrays

2011-01-10 Thread WoodHacker
Hi,

Can anybody explain to me how to create a multidimensional array of
floats such as:

   [[1.0 1.0 2.0 2.0] [3.0 2.2 4.0 0.0]]

Anything I try gives me errors.

Bill

-- 
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: Multidimensional Float arrays

2011-01-10 Thread WoodHacker
The question was how to place data in the array, not create it.   I've
been
doing that.   How do you populate it?The doc shows:

user= (doc aset-float)
-
clojure.core/aset-float
([array idx val] [array idx idx2  idxv])

If I try that I get:

user= (def wa (make-array Float/TYPE 4 4))
#'user/wa
user= wa
#float[][] [...@4cb533b8
user= (aset-float wa 0 0  1.0)
java.lang.Exception: Unable to resolve symbol:  in this context
(NO_SOURCE_FILE:5)
user=

What am I missing?

On Jan 10, 10:08 am, Albert Cardona sapri...@gmail.com wrote:
 2011/1/10 WoodHacker ramsa...@comcast.net:

  Hi,

  Can anybody explain to me how to create a multidimensional array of
  floats such as:

    [[1.0 1.0 2.0 2.0] [3.0 2.2 4.0 0.0]]

  Anything I try gives me errors.

 user= (doc make-array)
 -
 clojure.core/make-array
 ([type len] [type dim  more-dims])
   Creates and returns an array of instances of the specified class of
   the specified dimension(s).  Note that a class object is required.
   Class objects can be obtained by using their imported or
   fully-qualified name.  Class objects for the primitive types can be
   obtained using, e.g., Integer/TYPE.
 nil
 user= (make-array Double/TYPE 2 8)
 #double[][] [...@4cb533b8
 user= (count (aget *1 0))
 8

 --http://albert.rierol.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


Multiple Files

2010-10-19 Thread WoodHacker
Hi all,

Can anyone help me with this?   I have a program with multiple
files.   The program uses various data references, which may be
accessed from different files.   To facilitate this I usually put ref
variables in a separate file and then :use that file in all the
various modules that make up the program.   That has worked perfectly
- except for on problem.I cannot seem to get defrecord to work in
the same way.  If I put a defrecord description in my refs file I get
the following error:

Exception in thread main java.lang.IllegalArgumentException: Unable
to resolve classname: phone-data

The question is:   Why doesn't this work?   And how do I get around
it?Do I put the defrecord in each file it's to be used in?

Bill

-- 
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: Handling keystrokes

2010-10-01 Thread WoodHacker
This is a Clojure Java interop problem.If you are doing GUI
programming with Swing in Clojure this is a real problem.  The
question is how do you subclass (?) a built-in swing operation to
extend it to include your own code.After the paste, I want to do
something to the pasted text.This is done all the time, but I have
no idea how to do it in Clojure.

Bill

On Sep 30, 8:16 am, Laurent PETIT laurent.pe...@gmail.com wrote:
 You have probably mistaken this clojure group for another ...

 2010/9/30 WoodHacker ramsa...@comcast.net I have a keyboard paste problem, 
 but I think it has more general
  interest.   When the user types Control V in a JTextPane, data from
  the clipboard will be pasted into the text.   I want to act on that
  pasted text.   I can easily capture the keystroke.   The problem is
  that my capture takes place BEFORE the actual paste.     What do I do
  to make my handler occur AFTER the paste?

  Bill

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


Handling keystrokes

2010-09-30 Thread WoodHacker
I have a keyboard paste problem, but I think it has more general
interest.   When the user types Control V in a JTextPane, data from
the clipboard will be pasted into the text.   I want to act on that
pasted text.   I can easily capture the keystroke.   The problem is
that my capture takes place BEFORE the actual paste. What do I do
to make my handler occur AFTER the paste?

Bill

-- 
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: Dynamic defrecord

2010-07-29 Thread WoodHacker
Hi Stu

It is as simple as that. What I'm really working on is my own
editor.   The file in question is the lexer
for various program types.The editor never knows what type of file
will be loaded until it's loaded.   At
that point the proper lexer should be loaded and stored so that the
next time a file of that type is loaded
the lexer is already there.This problem is seen in many different
programming tasks.There is no
point in pre-loading a ruby lexer if the user never loads a ruby file,
etc.Once loaded the lexer is never
changed.

I like slurp as the function name!

Bill

On Jul 28, 9:16 am, Stuart Halloway stuart.hallo...@gmail.com wrote:
 Hi Bill,

 Are your looking for something as simple as this:

 (defrecord Foo [x])

 (defn load-a-record-at-runtime
   Loads a record value from a file
   [f]
   (Foo. (slurp f)))

 Or is there some subtlety here?

 Stu The confusion over type and instance was a sloppy example.   Sorry.

  But in your solution I'm confused by one thing.   You create and
  instance of Foo in the let and then assoc the new value of List1 to
  it.
  This has two problems.   One is that the loaded data is not
  permanent.   The other is that there is no way to add List2 to the
  MyFoo record.

  (I've decided to not use MyFoo at all.   Instead I have a (def List1
  (ref nil)) defined and then do a ref-set to it when the data is
  loaded.    This seems
  much simpler and works.   I then can do a def for List2, List3, etc.)

  It seem to me there should be some way to load a record at run time
  without breaking the immutability laws.    Once the dynamic data is
  loaded, the record becomes immutable and will never be changed
  again.    It's unrealistic to imagine that we always know at compile
  time what the values of a record will be.
  I'm not a compiler person so I have no idea how to do such a thing and
  no idea if it is possible.

  On Jul 27, 5:23 pm, Stuart Halloway stuart.hallo...@gmail.com wrote:
  Hi Bill,

  There are several issues here:

  (1) A confusion of record and instance. You are asking for the :list1 
  field from foo, the record type, not from an instance of the type.

          (:list1 foo)   s/b  (:list1 MyFoo)

  (2) You are ignoring the return value of assoc. Remember, Clojure data 
  structures are immutable. To actually assign something you need to hold on 
  to the return value of the expression (or use a reference type if you 
  really want an identity).

  (3) The capitalization choices facilitate confusion. You are using foo 
  for a record/class name, where both Java and Clojure style would dictate 
  Foo. Then you use MyFoo for a top-level def, where Clojure style would 
  encourage my-foo.

  The following code demonstrates these ideas.

  ;; stubbed so example can be run
  (defn load-data-from-file
    [x] :stub)

  (defrecord Foo [list1 list2])

  (defn get-data [path]
    (let [list1Data (load-data-from-file path)
          f (Foo. nil nil)
          f (assoc f :list1 list1Data)]
      (:list1 f)))

  (get-data fakepath)

  Regards,
  Stu

  Stuart Halloway
  Clojure/corehttp://clojure.com All the examples of defrecord I see seem 
  simple enough and when I
  experiment in the REPL I get things to work as they should.  However,
  when I move to 'real' code I can't get it to work at all.

  The problem at hand is simple enough - I want to create a record that
  hold records.   For example I have (defrecord foo [list1, list2])
  where list1 and list2 are defined records themselves.   The issue is
  that the data in list1 and list2 is dynamic - it is loaded from a file
  at run time.    So I do the following:

  (def MyFoo (foo. nil nil))

  (defn get-data [path]
    (let [list1Data (load-data-from-file path)]   ; fill in the record
  for list 1
        (assoc MyFoo :list1 list1Data)              ; assign the data
  record to the foo record
       (:list1 foo)
  ))

  As I say, if I do this non-dynamically in the REPL I get the proper
  result.

  In my program (using let)  (:list1 foo) always remains nil.    What am
  I doing wrong?   And how can I get the fields of foo to take on the
  dynamic data.

  Bill

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

Re: Dynamic defrecord

2010-07-29 Thread WoodHacker
Yes, but I don't want to load all the parts at once.   I may have four
records that will be part of MyFoo,
but I only ever need one - maybe List3 in this case.That's why
it's dynamic and why I have the
problem in the first place.

Bill

On Jul 28, 12:40 pm, Armando Blancas armando_blan...@yahoo.com
wrote:
  It seem to me there should be some way to load a record at run time
  without breaking the immutability laws.    Once the dynamic data is
  loaded, the record becomes immutable and will never be changed
  again.

 Actually, that's how records work and is exactly the behavior of the
 initial (foo. nil nil), after which the record is loaded and
 immutable. If the loaded data must be bound to MyFoo:

 (def MyFoo (foo. (load-data-from-file f1) (load-data-from-file f2)))

 or you might consider making Myfoo a ref instead of each subrecords,
 seems simpler that way.

-- 
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: Dynamic defrecord

2010-07-28 Thread WoodHacker
The confusion over type and instance was a sloppy example.   Sorry.

But in your solution I'm confused by one thing.   You create and
instance of Foo in the let and then assoc the new value of List1 to
it.
This has two problems.   One is that the loaded data is not
permanent.   The other is that there is no way to add List2 to the
MyFoo record.

(I've decided to not use MyFoo at all.   Instead I have a (def List1
(ref nil)) defined and then do a ref-set to it when the data is
loaded.This seems
much simpler and works.   I then can do a def for List2, List3, etc.)

It seem to me there should be some way to load a record at run time
without breaking the immutability laws.Once the dynamic data is
loaded, the record becomes immutable and will never be changed
again.It's unrealistic to imagine that we always know at compile
time what the values of a record will be.
I'm not a compiler person so I have no idea how to do such a thing and
no idea if it is possible.

On Jul 27, 5:23 pm, Stuart Halloway stuart.hallo...@gmail.com wrote:
 Hi Bill,

 There are several issues here:

 (1) A confusion of record and instance. You are asking for the :list1 field 
 from foo, the record type, not from an instance of the type.

         (:list1 foo)   s/b  (:list1 MyFoo)

 (2) You are ignoring the return value of assoc. Remember, Clojure data 
 structures are immutable. To actually assign something you need to hold on to 
 the return value of the expression (or use a reference type if you really 
 want an identity).

 (3) The capitalization choices facilitate confusion. You are using foo for 
 a record/class name, where both Java and Clojure style would dictate Foo. 
 Then you use MyFoo for a top-level def, where Clojure style would encourage 
 my-foo.

 The following code demonstrates these ideas.

 ;; stubbed so example can be run
 (defn load-data-from-file
   [x] :stub)

 (defrecord Foo [list1 list2])

 (defn get-data [path]
   (let [list1Data (load-data-from-file path)
         f (Foo. nil nil)
         f (assoc f :list1 list1Data)]
     (:list1 f)))

 (get-data fakepath)

 Regards,
 Stu

 Stuart Halloway
 Clojure/corehttp://clojure.com All the examples of defrecord I see seem 
 simple enough and when I
  experiment in the REPL I get things to work as they should.  However,
  when I move to 'real' code I can't get it to work at all.

  The problem at hand is simple enough - I want to create a record that
  hold records.   For example I have (defrecord foo [list1, list2])
  where list1 and list2 are defined records themselves.   The issue is
  that the data in list1 and list2 is dynamic - it is loaded from a file
  at run time.    So I do the following:

  (def MyFoo (foo. nil nil))

  (defn get-data [path]
    (let [list1Data (load-data-from-file path)]   ; fill in the record
  for list 1
        (assoc MyFoo :list1 list1Data)              ; assign the data
  record to the foo record
       (:list1 foo)
  ))

  As I say, if I do this non-dynamically in the REPL I get the proper
  result.

  In my program (using let)  (:list1 foo) always remains nil.    What am
  I doing wrong?   And how can I get the fields of foo to take on the
  dynamic data.

  Bill

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


Dynamic defrecord

2010-07-27 Thread WoodHacker
All the examples of defrecord I see seem simple enough and when I
experiment in the REPL I get things to work as they should.  However,
when I move to 'real' code I can't get it to work at all.

The problem at hand is simple enough - I want to create a record that
hold records.   For example I have (defrecord foo [list1, list2])
where list1 and list2 are defined records themselves.   The issue is
that the data in list1 and list2 is dynamic - it is loaded from a file
at run time.So I do the following:

(def MyFoo (foo. nil nil))

(defn get-data [path]
   (let [list1Data (load-data-from-file path)]   ; fill in the record
for list 1
   (assoc MyFoo :list1 list1Data)  ; assign the data
record to the foo record
  (:list1 foo)
))

As I say, if I do this non-dynamically in the REPL I get the proper
result.

In my program (using let)  (:list1 foo) always remains nil.What am
I doing wrong?   And how can I get the fields of foo to take on the
dynamic data.

Bill

-- 
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's n00b attraction problem

2010-06-29 Thread WoodHacker

 So I wonder how much making the first few baby steps easier is really
 going to help the uptake of Clojure. I have to imagine that the kind
 of person that can't figure out  a CLASSPATH is going to have his head
 explode when he has to figure out how to restructure all his
 iterations in terms of loop/recur.

This discussion, although interesting, is ridiculous.I've been
doing this for nearly 40 years and if I'd listened to all the people
who worried that new languages were to hard for noobs, I'd still be
writing Fortran or Cobal.C was hard when it first came out - for
most of the same reasons people are using with Clojure.Clojure is
a great language now and can only get better because it mixes the
greatest language ever invented (Lisp) with the best library
available.People have complained for years about the limitations
of Lisp, but it's still with us (whatever happened to PL1?)All
Lisp has ever needed was a universal library.   Let the faint of heart
turn away - they will come back.

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


Re: How to reset a counter

2010-05-30 Thread WoodHacker


On May 29, 9:44 am, James Reeves jree...@weavejester.com wrote:
 On 29 May 2010 14:19, WoodHacker ramsa...@comcast.net wrote:

  I'm working on  a simple imaging problem.   I want to copy an array of
  pixels to an image buffer.   That means that I have to deal both with
  an array and a matrix (x and y).   As I go along my array, each time x
  reaches the end of a line in the matrix I have to set it back to zero
  and increment y.

  I can find no simple way to do this without getting a compile error.
  Can someone show me how to do this?


   (dotimes [k 256]
     (write-buffer (mod k 16) (quot k 16) (value 16)))


James,

Thanks.   I have written code in about every mainstream language.
None of them have this power (except Lisp).
Two lines?   Amazing.

Bill

-- 
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 reset a counter

2010-05-29 Thread WoodHacker
I've been working with Lisp and Scheme for the past few years and have
migrated to Clojure because of the JVM.   I think I get functional
programming, but one problem is giving me fits.

I'm working on  a simple imaging problem.   I want to copy an array of
pixels to an image buffer.   That means that I have to deal both with
an array and a matrix (x and y).   As I go along my array, each time x
reaches the end of a line in the matrix I have to set it back to zero
and increment y.

I can find no simple way to do this without getting a compile error.
Can someone show me how to do this?

Example in pseudo code:

x = 0
y = 0

for  (k = 0; k  256; ++k)
   if (= x 16) {
  x = 0
 (inc y)
  }
  else
 (inc x)

 writeBuffer (x, y, value[k])


Bill

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


Testing equality

2010-04-28 Thread WoodHacker
Can someone explain to me why this doesn't work:

  (let [ p Bill/
  sep (System/getProperty file.separator)
   ]

  (if (= (last p) sep)
  (println found separator)
  (println no separator)
  )

The (= (last p) sep) always returns false.   If I print them out
inside pipes they look like
| / | and | / | (white space on either side of the slash).

Is this some sort of bug?   Is there a better solution for finding a
file separator at the end of a line?

Bill




-- 
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: Nubie Question

2010-03-25 Thread WoodHacker
I thank all the people who have sent me solutions to my Conj
problem.   Unfortunately, none of them seem to work.

The issue is adding a value to a defined vector - (def savedColors
[black, white])

One solution was given as:  (swap! savedColors conj newcolor)

This produces still the following runtime error:

Exception in thread AWT-EventQueue-0
java.lang.ClassCastException: clojure.lang.PersistentVector cannot
be cast to clojure.lang.Atom

Another solution was to make savedColors an atom - (def savedColors
(atom [black, white]))

This produces a new compile error:

Exception in thread AWT-EventQueue-0
java.lang.IllegalArgumentException: Don't know how to create ISeq
from: clojure.lang.Atom

Changing savedColors to a list instead of a vector gets the same
error.   The atom example on the web is for a map.

I'm sure this can be done.   So far I just don't know how.

Bill

-- 
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 from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Nubie Question

2010-03-24 Thread WoodHacker
Actually, swap! doesn't seem to work in my case.I should state
what I'm
trying to do.I'm writing a graphics editing program where I want
the user
to be able to choose and save color values.   I start out with a
vector
containing blank and white.  When the user selects a new color and
wants
to save it I add the new color to the vector.

(def savedColors [black, white])
.
(defn saveColor [color panel]
  (swap! savedColors  (conj savedColors color))   -- this does not
work
  .  also show the colors in the editor
))

I get the following error:

Exception in thread AWT-EventQueue-0 java.lang.ClassCastException:
clojure.lang.PersistentVector cannot be cast to clojure.lang.Atom

I assume I'm using swap! correctly, but may not be.

Bill

On Mar 23, 9:57 am, Per Vognsen per.vogn...@gmail.com wrote:
 By definition, persistent data structures are never mutable. But there
 are various kinds of mutable references (vars, refs, atoms, agents)
 that can _refer_ to persistent (hence unchanging) data structures.

 While David has given you an answer to your immediate query, I would
 ask you to step back and consider whether you're sure you really need
 references. You haven't supplied enough context for us to make that
 call.

 -Per

 On Tue, Mar 23, 2010 at 8:35 PM, WoodHacker ramsa...@comcast.net wrote:
  I understand howconjworks.    But how do you add a value to a
  persistent vector?    You have to add the new item to the vector with
  (conjvector item), but how do you assign the return value to the
  persistent vector.   So far I have it working with a def  -- (def
  vector (conjvector item)) -- but I'm not sure this is 'pure'
  Clojure.    Is there a better way, functionally, or am I there?
  Functional programming is the best way to go, but very few programs
  can exist without mutable persistent data.

  Bill

  --
  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 from this group, send email to 
  clojure+unsubscribegooglegroups.com or reply to this email with the words 
  REMOVE ME as the subject.

-- 
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 from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Nubie Question

2010-03-23 Thread WoodHacker
I understand how conj works.But how do you add a value to a
persistent vector?You have to add the new item to the vector with
(conj vector item), but how do you assign the return value to the
persistent vector.   So far I have it working with a def  -- (def
vector (conj vector item)) -- but I'm not sure this is 'pure'
Clojure.Is there a better way, functionally, or am I there?
Functional programming is the best way to go, but very few programs
can exist without mutable persistent data.

Bill

-- 
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 from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


JColorChooser

2010-03-22 Thread WoodHacker
When I try to use JColorChooser in Clojure I get the followinf error:

Exception in thread AWT-EventQueue-0
java.lang.IllegalArgumentException: No matching method found:
showDialog for class javax.swing.JColorChooser

Shouldn't showDioalog be there?   What and I doing wrong.   Here's the
code:

(defn newColor [parent]
  (proxy [ActionListener] []
(actionPerformed [evt]
  (def colorChooser (new JColorChooser))
  (doto colorChooser
(.showDialog parent Choose Color bisque))

 
)))

Bill

-- 
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 from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Menubar presentation on a Mac

2010-03-09 Thread WoodHacker
Hi All,

Can anyone explain how I can get a traditional Mac OS menubar to
appear at the top of the screen?

Normally I would use  (System/setProperty
apple.laf.useScreenMenuBar, true) and then
(.setJMenuBar ...) in my main frame.

This does not appear to work.   The menu shows up in the frame itself
as in Windows and the Apple menu shows only clojure.main.

I am running my program as a script - java -cp .:$CLOJURE_HOME/
clojure.jar clojure.main dicon.clj
and not compiling it into Java classes.Since I am calling
clojure.main from  my script it seems to be taking over the menubar.

Is there a way around this?

Bill

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