Function prototype: Difference between revisions
Content added Content deleted
(→ES6) |
|||
Line 614: | Line 614: | ||
l.pop(); // 15 |
l.pop(); // 15 |
||
l.length; // 2 |
l.length; // 2 |
||
</lang> |
|||
=={{header|Julia}}== |
|||
Julia does not need or use function prototypes in general. Generic functions are further specialized as to argument type and return type during just-in-time compilation if required. Julia can protoype its functions for passing its fuctions to extrenal languages such as C with the @cfunction macro: |
|||
<lang julia>julia > function mycompare(a, b)::Cint |
|||
(a < b) ? -1 : ((a > b) ? +1 : 0) |
|||
end |
|||
mycompare (generic function with 1 method) |
|||
</lang> |
|||
Using @cfunction to create a prototype for passing this to C's quicksort: |
|||
<lang julia>julia> mycompare_c = @cfunction(mycompare, Cint, (Ref{Cdouble}, Ref{Cdouble})) |
|||
</lang> |
</lang> |
||