On Tuesday 29 July 2008 14:44:00 Joe Groff wrote:

> And is there any way to distinguish defining a new word in the current
> vocab from adding a method to a generic in an imported method?

The method syntax works on words in the "current" vocabulary. So if you want 
to extend a generic from another vocabulary, you put an explicit 'IN:' there.

For example, if I want to extend the sequences 'nth' from one of my own 
vocabularies, I'd do:

IN: my-vocab

...
...

! Extend 'nth' from 'sequences':

IN: sequences

: nth ... ;

! Switch back to my-vocab:

IN: my-vocab

...

That's doing things in a very manual way however. It would be nice to declare 
at the top of the vocabulary:

        EXTEND: nth sequences

So you're saying "extend 'nth' from the 'sequences' vocabulary". How would 
this be implemented? Look at how word names are resolved in 
the 'method-syntax' implementation:

        : name>word ( name -- word )
          dup in get lookup dup
            [ nip ]
            [ drop in get create ]
          if ;

Nice and simple; we only pick words from the 'in' vocabulary. What 
the 'EXTEND:' word would do is add that generic word to a list. 
Then 'name>word' would check that list as well as the 'in' vocabulary.

Now the above example looks like:

        IN: my-vocab

        EXTEND: nth sequences

        ...

This is even *better* than the current state of affairs. Right now, when 
you're reading code, you'll see folks adding methods but it's not clear what 
vocabulary the generic is from unless you look it up manually. This way, it's 
clear from the declaration which generics are being extended. This also 
clears up possible problems that can result from the order of items in 
the 'USING:' form.

If you are extending a ton of generics from a particular vocabulary, it's 
probably better to fall back to using 'IN:':

        IN: my-vocab

        ...

        IN: sequences

        ... define lots of methods

        IN: my-vocab

Which might look better than:

        IN: my-vocab

        EXTEND: abc sequences
        EXTEND: def sequences
        EXTEND: ghi sequences
        ...

I.e. you'd need an 'EXTEND:' for every generic you're extending. Thus 
the 'IN:' is a cleaner route.

If you don't explicitly use 'IN:' or 'EXTEND:', then a new generic will be 
created in the current vocabulary.

Ed

-------------------------------------------------------------------------
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