Delight

Yigal Chripun yigal100 at gmail.com
Thu Sep 25 13:06:51 PDT 2008


bearophile wrote:
> Yigal Chripun:
>> From what I understood, global functions are allowed.
> 
> This is the (not nice to me) hello world:
> 
> import dlt.io
> 
> class Main:
> 	void main(Printer stdout):
> 		stdout("Hello World!\n")
> 
> 
> So I presume you need a least one class into your code.
> 
> Bye,
> bearophile

You're confusing two separate issues.
see: http://delight.sourceforge.net/syntax.html
there _are_ top level functions in delight.

from what I understand the Main class is due to the IoC feature and the
fact that you want to pass "global" state to your program.
here's a snippet from the above link:

# Define a class
class Main:
	# An argument that must be passed
	# when constructing this Class
	in Printer stdout

	void main():
		stdout(addNewline(greeting))

So you construct a Main instance and pass it all the needed outside
state, than you use the main method to start your program.
another option, as in your example from the "overview" page is to pass
the outside state directly as parameters to the main method.

Java is similar with this since it has dynamic class-loading - i.e. all
your classes can define a main function and you specify to the JVM which
class to load. this has other problems in java but the general idea (not
 the specific java implementation) is a good thing. if you try a similar
thing in D - compile two D files which both define main - you'll get an
error.


More information about the Digitalmars-d-announce mailing list