Mission Objective of scalax

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

Mission Objective of scalax

by Jesse Eichar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have been thinking about the MO of scalax.  In my life it has been (to a large degree) a library for helping write scripts and generally overcome many of the common annoyances of Java.  Copying files and deleting diretories are the classic examples.  

As such I had a couple of ideas that I would like to see included in the library.  I am not asking anyone to write these.  I will do that when time permits.  I am just asking if there is interest.

So:

1.  A mechanism for executing processes.  The current one is quite hard to use and could be made much more functional in design. For example a function could be passed in for dealing with the Error stream
2.  A way to essentially do dynamic invocation.  As an example lets say we have an implicit conversion to a DynamicObject that has a --> operator (or maybe ~> ) or maybe we should skip the fancy sugar and just use invoke. So here is a small example

import scalax.reflect.DynamicObject._
val someObject = getSomeObject();
someObject ~> ("operate") (1,2,3)

this would run the operate method on someObject.


I think the simplified reflection would be handy because sometimes in scripting you just want to call a method and to heck with casting, type introspection and whatever else.  And everyone knows how difficult Java reflection is to use.

Comments? Ideas? Suggestions?

Jesse

Re: Mission Objective of scalax

by bord :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Jesse,
Read your post and Per your request to for comment? suggestions? ....
To be honest I;'ve only been hacking Scala since spring of this year and have not even looked at anything in scalax as I'm not sure i can make sense of the stuff there from the API docs.

In any case I've been busy redoing a large PERL script that purports to do CI building of software "modules" and have really spent bunches of time writing and re-writing (and with a lot of mistakes) a function (and helpers) for executing processes. I cant say its community-worthy but it is functional design at this point with one do everything "run" method returning Option[R] with R the expected return type from processing the std out of the processing.
(note that somehow I overcurried the run method too much also... in any case...)

private[Lib] def run[R](workingdir:Option[java.io.File], env:Map[String,String], args:St
ring*)(killHook: Option[Killable => Unit])(onErr:Option[java.io.InputStream => U
nit])(onOut:java.io.InputStream =>R):Option[R]

def run[R](args:String*)
    (onErr:Option[java.io.InputStream => Unit])(onOut:java.io.InputStream =>R):O
ption[R] = run(None, Map[String,String](), args:_*)(None)(onErr)(onOut)

and other overloadings where again some params are defaulted

I use these run methods in some places where i pass an onOut function that processes a line at a time. Other places I'll pass an onOut function that essentially buffers the whole std out to a
ByteArrayOutputStream to turn into a String output. Sometimes I have the onErr function just do nothing as note that passing "None" for it means that I want std err and std out combined which is different.



Jesse Eichar-2 wrote:
Hi,

I have been thinking about the MO of scalax.  In my life it has been  
(to a large degree) a library for helping write scripts and generally  
overcome many of the common annoyances of Java.  Copying files and  
deleting diretories are the classic examples.

As such I had a couple of ideas that I would like to see included in  
the library.  I am not asking anyone to write these.  I will do that  
when time permits.  I am just asking if there is interest.

So:

1.  A mechanism for executing processes.  The current one is quite  
hard to use and could be made much more functional in design. For  
example a function could be passed in for dealing with the Error stream
2.  A way to essentially do dynamic invocation.  As an example lets  
say we have an implicit conversion to a DynamicObject that has a -->  
operator (or maybe ~> ) or maybe we should skip the fancy sugar and  
just use invoke. So here is a small example

> import scalax.reflect.DynamicObject._
> val someObject = getSomeObject();
> someObject ~> ("operate") (1,2,3)

this would run the operate method on someObject.


I think the simplified reflection would be handy because sometimes in  
scripting you just want to call a method and to heck with casting,  
type introspection and whatever else.  And everyone knows how  
difficult Java reflection is to use.

Comments? Ideas? Suggestions?

Jesse