I see. Well, it seems that the original idea was for `set-model` to be generic.
 
Also, there is an undocumented `GENERIC: update-model ( model -- )` - I wonder what is its role in the whole thing.
 
Apparently, `set-model` WAS generic until commit 57893118e066536decc. The documentation is simply out of date by almost 10 years...
 
14.06.2017, 01:31, "John Benediktsson" <mrj...@gmail.com>:
I'm not sure what the original author was thinking of, but you can always do this to perform validation:
 
    TUPLE: my-model < model ;
 
    : <my-model> ( value -- model ) my-model new-model ;
 
    M: my-model value<<
        over even? [ drop throw ] unless call-next-method ;
 
Then if you try and construct it with an odd number or set it with an odd number value it throws.
 
 
 
 
 
On Tue, Jun 13, 2017 at 2:24 PM, Alexander Ilin <ajs...@yandex.ru> wrote:
Hello!

  I have found this text in the documentation: "Models can override requests to change their value, for example to perform validation: set-model ( value model -- )".

  How would that work, exactly? `set-model` is not a generic that could be overridden. I don't understand the mechanism suggested by the help.

  For example, I'm developing a gadget for a certain type of objects, and I want only that class of objects to be assignable to the gadget's model slot. How would I do that kind of validation?

  Or is it not what I need in my case?

---=====---
 Александр

------------------------------------------------------------------------------
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
Factor-talk@lists.sourceforge.net
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
Factor-talk@lists.sourceforge.net
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
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to