call

call function with given list of parameters


Parameters

call function :string :word :literal :pathliteral :function :method
     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 ; ; NOTE: ; * If you're using GCC, just replace `clang` by `gcc` ; * If you're not on MacOS, replace your `dylib` by the right extension ; normally they can be `.so` or `.dll` in other Operational Systems. ; #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