Hello, and thanks for the reply!
I was thinking about immediately calling a TYPED: word, as you suggested. The
problem with this approach is that we are only enforcing the type check in an
implementation of the interface, not in the interface itself. Any new
implementation added afterwards is free to omit the type checks, which is not
what I want in the first place.
Here's an example interface I'm currently meditating about:
```
SYMBOL: drive-repository
HOOK: store-new-drive drive-repository ( drive -- )
HOOK: load-all-drives drive-repository ( -- drives )
HOOK: load-drive-by-id drive-repository ( id -- drive/f )
HOOK: store-updated-drive drive-repository ( drive -- )
```
I want to be able to define it like this:
```
SYMBOL: drive-repository
TYPED-HOOK: store-new-drive drive-repository ( drive: drive -- )
TYPED-HOOK: load-all-drives drive-repository ( -- drives: sequence )
TYPED-HOOK: load-drive-by-id drive-repository ( id: number -- drive: maybe{
drive } )
TYPED-HOOK: store-updated-drive drive-repository ( drive: drive -- )
```
We have a dispatch mechanism that is taking the current value of the
`drive-repository` symbol and calls the appropriate M:ethods of an
implementation (which typically is a SINGLETON:). I'd like it to also check the
type conformance prior to the call, and then check the result types when the
method returns.
Would that be possible to implement? What would it take, approximately, for
me to do so?
Would anyone else be interested in such functionality?
17.09.2017, 00:50, "Benjamin Pollack" <[email protected]>:
>> On Sep 16, 2017, at 17:03, Alexander Ilin <[email protected]> wrote:
>>
>> Hello!
>>
>> Do we have TYPED: methods in Factor?
>> Like, for when I want to have a M:ethod that performs type checks on the
>> arguments other than the dispatch variable.
>
> We don’t, as far as I know; if you wanted to do this “right”, I believe you’d
> have to extend the object system a bit. But it’d be pretty trivial (depending
> on context) to just have your M: implementation immediately pass things off
> to a TYPED: word and get most of the benefits for little cost.
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
---=====---
Александр
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk