|
From: | Egeyar Bagcioglu |
Subject: | Re: [RFC] Methods and functions |
Date: | Mon, 4 May 2020 00:03:12 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 |
Hi Jose,First of all, this is a very well written explanation, comparison and discussion. Thanks.
BUT, I am considering the following: what about introducing explicit methods separated from functions.
[snip]
My current opinion is that it would complicate the language, for little benefit: after all, it costs nothing to have prime_p defined outside of the struct type: defun prime_p = (int n) int: { ... } deftype Foo = struct { int f1 : prime_p (f1); int f2; defun frob = void: { ... } }; So I don't plan to implement support for both regular functions and methods inside struct types. I think the current approach is simple, intuitive, and predictable, given the user has access to some decent documentation. But I am very interested in feedback. What do you think? :)
I believe you are right that a function defined within a struct has nothing over an external function. In fact, that's exactly why we are referring to them as functions. I would also be against such complexity for the tiny benefit of hiding the function within the struct.
I do have one tiny consideration, that you did not ask for, if I may. I understand that the support for methods is very similar to that of functions, so much that defun can be extended for the sake of simplicity. Simplicity for a poke developer... However, after reading your detailed email, I am convinced that methods and functions are indeed different entities for a Poke writer (mind the capital letter). Not all of them will be lucky enough to read this email of yours before stumbling upon behavioral differences between the "functions" they define. It seems to me that it would be quite easy to adjust the parser to accept defmeth, or something as such, in a struct, rather than defun. Then, defmeth could be defined as a single defun to use your current implementation. That would be only to enforce the awareness of the differences between functions and methods on the folks who are writing them. Have you considered using a different keyword for methods? If you are against that, can you share your reasoning so that I can learn from it?
Regards Ege
[Prev in Thread] | Current Thread | [Next in Thread] |