Modulinos: Difference between revisions

Content added Content deleted
(Added Go)
Line 534: Line 534:


cr .( Why aren't you running this as a script? It only provides a constant.)</lang>
cr .( Why aren't you running this as a script? It only provides a constant.)</lang>

=={{header|Go}}==
Go doesn't support scripted main directly.

Although the [https://github.com/mcandre/modulinos examples] linked to above include an example for Go, this is only a work around, not an emulation. To emulate a modulino, we need to proceed as in the [[https://rosettacode.org/wiki/Executable_library#Go Executable library]] task and split the 'main' package into two.

First create these two files in the 'modulino' directory:
<lang go>// modulino.go
package main

import "fmt"

func MeaningOfLife() int {
return 42
}

func libMain() {
fmt.Println("The meaning of life is", MeaningOfLife())
}</lang>

<lang go>// modulino_main.go
package main
func main() {
libMain()
}</lang>

To emulate a modulino:
{{out}}
<pre>
$ go run modulino

The meaning of life is 42
</pre>

Now create this file in the 'mol' directory:
<lang go>// mol.go
package main

import "fmt"

func main() {
fmt.Println("The meaning of life is still", MeaningOfLife())
}</lang>
and copy modulino.go to the 'mol' directory. The library can then be used in the 'normal' way:
{{out}}
<pre>
$ go run mol

The meaning of life is still 42
</pre>


=={{header|Groovy}}==
=={{header|Groovy}}==