- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Including one script in another
Mon, 2009-02-23, 19:04
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
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
Mon, 2009-02-23, 19:37
#2
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:
--
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
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
Mon, 2009-02-23, 19:57
#3
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.
Tue, 2009-02-24, 04:07
#4
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.
:)
Tue, 2009-02-24, 10:37
#5
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>
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.
:)
Tue, 2009-02-24, 17:07
#6
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:
--
__~O
-\ <, Christos KK Loverdos
(*)/ (*) http://ckkloverdos.com
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
Tue, 2009-02-24, 20:07
#7
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?
Wed, 2009-02-25, 00:27
#8
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". :-)
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.