Issue 9 in clever: Function pointer type

2 views
Skip to first unread message

cle...@googlecode.com

unread,
Jul 19, 2011, 11:04:06 PM7/19/11
to cleve...@googlegroups.com
Status: New
Owner: felipensp
Labels: Type-Defect Priority-Medium

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);'

cle...@googlecode.com

unread,
Jul 19, 2011, 11:08:07 PM7/19/11
to cleve...@googlegroups.com
Updates:
Labels: -Type-Defect Type-Todo

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.)

cle...@googlecode.com

unread,
Jul 19, 2011, 11:20:12 PM7/19/11
to cleve...@googlegroups.com
Updates:
Labels: -Type-Todo Type-TODO

Comment #2 on issue 9 by felipensp: Function pointer type

cle...@googlecode.com

unread,
Jul 19, 2011, 11:37:18 PM7/19/11
to cleve...@googlegroups.com

Comment #3 on issue 9 by cado...@gmail.com: Function pointer type
http://code.google.com/p/clever/issues/detail?id=9

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.

Reply all
Reply to author
Forward
0 new messages