Hello,

Here's a demonstration of something along the lines of what Slava mentioned on 
his blog a while ago. It's a unification of words, generics, and methods, 
into a uniform simple syntax.

I'm going to make an 'elt' word which is sort of like 'nth' but with the 
inputs reversed. I changed the Factor prompt to '>'.

        Define the word and test it:

> : elt ( :array :integer -- :object ) swap nth ;
> { 10 20 30 } 0 elt .
10

        Try 'elt' on a string:

> "abc" 0 elt .
Type check error
...

        Tell 'elt' to work on strings:

> : elt ( :string :integer -- :object ) swap nth ;

        Test it:

> "abc" 0 elt .
97

        Try 'elt' on a vector:

> V{ 10 20 30 } 0 elt .
Type check error

        Tell 'elt' to work on vectors:

> : elt ( :vector :integer -- :object ) swap nth ;

        Test it:

> V{ 10 20 30 } 0 elt .
10

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