Examples

Hello World

hello.morpho:

"hello.mexe" = main in
{{
main = fun()
{
	writeln("Hello World!");
};
}}
*
BASIS
;

Compile & execute:

hhg@hhg:~/morpho/examples$ morpho -c hello.morpho
Reused 551 out of 792 operations, 241 operation objects used.
Reuse ratio is 70%
hhg@hhg:~/morpho/examples$ morpho hello
Hello World!
hhg@hhg:~/morpho/examples$ 

List & map

map.morpho:

"map.mexe" = main in
!
{{
map = fun(f,lst)
{
	lst==null && (return []);
	f(head(lst)) : map(f,tail(lst));
};

main = fun()
{
	var lst = [1,2,3,4,5];
	var f = fun(x) { x*x; };

	writeln(map(f,lst));
};
}}
*
BASIS
;

Compile & execute:

hhg@hhg:~/morpho/examples$ morpho -c map.morpho
Reused 579 out of 836 operations, 257 operation objects used.
Reuse ratio is 69%
hhg@hhg:~/morpho/examples$ morpho map
[1,4,9,16,25]
hhg@hhg:~/morpho/examples$