Wednesday, November 02, 2005

Subroutines / Functions

NOTE: I am not sure how functions/subroutines will be defined, as the following will show. So the actual design may, or may not, resemble anything in this post.


Functions/subroutines will probably be very different than what most people would be used to.

For example, I want to be able to define two functions that return two different types of data, but have the same parameters.

int main(){ return 0; }
char main(){ return "0"; }

I always like being able to have two different things returned depending on the context, when working in Perl5.

There will be times where it would be impossible to do this, but mainly it would only be when calling functions from libraries, or when implementing outside.

I also want to be able to have subroutines that don't have any particular return type, but that would automatically be converted the way you think it would.

sub main(){ return 0; }

char c = main();
int i = main();

The arguments for these functions will also come in several different flavors. There of course be functions that take only certain types of values, and also some that take in a varying number of arguments that are all of the same type, and still others that will take varying types.
sub main( int i ){...}
sub main( @int args ){...}
sub main( @ args ){...}

String Management

I plan on having the ability to work with strings without necessarily knowing how they are encoded, and I want to be able to easily convert between different encodings.

The way this could be handled may be similar in design to the way Parrot handles strings. It probably should have a way to implement this functionality in a pluggable way.

It might need to be integrated with IO handling, which I also plan on having higher level constructs.

I hope that it would be simple to read in different encodings and slmost never having to dealing with the minor details.