From: ········@acm.org
Subject: s-expression library for Java?
Date: 
Message-ID: <1118408685.776424.204200@g49g2000cwa.googlegroups.com>
Hello,

  I am looking for an s-expression library for Java. Something tailored
specifically for this, I don't want to be calling Kawa from Java, for
example.

Thanks in advance,

Fernando Mato Mira

From: Scott G. Miller
Subject: Re: s-expression library for Java?
Date: 
Message-ID: <F-adnU54sLw7CDTfRVn-pA@giganews.com>
········@acm.org wrote:
> Hello,
> 
>   I am looking for an s-expression library for Java. Something tailored
> specifically for this, I don't want to be calling Kawa from Java, for
> example.
> 
> Thanks in advance,
> 
> Fernando Mato Mira
> 

You can strip out the "reader" and "data" packages from SISC to do what 
you want.  It should be very little work as they are only loosely tied 
to SISC itself.

	Scott
From: ········@acm.org
Subject: Re: s-expression library for Java?
Date: 
Message-ID: <1118670703.993070.30930@g44g2000cwa.googlegroups.com>
Well, finally I tried using Kawa, but it represents lists as TreeLists,
instead of just using Pairs, so I guess now I have to convert all the
code to use SISC.
From: Per Bothner
Subject: Re: s-expression library for Java?
Date: 
Message-ID: <42B52D4F.1060106@bothner.com>
········@acm.org wrote:
> Well, finally I tried using Kawa, but it represents lists as TreeLists,
> instead of just using Pairs, 

No, it doesn't.  A pair (cons cell) is implemented using the class 
gnu.lists.Pair:

package gnu.lists;
public class Pair extends LList implements Externalizable
{
    public Object car;
    public Object cdr;
    ...
}

The empty list is the static object LList.Empty.

A TreeList is a very different and more complicated (and general) data 
structure.
From: William Bland
Subject: Re: s-expression library for Java?
Date: 
Message-ID: <pan.2005.06.20.17.30.18.102848@abstractnonsense.com>
On Mon, 20 Jun 2005 01:36:16 -0700, matomira wrote:

> Per Bothner wrote:
>> ········@acm.org wrote:
>> > Well, finally I tried using Kawa, but it represents lists as TreeLists,
>> > instead of just using Pairs,
>>
>> No, it doesn't.  A pair (cons cell) is implemented using the class
>> gnu.lists.Pair:
>>
>> package gnu.lists;
>> public class Pair extends LList implements Externalizable
>> {
>>     public Object car;
>>     public Object cdr;
>>     ...
>> }
>>
>> The empty list is the static object LList.Empty.
>>
>> A TreeList is a very different and more complicated (and general) data
>> structure.
> 
> 
> Well, I read a list structure from a string and it gave me a TreeList.

There is also a sexp reader/writer in TINA
(http://abstractnonsense.org/tina.html).  It's released under the BSD
license, and it tries to use standard Java types where possible - so it
simply reads a Java.util.LinkedList (which does of course have the
disadvantage that it cannot read dotted pairs).

Best wishes,
		Bill.
From: Ray Blaak
Subject: Re: s-expression library for Java?
Date: 
Message-ID: <u1x6wltwj.fsf@STRIPCAPStelus.net>
···@zedat.fu-berlin.de (Stefan Ram) writes:
> class List
> { final java.util.List me;
>   final int offset;
>   List( final Object[] me )
>   { this.me = java.util.Arrays.asList( me ); this.offset = 0; }
>   List( final java.util.List me )
>   { this.me = me; this.offset = 0; }
>   List( final List me, final int offset )
>   { this.me = me.me; this.offset = me.offset + offset; }
>   Object get( final int offset )
>   { return this.me.get( this.offset + offset ); }
>   Object car()
>   { return this.get( 0 ); }
>   List cdr()
>   { return new List( this, 1 ); }}
> 

1) call it something other than List, so as to make it easier to work with
   existing Java code. LList is better. java.util.* classes are too prevalent
   to force people to use fully qualified names for them.

2) Don't use Lisp ...)) close-paren style for Java; that makes Java code
   harder to read, since its usual idiom is different. Use proper Java
   whitespace and line separation.

3) Chain constructors to improve maintainence, e.g. core field assignments are
   in one place.

4) Use sublists instead of explicit offsets to simplify things.

5) Don't forget about the null case for the last item in a proper list.

6) To truly model Lisp lists, you need to allow for improper lists, and so
   need a version of cdr that return a pure Object.

Anyway, my suggested code clean up for the existing code is:
  
import java.util.*;

/**
* Describes a list that can masquerade as a (proper) Lisp list.
*/
public class LList extends AbstractList
{
  final private List items;

  public LList(List items)
  {
    this.items = items;
  }

  public LList( Object[] items )
  {
    this(Arrays.asList(items));
  }
  
  public LList(List items, int fromOffset)
  {
    this(items.subList(fromOffset, items.size()));
  }

  public Object car() {return this.get(0);}

  public LList cdr()
  {
    return (size() >= 2) ? new LList(this.items, 1) : null;
  }

  // AbstractList implementation:
  public Iterator iterator() {return items.iterator();}
  public int size() {return items.size();}
  public Object get(int atIndex) {return items.get(atIndex);}
}


-- 
Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
········@STRIPCAPStelus.net                    The Rhythm has my soul.
From: Edi Weitz
Subject: Re: s-expression library for Java?
Date: 
Message-ID: <uslzqnyf0.fsf@agharta.de>
On 10 Jun 2005 06:04:45 -0700, ········@acm.org wrote:

>   I am looking for an s-expression library for Java. Something tailored
> specifically for this, I don't want to be calling Kawa from Java, for
> example.

If I enter "java s-expressions" into Google the first hit I get is
this one:

  <http://www-106.ibm.com/developerworks/library/j-diag1211.html?n-j-12131>

Some of the other links also look promising.

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Robert Maas, see http://tinyurl.com/uh3t
Subject: Re: s-expression library for Java?
Date: 
Message-ID: <REM-2005jun10-003@Yahoo.Com>
> From: ········@acm.org
Your question is too vague:
> I am looking for an s-expression library for Java.

An s-expression is nothing more than a string of characters that
satisfy a particular syntactic requirement. Do you merely want a method
to recognize whether a given string is or is not an s-expression, or do
you want something more interesting such as deserializing such an
expression into some kind of pointy structure, and then serializing
such a pointy structure back out to an s-expression again? (I've used
java jargon, deserialize/serialize, instead of lisp jargon,
read/print.) In either case, what sorts of atoms do you want to allow
inside your s-expressions? If you want (de)serialization, do you have
any particular requirement for the form of the internal pointy
structure, for example do you require each node to be a particular
2-container, or do you require the entire CDR-chain of a level of list
structure to be a single n-container, or do you not care and would
adapt to anything available?

I wrote myself a class MyList which is simply a wrapper around Vector,
and a class Sexpr1 which has a static method toSexpr to serialize a
MyList structure or any of several built-in types to yield an
s-expression, and some parser classes to deserialize an s-expression
back into a MyList. The only atoms allowed are Strings and maybe some
primitive types or wrappers thereof, so I don't believe this would
suffice for your needs.
From: Jim White
Subject: Re: s-expression library for Java?
Date: 
Message-ID: <g%Yre.460$wV5.333@fed1read06>
········@acm.org wrote:

> Hello,
> 
>   I am looking for an s-expression library for Java. Something tailored
> specifically for this, I don't want to be calling Kawa from Java, for
> example.
> 
> Thanks in advance,
> 
> Fernando Mato Mira
> 

Here is some code I wrote several years ago.  It is pretty basic but
does implement Java Collections.  The license is LGPL.

http://www.pagesmiths.com/downloads/sexp.tar.gz

Jim White