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

@GiuseppeChillemi

neutral

Yes, I haven't find any difference.

no find/select

what you mean?

GiuseppeChillemi
@GiuseppeChillemi
Something like Find series newline
nedzadarek
@nedzadarek
@GiuseppeChillemi you can use forall loop:
>> arr: head arr
== [a 
    b c
]
>> forall arr [
[    probe arr
[    print new-line? arr
[    ]
[a 
    b c
]
false
[
    b c
]
true
[c]
false
GiuseppeChillemi
@GiuseppeChillemi
So, forall detects newline and Find and Select do not.
Detects = manage.
While It is trasparent/invisible to Find/select
nedzadarek
@nedzadarek
@GiuseppeChillemi forall doesn't detects anything. It's just a loop that changes position of the series (arr: [1 2 3] > [1 2 3] > [2 3] > ...). new-line? detects new lines.
GiuseppeChillemi
@GiuseppeChillemi
I use the wrong terminology : It does not skip newline
While find/select do skip It.
I am on mobile client for gitter and can't test but Will try "foreach" and lenght? Too.
nedzadarek
@nedzadarek
@GiuseppeChillemi I don't think find/select skip new-line markers on purpose. It's just they are made to do something else. They are made to check values not new-line markers. New-line markers are not "normal values".
foreach won't work because it gives you element of the series. The element doesn't hold information about new-line markers.
GiuseppeChillemi
@GiuseppeChillemi
If lenght? counts new-lines too, I Need to reconsider some routines
nedzadarek
@nedzadarek
@GiuseppeChillemi no, length? doesn't count new lines markers. length? arr; 3
Toomas Vooglaid
@toomasv
@GiuseppeChillemi See also red-by-example
Vladimir Vasilyev
@9214
This markers exist solely for formatting purposes, and do not affect anything except series appearance.
Chris Prinos
@cprinos

how would you store functions in a block/series and then execute them with foreach. I tried various things along the lines of this:

a: function [x] [x + 1]
b: function [x] [x * 2]
c: function [x] [x * x]

funcs: [:a :b :c]

foreach f funcs [ print f 5]

which is printing 'a b c', when I'm trying to get '6 10 25'.

Vladimir Vasilyev
@9214
foreach f reduce funcs ...
Vladimir Vasilyev
@9214
@cprinos you're not storing functions, you're storing get-word!s.
Toomas Vooglaid
@toomasv
@cprinos To store functions: funcs: reduce [:a :b :c].
Palaing
@Palaing

Looking for a way to give a variable as an argument to cd? I try:

dir: %/D/Dropbox/utils
cd :dir

...that does not work: "cd does not allow get-word! for its :dir argument"
Any hint?

Boleslav Březovský
@rebolek
@Palaing use change-dir instead
cd is meant for interactive console sessions
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