call

call function with given list of parameters


Parameters

call function :string :literal :function
     params :block

Attributes

external:stringpath to external library
expect:typeexpect given return type

Returns

  • :any

Examples

copy
multiply: function [x y][ x * y ] call 'multiply [3 5] ; => 15

copy
call $[x][x+2] [5] ; 7

copy
; Calling external (C code) functions ; compile with: ; clang -c -w mylib.c ; clang -shared -o libmylib.dylib mylib.o ; #include ; ; void sayHello(char* name){ ; printf("Hello %s!\n", name); ; } ; ; int doubleNum(int num){ ; return num * 2; ;} ; call an external function directly call.external: "mylib" 'sayHello ["John"] ; map an external function to a native one doubleNum: function [num][ ensure -> integer? num call .external: "mylib" .expect: :integer 'doubleNum @[num] ] loop 1..3 'x [ print ["The double of" x "is" doubleNum x] ]

Related