Hi Brian,

> Say I want to name my package 'Algs", so that my implementation of a
> LinkedStack would be a record Algs.LinkedStack.T (T is for type, more on
> that later). The only way I can see to do that now is to have a module Algs
> which contains all of my algorithms in one file. Is there any way that I
> can have that behavior (all modules accessible by Algs.Modname) and be able
> to split my implementation across files, like in Java, or like Ada package
> subunits?

I have a thought about constructing a module out of multiple Chapel source 
files.  It feels like a workaround, but you might be able to take 
advantage of Chapel's transitive module use.  That is, if your Algs 
module uses other modules, then to the user of the Algs module it will 
appear that those other modules' symbols are provided by Algs.


$ for i in *.chpl; do echo $i; cat $i; echo; done
main.chpl
use Algs;

proc main() {
  Mod1.foo();
  Mod2.bar();
}

Algs.chpl
module Algs {
  use Mod1wrap;
  use Mod2wrap;
}

Mod1wrap.chpl
module Mod1wrap {
  module Mod1 {
    proc foo() { writeln("foo()"); }
  }
}

Mod2wrap.chpl
module Mod2wrap {
  module Mod2 {
    proc bar() { writeln("bar()"); }
  }
}


fortytwo@magrathea:~/src/chpl/secondarymodules$ chpl *.chpl
fortytwo@magrathea:~/src/chpl/secondarymodules$ ./main -nl 1
foo()
bar()


(Though I can't get it to work having main() refer to the name in full: 
Algs.Mod1.foo())



Paul


On Wed, 21 Feb 2018, Brad Chamberlain wrote:

> 
> [The following message never showed up on chapel-users this week as intended
> by its author.  With his permission, I'm trying a re-send to see if
> chapel-users is working for me or not.]
> 
> -Brad
> 
> 
> ---------- Forwarded message ----------
> From: Brian Rogoff <brog...@gmail.com>
> Date: Mon, Feb 19, 2018 at 11:51 AM
> Subject: A few questions about Chapel modules
> To: chapel-users@lists.sourceforge.net
> 
> 
> Hi,
>     I started porting over some code from https://github.com/kevin-
> wayne/algs4 to learn Chapel better, and I have some questions. For those
> who haven't seen it, this is the Java code for Sedgewick's "Algorithms 4th
> Ed" and it's fairly plain Java code, not even using interfaces, which
> Chapel lacks, all that much. I'd like to match the structure of the Java
> code and the naming conventions as closely as is tasteful. I don't know how
> to do what I want and the spec is unenlightening so I'm hacking with 1.16.
> 
>     In Java we have packages and classes, and all of the library is in a
> package "edu.princeton.cs.algs4" using Java's reverse URL package naming.
> Say I want to name my package 'Algs", so that my implementation of a
> LinkedStack would be a record Algs.LinkedStack.T (T is for type, more on
> that later). The only way I can see to do that now is to have a module Algs
> which contains all of my algorithms in one file. Is there any way that I
> can have that behavior (all modules accessible by Algs.Modname) and be able
> to split my implementation across files, like in Java, or like Ada package
> subunits?
> 
>     I also noticed that Chapel doesn't seem to permit types and their
> parent module to have the same name. Originally I had tried to have a
> module Stack with a (record) type Stack like
> 
> module Stack {
>   class Node {
>     type ItemType; // type of item
>     ...
>   }
> 
>   record Stack {
>   }
> }
> 
> but the Chapel compiler rejects that. Is that supposed to be the behavior
> of modules? I settled on the OCaml-ish convention of naming the main type
> from the module "T" because of this, but I'd like to know if it's necessary.
> 
>   I think an example of how to organize multifile/multimodule libraries in
> Chapel would be enlightening. Packing everything into one file, as I see in
> the examples in the mason registry, is not a solution I'm comfortable with.
> 
> -- Brian
> 
> PS: Chapel could also do with some naming and formatting conventions. I'm
> trying to stick with Java-ish conventions (well, Java packages are
> typically lower cased and I haven't done that yet...) and "One True Brace
> Style" with non-optional braces (like Rust) and the Chapel code I read
> varies greatly in style.
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Chapel-users mailing list
> Chapel-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/chapel-users
> 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-users mailing list
Chapel-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to