Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:19
    @PeterWAWood banned @TimeSeriesLord
  • Aug 13 2016 03:23
    @PeterWAWood banned @Vexercizer
nedzadarek
@nedzadarek

@cprinos to add to previous answers, you can as well add functions to the block funcs: append funcs :a.
ps. you may use a map! (key-value container, e.g. m: #(a: 42) m/a ; 42).

m: #()
m/a: function [x] [x + 1]
m/b: function [x] [x + 2]
m/c: function [x] [x + 3]

You can run functions by a name: m/a 1; == 2 or you can get keys (words) of the map and use foreach:

foreach key words-of m [probe m/:key 10]
; 11
; 12
; 13
Toomas Vooglaid
@toomasv
For maps keys-of is suggested.
Chris Prinos
@cprinos
@9214, @toomasv @nedzadarek thanks for the variations... will take a bit to convert my python thoughts to red thoughts
nedzadarek
@nedzadarek
@toomasv is there a reason for this? They are the same. I guess it can change in the future.
ps. I wanted to use keys-of but I forgot to add m before foreach's block. It showed me an error reserved for future use (or not yet implemented) so I just blindly took 2nd similar-looking function.
Toomas Vooglaid
@toomasv
@nedzadarek IIRC @dockimbel strongly adviced to use keys-of for maps, although currently there is no difference in practice.
nedzadarek
@nedzadarek
reflect: make action! [[
    {Returns internal details about a value via reflection} 
    value [any-type!] 
    field [word!] {spec, body, words, etc. **Each datatype defines its own reflectors**}
]]

Can I get list of datatype - reflector(s) from within red?

@toomasv I see, I will keep this in mind.

Toomas Vooglaid
@toomasv
Do you mean something like
>> ? "-of"
     body-of         function!     Returns the body of a value that supports reflection.
     caret-to-offset function!     Given a text position, returns the corresponding coordinate relative to the top-left o...
     class-of        function!     Returns the class ID of an object.
     keys-of         function!     Returns the list of words of a value that supports reflection.
     layout          function!     Return a face with a pane built from a VID description.
     spec-of         function!     Returns the spec of a value that supports reflection.
     values-of       function!     Returns the list of values of a value that supports reflection.
     words-of        function!     Returns the list of words of a value that supports reflection.
Better
>> ? "reflection"
     body-of         function!     Returns the body of a value that supports reflection.
     keys-of         function!     Returns the list of words of a value that supports reflection.
     reflect         action!       Returns internal details about a value via reflection.
     spec-of         function!     Returns the spec of a value that supports reflection.
     values-of       function!     Returns the list of values of a value that supports reflection.
     words-of        function!     Returns the list of words of a value that supports reflection.
nedzadarek
@nedzadarek
@toomasv I mean I want list like:
  • function - spec, body
  • map - words, values
    ...
Vladimir Vasilyev
@9214
system/catalog
Toomas Vooglaid
@toomasv
@nedzadarek These are those I know of, which may be strongly limited:
function - spec, body
map - keys (words), values, body
object - words (keys), values, body
nedzadarek
@nedzadarek
@toomasv I see, thank you.
@9214
SYSTEM/CATALOG is an object! with the following words and values:
     datatypes  none!         none
     actions    none!         none
     natives    none!         none
     accessors  block!        length: 12  [date! [date year month day zone ti...
     errors     object!       [throw note syntax script math access reserved1...
there is no such informations here.
Rudolf Meijer
@meijeru
system/catalog/accessors exists, but it contains only the words that can access components of values of direct types: extract system/catalog/accessors 2 => date! email! event! image! pair! time!. To complete Toomas's list:
object!, error!, port! and map! have words-of = keys-of, values-of and body-of
any-function! have spec-of, body-of and words-of(this one not yet implemented)
Toomas Vooglaid
@toomasv
Thanks, @meijeru !
Vladimir Vasilyev
@9214

To answer the original question:

Can I get list of datatype - reflector(s) from within red?

Red [
    Title:  "Bruteforce search of all available reflectors"
    Author: 9214
    Date:   9-Oct-2018
]

; N.B. KEYS-OF is an alias for VALUES-OF
reflectors: extract load rejoin take/part at 
    read/lines https://raw.githubusercontent.com/red/red/master/environment/functions.red
    116 5 2

datatypes: remove/part sort load help-string datatype! 12

seeds: [[[][]] [1 1 0] 0 0x0 "."]

cartesian: function [domains body][
    product: reduce [body]
    do take forall domains [
        remove back tail spelling: form domains/1
        product: reduce [
            head insert product reduce ['foreach to word! spelling domains/1]
        ] 
    ]
]

probe also catalog: make map! length? datatypes cartesian [reflectors datatypes seeds][
    all [
        attempt [reflect make get datatype seed reflector]
        either catalog/:datatype [
            append catalog/:datatype reflector
        ][
            catalog/:datatype: make block! length? reflectors
        ]
    ]
]
Vladimir Vasilyev
@9214
For some reason spec is not there...
Vladimir Vasilyev
@9214
Duh, should be to block! reflector instead of make block! length? reflectors.
Toomas Vooglaid
@toomasv
@9214 :+1: Result:
#(
    function!: [spec body]
    object!: [body words class values body words class values]
    op!: [spec]
    error!: [body words class values body words class values]
    map!: [body words values]
)
Vladimir Vasilyev
@9214
@toomasv need to stick unique somewhere.
Toomas Vooglaid
@toomasv
Yes
Vladimir Vasilyev
@9214
I've put a slightly refined version here.
nedzadarek
@nedzadarek
I wonder why op! doesn't ave 'body.
@9214 :+1:
GiuseppeChillemi
@GiuseppeChillemi
Hi, again on paths:
Is it possible to store a path in a word and have it evalued later ?
nedzadarek
@nedzadarek
@GiuseppeChillemi w: 'foo/bar/baz
GiuseppeChillemi
@GiuseppeChillemi
example: path a/b/(c)/d/e
(c) around parens should be "reduced" later
nedzadarek
@nedzadarek
foo: [bar [baz 42]]
w: 'foo/bar/baz
get w
; == 42
reduce w
; == 42
w2: 'foo/('bar)/baz
; == foo/('bar)/baz
get w2
; == 42
GiuseppeChillemi
@GiuseppeChillemi
could I "select" ?
nedzadarek
@nedzadarek
select?
w3: 'foo/('bar) 
select get w3 'baz
?
GiuseppeChillemi
@GiuseppeChillemi
Headache !
nedzadarek
@nedzadarek
What's wrong?
(sorry, it's midnight - I don't have fresh mind)
GiuseppeChillemi
@GiuseppeChillemi
Midnight here too...
I suppose this syntax is not comatible with R2
nedzadarek
@nedzadarek
Let me try
GiuseppeChillemi
@GiuseppeChillemi

I suppose

select w3 'baz

Is not possible

or
w3: to-path w3
select w3 'baz
Is not possible too
nedzadarek
@nedzadarek
@GiuseppeChillemi get doesn't allow path! and reduce doesn't work... I'll check alternatives.
^^ yes, not possible
@GiuseppeChillemi hmm.. this work:
>> ? :w
FOO/BAR/BAZ is an integer of value: 42
GiuseppeChillemi
@GiuseppeChillemi
It is possible to use the
w: 'FOO/('REDUCES-TO-BAR)/BAZ
? :w

@nedzadarek

w: 'FOO/(:REDUCES-TO-BAR)/BAZ

is the answer

(REBOL 2)
nedzadarek
@nedzadarek
@GiuseppeChillemi I found that reduce does not reduce path (I am not sure why) but it is happy with a block:
type? first [w]
; == word!
type? first reduce [w]
; == path!
 first reduce [w]
; == foo/bar/baz
first reduce reduce [w]
; == 42