Search code examples
rebolrebol3

How do I show which refinements are available for a word?


The date datatype has a great set of refinements, for example:

t: now
t/second
== 21
t/month
== 4

How do I get a list of the available refinements for a word like t?


Solution

  • Words-of is great for functions, but what to do if your word is holding a non-function?

    Well, you could try 'help.

    It will let you down, however, for example if you want to find the accessors for time! values.

    You could also try accessing via numbers, if all you want is to see what's available:

    >> x: now/precise
    == 15-Jan-2015/16:18:39.609-5:00
    
    >> x/1
    == 2015
    
    >> x/9
    == 15-Jan-2015/21:18:39.609
    

    However, and I myself just found this out, this can also let you down; date! values have more than 9 accessors, but:

    >> x/10
    ** Script error: cannot access 10 in path x/10
    

    And even if it was complete it would still not answer the question, what are the available refinements?

    So, I am here providing another answer: Look it up on SO!

    Type     Accessor words (and paths)
    ====     ==========================
    date!    year month day time zone date weekday julian yearday utc hour minute second
    time!    hour minute second
    pair!    x y
    gob!     offset size size/x size/y alpha
    event!   offset
    

    The gob! and event! paths are incomplete, since word and value pairs can be added dynamically, but this is a start, and what I've listed here will always be there. (Actually for those two cases, just printing the value gives you the words it recognizes, similar to objects and blocks.)