Hello,

This is a much more experimental suggestion than the 'eval:' slot attribute.

This:

        TUPLE: <abc> { a model-slot } b c ;

Indicates that the 'a' slot will be a model and the reader and writer will act 
accordingly. I.e. given:

        10 <model> 20 30 <abc> boa

The 'a>>' will return '10' and '>>a' will update the model via 'set-model' so 
that observers are notified.

It's somewhat controversial because the jury is still out on whether or not 
custom reader and writer methods should be used. This idiom is worth 
exploring. If custom methods enjoy wide usage, then words which access the 
slot directly by name would be good to have (can be achived via mirrors...).

Code attached.

Ed

----------------------------------------------------------------------

IN: syntax

SYMBOL: model-slot

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

IN: slots

TUPLE: slot-spec name offset class initial read-only model-slot ;

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

: peel-off-attributes ( slot-spec array -- slot-spec array )
  dup empty?
    [
      unclip
      {
        { initial:   [ [ first >>initial ] [ rest ] bi ] }
        { model-slot [ [ t >>model-slot  ] dip         ] }
        { read-only  [ [ t >>read-only   ] dip         ] }
        [ bad-slot-attribute ]
      }
      case
    ]
  unless ;

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

:: model-reader-quot ( SLOT-SPEC -- quot )
  
  [let | OFFSET [ SLOT-SPEC offset>> ] |

    [ OFFSET slot value>> ] ] ;

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

:: define-model-reader ( CLASS SLOT-SPEC -- )
  CLASS
  SLOT-SPEC name>> reader-word
  SLOT-SPEC        model-reader-quot
  SLOT-SPEC        reader-props
  define-typecheck ;

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

:: model-writer-quot ( SLOT-SPEC -- quot )
  
  [let | OFFSET [ SLOT-SPEC offset>> ] |

    ! ( val obj -- )

    [ OFFSET slot set-model ] ] ;

:: define-model-writer ( CLASS SLOT-SPEC -- )
  CLASS
  SLOT-SPEC name>> writer-word
  SLOT-SPEC        model-writer-quot
  SLOT-SPEC        writer-props
  define-typecheck ;

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

:: define-slot-methods ( CLASS SLOT-SPEC -- )
  SLOT-SPEC model-slot>>
    [
      CLASS SLOT-SPEC define-model-reader
      CLASS SLOT-SPEC define-model-writer
    ]
    [
      CLASS SLOT-SPEC
      [ define-reader ]
      [
        dup read-only>> [ 2drop ] [
            [ name>> define-setter drop ]
            [ name>> define-changer drop ]
            [ define-writer ]
            2tri
        ] if
      ] 2bi
    ]
  if ;

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to