New issue 9 by felipensp: Function pointer type
http://code.google.com/p/clever/issues/detail?id=9
Currently it's possible to use the function name as a variable name in the
code, but it actually does nothing.
$ ./clever -r 'import std;Int foo() { return 5; } println(foo);'
Comment #1 on issue 9 by felipensp: Function pointer type
http://code.google.com/p/clever/issues/detail?id=9
(No comment was entered for this change.)
Comment #2 on issue 9 by felipensp: Function pointer type
This would allow us to use callbacks (as JavaScript does) and so add new
features using those callbacks. I was thinking about a basic thread
implementation as an example.
Another example would be a Quick Sort algorithm, which requires a
comparator. In C (qsort) you can just give a function to be called as an
argument. In Clever we would pass the function variable.
Two questions:
1. What happens with generic types, like in qsort() (C) paramaters (void*)?
I've found two solutions so far:
a) Use a generic object type (let's call Object), so that the function
would receive 2 arguments of type Object.
b) Force the correct type in the callback, so there's no need for
type-casting (the function would receive 2 parameters from type T). The
language should check the types from both sides to make sure that
everything has the same type T.
2. What happens with the number of arguments in callbacks? If my function
was expecting a callback that can receive 2 args, we shouldn't be able to
pass a function that can receive only one argument, neither one with 3.