Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFI overloading and documentation #88

Open
quasilyte opened this issue Jul 5, 2017 · 0 comments
Open

FFI overloading and documentation #88

quasilyte opened this issue Jul 5, 2017 · 0 comments

Comments

@quasilyte
Copy link
Owner

Functions like aref have very generic input parameters.

aref, in particular, can return nth element of string, vector, bool-vector and char-table.
The problem is that string is not necessarily stored as lisp.Object, so we can not have func(array lisp.Object, index int) lisp.Object as a signature. More over, strings always return rune (char) as a result of indexing. This leads to func(s string, index int) rune signature.

(aref Aref (:object array :int idx) :object)
(aref ArefString (:string array :int idx) :char)

The result is 2 duplicated comment blocks that can confuse users.

// Aref = Return the element of ARRAY at index IDX.
// ARRAY may be a vector, a string, a char-table, a bool-vector,
// or a byte-code object.  IDX starts at 0.
//
//goism:"Aref"->"aref"
func Aref(array Object, idx int) Object {}

// ArefString = Return the element of ARRAY at index IDX.
// ARRAY may be a vector, a string, a char-table, a bool-vector,
// or a byte-code object.  IDX starts at 0.
//
//goism:"ArefString"->"aref"
func ArefString(array string, idx int) rune {}

Proposal:
add additional syntax that supports overloaded signatures;
optionally with alternative doc-string.

Example:

(aref Aref (:object array :int idx) :object
      "ArefString is like Aref, but only for strings."
      ArefString (:string s :int idx) :char)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant