Easy serialization

View: New views
3 Messages — Rating Filter:   Alert me  

Easy serialization

by Arnaud Bailly :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

Hello,
In the process of writing a piece of software, I ran into the problem
of serializing or interacting with the user/outside world and am
looking for a scala(tm) way to deal with that.

I have a class LSystem which I can initialize using "syntactic sugar"
like:

  new LSystem(
    'A' -> "AB",
    'B' -> "BB")

I would like to write a small program that read a textual description
of a l-system and creates a scala object from it. I was thinking of
at least three possible ways of doing that:
 - write a parser: a bit overkill...
 - lift java serialization (eg. xstream or anything similar): not very
 user friendly
 - use some form dynamic evaluation like in a scala console: I would
 create a l-system object then "evaluate" the rules in its context.

Is it possible (and easy) to achieve the latter ? Is there another way
I might be skipping ?

Thanks ,
--
Arnaud Bailly, PhD
OQube - Software Engineering
http://www.oqube.com


Re: Easy serialization

by Stanislas Klimoff-2 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

I'm not sure if that's what you mean...
You should be able to create class LSystem that takes a variable number of LRules in the constructor. LRule class would implement -> method, that sets up the rvalue. You'll also need an implicit def that converts a string to a LRule.

The only thing that (I believe) you won't be able to achieve is to use the 'symbol' notation. As per my understanding, apostrophe is reserved to represent symbols in Scala.

HTH, Stan

On 1/11/08, Insitu <abailly@...> wrote:
Hello,
In the process of writing a piece of software, I ran into the problem
of serializing or interacting with the user/outside world and am
looking for a scala(tm) way to deal with that.

I have a class LSystem which I can initialize using "syntactic sugar"
like:

  new LSystem(
    'A' -> "AB",
    'B' -> "BB")

I would like to write a small program that read a textual description
of a l-system and creates a scala object from it. I was thinking of
at least three possible ways of doing that:
- write a parser: a bit overkill...
- lift java serialization (eg. xstream or anything similar): not very
user friendly
- use some form dynamic evaluation like in a scala console: I would
create a l-system object then "evaluate" the rules in its context.

Is it possible (and easy) to achieve the latter ? Is there another way
I might be skipping ?

Thanks ,
--
Arnaud Bailly, PhD
OQube - Software Engineering
http://www.oqube.com




--
Best wishes,
  Stan Klimoff
  Grid Dynamics Consulting

Re: Easy serialization

by David Bernard-3 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

Insitu wrote:

> Hello,
> In the process of writing a piece of software, I ran into the problem
> of serializing or interacting with the user/outside world and am
> looking for a scala(tm) way to deal with that.
>
> I have a class LSystem which I can initialize using "syntactic sugar"
> like:
>
>   new LSystem(
>     'A' -> "AB",
>     'B' -> "BB")
>
> I would like to write a small program that read a textual description
> of a l-system and creates a scala object from it. I was thinking of
> at least three possible ways of doing that:
>  - write a parser: a bit overkill...
>  - lift java serialization (eg. xstream or anything similar): not very
>  user friendly
>  - use some form dynamic evaluation like in a scala console: I would
>  create a l-system object then "evaluate" the rules in its context.

Write a parser or "dynamic evaluation" are for reading stream -> object
How do you plan to write (object -> stream) ?

I did some quick test and xstream work nicely with case class (write and read).
Why did you say "not user friendly" ?

> Is it possible (and easy) to achieve the latter ? Is there another way
> I might be skipping ?
>
> Thanks ,

/davidB
LightInTheBox - Buy quality products at wholesale price!