This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Including one script in another

8 replies
Dean Wampler
Joined: 2008-12-26,
User offline. Last seen 42 years 45 weeks ago.
Is it possible to include/invoke one Scala script in another? I haven't found a way.

TIA,
dean

--
Dean Wampler
twitter: @deanwampler, @chicagoscala
http://groups.google.com/group/chicagoscala
http://www.objectmentor.com
http://www.polyglotprogramming.com
http://www.aspectprogramming.com
http://aquarium.rubyforge.org
http://www.contract4j.org
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Including one script in another

On Mon, Feb 23, 2009 at 12:01:21PM -0600, Dean Wampler wrote:
> Is it possible to include/invoke one Scala script in another? I haven't
> found a way.

Runtime.getRuntime.exec("scala -i " + script)

Okay, maybe not exactly what you wanted, although it does meet the "invoke" test. I am looking over related stuff so if you want
to outline exactly what you'd hope to achieve I will see what I can do.

Dean Wampler
Joined: 2008-12-26,
User offline. Last seen 42 years 45 weeks ago.
Re: Including one script in another
Thanks. Agreed that it's not pretty ;)

I have a very simple need in mind. I have a few scripts that have some common code, like variable and function definitions. I would like to put those in one file and have each script "include" that file. The parser would parse the included script just as if its contents were actually written in the enclosing script.

dean

On Mon, Feb 23, 2009 at 12:13 PM, Paul Phillips <paulp@improving.org> wrote:
On Mon, Feb 23, 2009 at 12:01:21PM -0600, Dean Wampler wrote:
> Is it possible to include/invoke one Scala script in another? I haven't
> found a way.

Runtime.getRuntime.exec("scala -i " + script)

Okay, maybe not exactly what you wanted, although it does meet the "invoke" test.  I am looking over related stuff so if you want
to outline exactly what you'd hope to achieve I will see what I can do.

--
Paul Phillips      | Every election is a sort of advance auction sale
Analgesic          | of stolen goods.
Empiricist         |     -- H. L. Mencken
up hill, pi pals!  |----------* http://www.improving.org/paulp/ *----------



--
Dean Wampler
twitter: @deanwampler, @chicagoscala
http://groups.google.com/group/chicagoscala
http://www.objectmentor.com
http://www.polyglotprogramming.com
http://www.aspectprogramming.com
http://aquarium.rubyforge.org
http://www.contract4j.org
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Including one script in another

On Mon, Feb 23, 2009 at 12:19:41PM -0600, Dean Wampler wrote:
> I have a very simple need in mind. I have a few scripts that have some
> common code, like variable and function definitions. I would like to put
> those in one file and have each script "include" that file. The parser would
> parse the included script just as if its contents were actually written in
> the enclosing script.

As far as I can see the only way this differs from importing the contents of an object is that you want the compilation to happen
on the fly. That should be doable.

hrj
Joined: 2008-09-23,
User offline. Last seen 4 years 3 weeks ago.
Re: Including one script in another

Dean Wampler wrote:

> Thanks. Agreed that it's not pretty ;)
>
> I have a very simple need in mind. I have a few scripts that have some
> common code, like variable and function definitions. I would like to put
> those in one file and have each script "include" that file. The parser
> would parse the included script just as if its contents were actually
> written in the enclosing script.

Hmm.. thinking out of the box, in a quick and dirty way:

You could use the C pre-processor

#include "def.scala"

If only scala could accept input from stdin, you could chain the CPP with scala without involving any temporary files.

:)

Ricky Clarkson
Joined: 2008-12-19,
User offline. Last seen 3 years 2 weeks ago.
Re: Re: Including one script in another
Freemarker or m4 are probably better options.  In particular, the C preprocessor doesn't allow for newlines in the output, which can be useful to have.

2009/2/24 Harshad <harshad.rj@gmail.com>
Dean Wampler wrote:

> Thanks. Agreed that it's not pretty ;)
>
> I have a very simple need in mind. I have a few scripts that have some
> common code, like variable and function definitions. I would like to put
> those in one file and have each script "include" that file. The parser
> would parse the included script just as if its contents were actually
> written in the enclosing script.

Hmm.. thinking out of the box, in a quick and dirty way:

You could use the C pre-processor

#include "def.scala"

If only scala could accept input from stdin, you could chain the CPP with scala without  involving any temporary files.

:)



loverdos
Joined: 2008-11-18,
User offline. Last seen 2 years 27 weeks ago.
Re: Re: Including one script in another
I was just wondering, since the interactive interpreter supports the ":load" command, how terrible a hack would it be to enable (I do not know difficult, implementaton-wise, this might be) the feature when running a scala script?

On Tue, Feb 24, 2009 at 11:29 AM, Ricky Clarkson <ricky.clarkson@gmail.com> wrote:
Freemarker or m4 are probably better options.  In particular, the C preprocessor doesn't allow for newlines in the output, which can be useful to have.

2009/2/24 Harshad <harshad.rj@gmail.com>
Dean Wampler wrote:

> Thanks. Agreed that it's not pretty ;)
>
> I have a very simple need in mind. I have a few scripts that have some
> common code, like variable and function definitions. I would like to put
> those in one file and have each script "include" that file. The parser
> would parse the included script just as if its contents were actually
> written in the enclosing script.

Hmm.. thinking out of the box, in a quick and dirty way:

You could use the C pre-processor

#include "def.scala"

If only scala could accept input from stdin, you could chain the CPP with scala without  involving any temporary files.

:)






--
 __~O
-\ <,       Christos KK Loverdos
(*)/ (*)      http://ckkloverdos.com
David Hall 3
Joined: 2009-02-19,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Including one script in another

On Tue, Feb 24, 2009 at 7:55 AM, Christos KK Loverdos
wrote:
> I was just wondering, since the interactive interpreter supports the ":load"
> command, how terrible a hack would it be to enable (I do not know
> difficult, implementaton-wise, this might be) the feature when running a
> scala script?

or even allowing the -i command for scripts?

DRMacIver
Joined: 2008-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Including one script in another

On Tue, Feb 24, 2009 at 3:55 PM, Christos KK Loverdos <loverdos@gmail.com> wrote:
I was just wondering, since the interactive interpreter supports the ":load" command, how terrible a hack would it be to enable (I do not know difficult, implementaton-wise, this might be) the feature when running a scala script?

It should be noted that currently there is almost no resemblance between the interpreter and script runner implementations. They do very different things.

It should further be noted that the answer is "very". :-)

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland