Thank you for clarifying your point about "Appendix" for ref args. This
sounds good to me.
Sorry for the original misunderstanding.
You certainly have good suggestions about Chapel's interop. I suggest you
open GitHub issues with those, to make sure your ideas are reflected well.
The ideas need refinement. I am only trying to document things at the moment.
That's for the feedback. My notes just came from some discussions with a few colleagues and some minor refinement.
I will respond with their feedback. I have rewritten this stuff using groff with parameterized names so I can push it back to the old names if they are cast in stone.
It seemed like there were 3 kinds of C pointers that had to be handled
- function pointers,
- void pointers, and
- data pointers.
When it came to the c_?????_ptr
names, I was asked over several cups of coffee
Why not just use the first 4 letters of each to minimize abbreviations?
and I said "why not"? Hence, from a C perspective, these became
c_func_ptr
c_void_ptr
c_data_ptr
When we changed to those names in the documentation, things were a lot more obvious and delineated. And everything had 4 letters so it read a lot better which is key to any documentation.
I unilaterally changed our consensus first name to proc - silly me. It is now reverted to func
We also could not understand the mix of CAPs and underscores in the name in
c_ptrTo
As we figured that the c_
was not negotiable, we changed it to c_ptr_to
. But then nothing coerces to a c_void_ptr, so we came up with
c_func_ptr_to
and
c_data_ptr_to
for two reasons. Firstly, it read just soooo much better. Also, we thought the former might need to be special later if it has to handle types for both argument the function's argument(s) and return value. In hindsight, that may not be a good idea.
I'd like to argue with a couple of your ideas:
Go for it.
c_fn_ptr --> c_proc_ptr : this depends on your point of view. This
exists explicitly to describe things callable in the C world. Those
things are "fns", not "procs". By analogy, "c_void_ptr" is gibberish in
the Chapel world, as in Chapel there are no values of void type and no
pointers at all. So "fn" in the name makes more sense to me.
Agreed, they are func[tions]
. While first-letter/last-letter of a name is a valid way to abbreviate the name, we used the first 4 letters of the words data and void, so we choose the first four from function
. Also, func is a lot more obvious in meaning to a first time reader who has not seen Rust.
c_data_ptr_to() and c_proc_ptr_to() : to me this is like you are
proposing different names for the plus operator on ints vs. complex
vs. strings. It is common in Chapel to overload a single name to
mean similar operations on different argument types.
Agreed - In hindsight, I agree that these two should not be different.
I have been overloading operators and functions for 25 years before I ever saw Chapel. Well longer than that if you add Algol68 experience with operators.
The case of c_ptrTo or c_ptr_to falls squarely into this category in my view.
Maybe. But really c_ptrTo
seems like it was chosen by somebody who cannot decide between underscores and camelCase and wants a bet each way. We did a version of the document with the original name and then another with
c_ptr_to
The latter reads infinitely easier on the eyes and does not clutter up the interline space in the same way that a camelCase name does. We then screwed around with those two variants of that but as I said, we can forgot those.
"c_ptrTo relies on some casting magic" -- indeed it does. Likewise
"+" on integers relies on some bitwise magic, doesn't it? Regardless,
let us say that we have implemented c_ptrTo() that does not rely on any
magic. How would you document that function?
I am happy with casting magic, but not when I cannot understand it.
In my current rewritten 'Interoperability' Technotes, I have changed the name back to c_ptr_to
and am happy to keep the single name. That means I can say
c_ptr_to( <Chapel-function-name> )
coerces/evaluates to a C pointer to that Chapel-function-name, and similarly
c_ptr_to( <Chapel-variable-name> )
coerces/evaluates to a C pointer to that Chapel-variable-name.
As for the document itself, I still need to rearrange some bits and add more examples. The latter includes your own examples of C function prototypes and declarations with a few extra words, in both extern { } block style and require style. and my own extern {} block style which has some embedded assembler and uses a less common but very well accepted #include file.
I will then do a PDF so people can read it like a real document and once I get something approximating consensus, I will then emasculate it back to Markdown and people can hack it to their heart's content.
But my day job takes precedence this week.