by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 20 2019 22:59
    @dockimbel banned @SmackMacDougal
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:19
    @PeterWAWood banned @TimeSeriesLord
  • Aug 13 2016 03:23
    @PeterWAWood banned @Vexercizer
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
GiuseppeChillemi
@GiuseppeChillemi

I have enough information...

But still have to understand why this works:

foo/('bar)/baz
nedzadarek
@nedzadarek
@GiuseppeChillemi do you mean paren! (()) and 'bar inside it?
GiuseppeChillemi
@GiuseppeChillemi
Yes
hexpected paren! () and :bar
*expected
nedzadarek
@nedzadarek
As parens in the paths are evaluated you will end up with the value that bar points to. What you want is word! (or any-word! - more later if you need additional informations*).
* it is all the same for red if you want select something:
>> arr: [a 42]
== [a 42]
>> select arr to-word "a"
== 42
>> select arr probe to-word "a"
a
== 42
>> select arr probe to-get-word "a"
:a
== 42
>> select arr probe to-set-word "a"
a:
== 42
>> select arr probe to-lit-word "a"
'a
== 42
GiuseppeChillemi
@GiuseppeChillemi
@nedzadarek
To me 'something mean "literal word", so no-translation
nedzadarek
@nedzadarek
@GiuseppeChillemi it is not that simple. At "top" level it says "do not evaluate this word", a: 'b. You will end up with a word!: ? a. In a block words/pathes are not evaluated so you will end up with lit-word! (type? first ['a]).
GiuseppeChillemi
@GiuseppeChillemi
Totally obscure at the moment
Needs more information
Needs input ! Beep !
nedzadarek
@nedzadarek
@GiuseppeChillemi What do you do not understand?