jckarter / clay

The Clay programming language
http://claylabs.com/clay
Other
404 stars 34 forks source link

drop Function, rename FunctionBody -> Function #474

Closed stepancheg closed 11 years ago

stepancheg commented 11 years ago

If someone needs Function to be refcounted, Function can be explicitly wrapped in sharedpointer, like this:

var functionPtr = new(Function((x: Int) -> x * 2));
var thirtyFour = functionPtr^(17);

Note that sharedpointers are not thread-safe (thus Function weren't thread-safe until this patch), so simple function copying could cause memory problems.

jckarter commented 11 years ago

Sounds good. Separating the ownership policy from Function also allows you to use it with unique pointers, which is useful.