This has been proposed by a few people at different times, so I'll
probably add something like this soon.
Slava
On Tue, Dec 2, 2008 at 11:26 PM, Eduardo Cavazos <[EMAIL PROTECTED]> wrote:
> Hello,
>
> The 'TUPLE:' word currently supports specifying an initial value for a slot
> via the 'initial:' slot specifier:
>
> TUPLE: <abc> { a initial: 100 } b c ;
>
> It would also be useful to specifiy a quotation which is called in order to
> have a computed initial value. I.e.
>
> TUPLE: <abc> { a initial: 100 } { b eval: [ 10 random ] } c ;
>
> The attached code implements this along with an alterntive 'new'. You can
> paste the code, the second example above, followed by:
>
> <abc> new
>
> into a listener to try it out.
>
> Ed
>
> ----------------------------------------------------------------------
>
> IN: slots
>
> TUPLE: slot-spec name offset class initial read-only eval ;
>
> ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>
> USING: classes ;
>
> IN: classes.tuple
>
> :: init-eval-slots ( OBJ -- obj )
> "slots" OBJ class props>> at [ eval>> ] filter
> [| SLOT-SPEC |
> SLOT-SPEC eval>> call
> SLOT-SPEC name>>
> OBJ <mirror>
> set-at
> ]
> each
> OBJ ;
>
> ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>
> IN: syntax
>
> SYMBOL: eval:
>
> ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>
> IN: slots
>
> : peel-off-attributes ( slot-spec array -- slot-spec array )
> dup empty?
> [
> unclip
> {
> { initial: [ [ first >>initial ] [ rest ] bi ] }
> { eval: [ [ first >>eval ] [ rest ] bi ] }
> { read-only [ [ t >>read-only ] dip ] }
> [ bad-slot-attribute ]
> }
> case
> ]
> unless ;
>
> ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>
> IN: alt-new
>
> GENERIC: new ( class -- obj )
>
> M: tuple-class new
> dup "prototype" word-prop
> [ (clone) ] [ tuple-layout <tuple> ] ?if
> init-eval-slots ;
>
> -------------------------------------------------------------------------
> 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
>
-------------------------------------------------------------------------
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