Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Lisp-style list

Thread view: 
Hendrik Maryns - 21 Feb 2006 10:35 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

Hi,

I want a list in which I can add at any place, but whose size is not
statically known.  So after creating, if I do get(i) for an i for which
there is no value yet, I?d just get null, and if I do add(i, element)
when for some value < i no value is present yet, these values would just
all be null.  Is there something like this, or will I have to do it the
hard way with an ArrayList?

Thanks, H.
Signature

Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org

Wibble - 21 Feb 2006 14:00 GMT
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 10 lines]
>
> Thanks, H.
It sounds to me like ArrayList is the easy way.

Lisp lists dont directly support most of what
you want, functions do.  Its easy enough
to write a simple class implementing a cons
cell with a next pointer, and add whatever
'lisp' methods to that, but if all you need
is a list, go with the provided ones.
Robert Klemme - 21 Feb 2006 14:14 GMT
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 8 lines]
> all be null.  Is there something like this, or will I have to do it the
> hard way with an ArrayList?

AFAIK you'll have to do it your own - unless you find a lib out there that
does it.  However, you can inherit AbstractList and get a lot methods for
free.

Alternatively you could use a map with int as index, but unless you are on
1.5 you'll have to do the boxing yourself.  Note also, that boxing of
primitive values has some performance implications depending on your
application.

Kind regards

   robert
Stefan Ram - 21 Feb 2006 14:30 GMT
>I want a list in which I can add at any place, but whose size is not
>statically known.  So after creating, if I do get(i) for an i for which
>there is no value yet, I?d just get null, and if I do add(i, element)

 This has nothing to do with Lisp. Something similar is called
 a "sparse array". You could use a Map implementation in
 Java for this purpose, for example, "java.util.HashMap".

 I you really need Lisp, there are Java-libraries for it, like
 »Jatha«.

 A Lisp list is easily done:

private final int car; private final List cdr;
List( final int car, final List cdr ){ this.car = car; this.cdr = cdr; }

 But this is not what you asked for.
Roedy Green - 21 Feb 2006 19:36 GMT
On Tue, 21 Feb 2006 11:35:35 +0100, Hendrik Maryns
<hendrik_maryns@despammed.com> wrote, quoted or indirectly quoted
someone who said :

>I want a list in which I can add at any place, but whose size is not
>statically known.  So after creating, if I do get(i) for an i for which
>there is no value yet, I?d just get null, and if I do add(i, element)
>when for some value < i no value is present yet, these values would just
>all be null.  Is there something like this, or will I have to do it the
>hard way with an ArrayList?

see http://mindprod.com/jgloss/arraylist.html#GROWINGARRAYLIST

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Hendrik Maryns - 22 Feb 2006 10:04 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

Roedy Green schreef:
> On Tue, 21 Feb 2006 11:35:35 +0100, Hendrik Maryns
> <hendrik_maryns@despammed.com> wrote, quoted or indirectly quoted
[quoted text clipped - 8 lines]
>
> see http://mindprod.com/jgloss/arraylist.html#GROWINGARRAYLIST

Thanks Roedy, that is exactly what I need, with some more methods like
this for get and add, but I can add them myself.  I looked at the page
before, but have read over it.

H.
Signature

Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org

Roedy Green - 24 Feb 2006 14:23 GMT
On Wed, 22 Feb 2006 11:04:04 +0100, Hendrik Maryns
<hendrik_maryns@despammed.com> wrote, quoted or indirectly quoted
someone who said :

>Thanks Roedy, that is exactly what I need, with some more methods like
>this for get and add, but I can add them myself.  I looked at the page
>before, but have read over it.

Inherited get is ok, unless you want it to grow the array rather than
throw a subscript out of range.

inherited add should do fine.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 21 Feb 2006 19:39 GMT
On Tue, 21 Feb 2006 11:35:35 +0100, Hendrik Maryns
<hendrik_maryns@despammed.com> wrote, quoted or indirectly quoted
someone who said :

>I want a list in which I can add at any place, but whose size is not
>statically known.  So after creating, if I do get(i) for an i for which
>there is no value yet, I?d just get null, and if I do add(i, element)
>when for some value < i no value is present yet, these values would just
>all be null.  Is there something like this, or will I have to do it the
>hard way with an ArrayList?

see also http://mindprod.com/products1.html#LINKEDLIST

I wrote it for Java 1.0. It is implemented as a chain of objects, no
backing array like Sun's later version.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Hendrik Maryns - 22 Feb 2006 10:05 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

Roedy Green schreef:
> On Tue, 21 Feb 2006 11:35:35 +0100, Hendrik Maryns
> <hendrik_maryns@despammed.com> wrote, quoted or indirectly quoted
[quoted text clipped - 11 lines]
> I wrote it for Java 1.0. It is implemented as a chain of objects, no
> backing array like Sun's later version.

You must have meant http://mindprod.com/jgloss/linkedlist.html.

H.
Signature

Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org

Roedy Green - 24 Feb 2006 14:25 GMT
On Wed, 22 Feb 2006 11:05:22 +0100, Hendrik Maryns
<hendrik_maryns@despammed.com> wrote, quoted or indirectly quoted
someone who said :

>> see also http://mindprod.com/products1.html#LINKEDLIST
>>
>> I wrote it for Java 1.0. It is implemented as a chain of objects, no
>> backing array like Sun's later version.
>
>You must have meant http://mindprod.com/jgloss/linkedlist.html.

I meant http://mindprod.com/products2.html#LINKEDLIST
which the page you found links to. That is the download. I moved it to
the second string section.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.