[Swift-user] import position in swift script

Max Hutchinson maxhutch at gmail.com
Thu Jun 18 14:48:04 CDT 2015


I agree that it is a no interface function call.  Maybe this is also
helpful with not needing to explicitly collect outputs to get staged out?
My understanding is that If run.swift contains a bunch of nested loops, one
would have declare a bunch of [auto] outputs and remember to append
everything to them (or they could be considered tmps and not staged out).
There's value to being forced to be thoughtful, but it might also be nice
to start with the trailing import while prototyping/debugging a script and
then switch to a wrapper after the dust has settled.

I'm focusing on direct staging, so the wrapper was straightforward.  For
reference:
https://github.com/maxhutch/nek-swift/blob/alcf/debug.swift
https://github.com/maxhutch/nek-swift/blob/alcf/nek.swift

If imports are only going to be supported in the preamble, could that be
added to the docs?
http://swift-lang.org/guides/trunk/userguide/userguide.html#_imports


On Thu, Jun 18, 2015 at 2:20 PM Mihael Hategan <hategan at mcs.anl.gov> wrote:

> Hi,
>
> I don't think imports were meant to be used as a templating scheme,
> which is why they are restricted to be only at the start of a script.
> The alternative amounts to a dynamically scoped, no interface function
> call. So I don't think avoiding argument list bloat is a good enough
> reason to allow that, especially when you can package complex argument
> lists in a structure.
>
> Are the defs just values or do they also define behavior/functions?
>
> Mihael
>
> On Thu, 2015-06-18 at 18:18 +0000, Max Hutchinson wrote:
> > Not scattered; at the end.  I will have ~10 use cases, each written as a
> > different defs file (i.e. defs_a.swift, defs_b.swift, etc).  For each
> > use-case, the run.swift, which is a big foreach loop, is the same.  Given
> > this structure, I can think of at least 4 organizations:
> >  1) run.swift imports "defs_a" or "defs_b".  To change use cases, the
> > import in run.swift is edited.  This is what I currently do but forces me
> > to either serialize inter-script execution or edit scripts that are in
> the
> > process of being executed.
> >  2) defs_a.swift, defs_b.swift, etc import "run".  This seems clean and
> is
> > what I want to do.
> >  3) Wrapper scripts are created to contain both imports (i.e.
> a_wrap.swift
> > : ```import "defs_a"; import "run"```).  This currently works, but
> results
> > in script bloat.
> >  4) Wrap the contents of run.swift in a procedure, import it at the top
> of
> > defs_{a,b,...}.swift, but then call it at the bottom.  This is surely the
> > "right" way to do it, but its more effort and could have argument list
> > bloat.
> > Since each of these option is semantically identical, why not allow the
> > user to pick their preference?
> >
> > On Thu, Jun 18, 2015 at 1:07 PM Mihael Hategan <hategan at mcs.anl.gov>
> wrote:
> >
> > > Yes, but I don't think it should.
> > >
> > > Why is it important to have import statements scattered through the
> > > script?
> > >
> > > Mihael
> > >
> > > On Thu, 2015-06-18 at 17:58 +0000, Max Hutchinson wrote:
> > > > Could that constraint be relaxed?
> > > >
> > > > On Thu, Jun 18, 2015 at 12:47 PM Mihael Hategan <hategan at mcs.anl.gov
> >
> > > wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > Yes. Imports must come before other types of statements.
> > > > >
> > > > > Mihael
> > > > >
> > > > > On Thu, 2015-06-18 at 17:20 +0000, Max Hutchinson wrote:
> > > > > > Do all import statements need to come before executable
> statements?
> > > > > >
> > > > > > I have two scripts: defs.swift and run.swift.  If run.swift
> starts
> > > with
> > > > > > import "defs";
> > > > > > then everything works fine.  If instead defs.swift ends with
> > > > > > import "run";
> > > > > > I get this error:
> > > > > > Swift trunk git-rev: 1d512cbda070d363e8ec3cf16e77dfcddc6e66cb
> > > > > heads/master
> > > > > > 6377
> > > > > > RunID: run011
> > > > > > Could not compile SwiftScript source: line 24:12: unexpected
> token: ;
> > > > > > where line 24 is:
> > > > > > int foo = 1;
> > > > > >
> > > > > > Thanks,
> > > > > > Max
> > > > > > _______________________________________________
> > > > > > Swift-user mailing list
> > > > > > Swift-user at ci.uchicago.edu
> > > > > >
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-user
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-user/attachments/20150618/be170aa9/attachment.html>


More information about the Swift-user mailing list