Module Pattern ============== ```Example from 1 languages: Java // Package = directory. Java classes can be grouped together in packages. A package name is the same as the directory (folder) name which contains the .java files. You declare packages when you define your Java program, and you name the packages you want to use from other libraries in an import statement. // The first statement, other than comments, in a Java source file, must be the package declaration. // Following the optional package declaration, you can have import statements, which allow you to specify classes from other packages that can be referenced without qualifying them with their package. // This source file must be Drawing.java in the illustration directory. package illustration; import java.awt.*; public class Drawing { // ... } ``` ```Example from 1 languages: C# // In C#, namespaces are the semi-equivalent of Java's packages. namespace com.test { class Test {} } ``` ```Example from 1 languages: Julia module MyModule using Lib using BigLib: thing1, thing2 import Base.show export MyType, foo struct MyType x end bar(x) = 2x foo(a::MyType) = bar(a.x) + 1 show(io::IO, a::MyType) = print(io, "MyType $(a.x)") end ``` ```Example from 1 languages: Racket (module nest racket (provide (for-syntax meta-eggs) (for-meta 1 meta-chicks) num-eggs) (define-for-syntax meta-eggs 2) (define-for-syntax meta-chicks 3) (define num-eggs 2)) ``` ```Example from 1 languages: Fortran module constants implicit none real, parameter :: pi = 3.1415926536 real, parameter :: e = 2.7182818285 contains subroutine show_consts() print*, "Pi = ", pi print*, "e = ", e end subroutine show_consts end module constants program module_example use constants implicit none real :: x, ePowerx, area, radius x = 2.0 radius = 7.0 ePowerx = e ** x area = pi * radius**2 call show_consts() print*, "e raised to the power of 2.0 = ", ePowerx print*, "Area of a circle with radius 7.0 = ", area end program module_exampl ``` ```Example from 1 languages: Chapel module ``` ```Example from 1 languages: OCaml (* In OCaml, every piece of code is wrapped into a module. *) (* amodule.ml *) let hello () = print_endline "Hello" (* bmodule.ml *) Amodule.hello () ``` ```Example from 1 languages: Gleam // Gleam’s file is a module and named by the file name (and its directory path). Since there is no special syntax to create a module, there can be only one module in a file. // in file main.gleam import wibble // if wibble was in a folder called `lib` the import would be `lib/wibble` pub fn main() { wibble.identity(1) } ``` ```Example from 1 languages: C3 module my_module::submodule; ... ``` ```Example from 1 languages: Speedie module App function Path (|string|) // return the app's path here ``` * Languages *with* Module Pattern include Java, C#, Julia, Racket, Fortran, Chapel, OCaml, Gleam, C3, progsbase, Aardvark, Speedie, Bio * View all concepts with or missing a *hasModules* measurement http://pldb.info/../lists/explorer.html#columns=rank~id~appeared~tags~creators~hasModules&searchBuilder=%7B%22criteria%22%3A%5B%7B%22condition%22%3A%22null%22%2C%22data%22%3A%22hasModules%22%2C%22origData%22%3A%22hasModules%22%2C%22type%22%3A%22num%22%2C%22value%22%3A%5B%5D%7D%5D%2C%22logic%22%3A%22AND%22%7D missing http://pldb.info/../lists/explorer.html#columns=rank~id~appeared~tags~creators~hasModules&searchBuilder=%7B%22criteria%22%3A%5B%7B%22condition%22%3A%22!null%22%2C%22data%22%3A%22hasModules%22%2C%22origData%22%3A%22hasModules%22%2C%22type%22%3A%22num%22%2C%22value%22%3A%5B%5D%7D%5D%2C%22logic%22%3A%22AND%22%7D with * Read more about Module Pattern on the web: 1. https://en.wikipedia.org/wiki/Module_pattern 1. Built with Scroll v178.2.3