Hello,

Here's the code for the localize generic word from extra/locals :

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

GENERIC# localize 1 ( obj args -- )

M: local        localize read-local ;

M: quote        localize >r quote-local r> read-local ;

M: local-word   localize read-local \ call , ;

M: local-reader localize read-local \ first , ;

M: object       localize drop , ;

M: word         localize drop dup \ lambda eq? [ drop ] [ , ] if ;

M: local-writer localize
   >r "local-reader" word-prop r> read-local \ set-first , ;

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

This demonstrates the use of GENERIC: to accomplish what a complex (and more 
importantly, sealed) cond or case statement might achieve.

Unfortunately, there's some boilerplate in there; all the M:'s and the 
repeated 'localize' for each method. This is an area where the syntax for 
mortar and message passing in general wins. I'm not suggesting that this code 
be rewritten in a message passing style; but maybe we should think about a 
shorter expression of the above. E.g.

METHODS# localize 1 ( obj args -- )

  local        [ read-local ]

  quote        [ >r quote-local r> read-local ]

  local-word   [ read-local \ call , ]

  local-reader [ read-local \ first , ]

  local-writer [ >r "local-reader" word-prop r> read-local \ set-first , ]

  object       [ drop , ]

  word         [ drop dup \ lambda eq? [ drop ] [ , ] if ] ;

In the case of localize, it might be overkill to make it a GENERIC: at all. It 
is unlikely that methods will be added. And it is only called by point-free 
and (point-free). Maybe the way to go is a new word that really expresses the 
intent:

: localize ( obj args -- )
  over
  { local        [ read-local ]
    quote        [ >r quote-local r> read-local ]
    local-word   [ read-local \ call , ]
    local-reader [ read-local \ first , ]
    local-writer [ >r "local-reader" word-prop r> read-local \ set-first , ]
    word         [ drop dup \ lambda eq? [ drop ] [ , ] if ]
    object       [ drop , ] }
  class-case ;

Ed

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to