Identifiers in `_fun`

I typed this in the repl and an error was raised:

> (require ffi/unsafe)
> (_fun (f) :: ((_array/list _int (length f)) = f) -> _int)
f: undefined;
 cannot reference an identifier before its definition
  in module: top-level
 [,bt for context]

It seems that the identifier f in the type expression is not bound and I have to do something else to fix the scope.

How to use the _array/list elegantly?

I'm not sure what the intended semantics of the function type you're describing are, but you have the syntax of _fun incorrect. The type of f needs to needs to be specified like this: (f : <type here>) and there's no use of ::.

1 Like

The argument names (eg, f) are not in scope in the type expressions. It would be strange for the calling convention of a function to change depending on the actual values passed to it. The _fun syntax is syntactic sugar for _cprocedure, which just takes a list of input types.

I believe _array/list is mainly for use within define-cstruct. For function calls, C passes an array argument as a pointer, so you probably just want to use _list instead, as in (_list i _int).

1 Like