Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 20 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
Vladimir Vasilyev
@9214
@GiuseppeChillemi select returns a value that follow the key (if any), find/tail searches for the first occurence of a value and returns a series past that value.
GiuseppeChillemi
@GiuseppeChillemi
From REBOL documentation: "Finds a value in the series and returns the value or series after it"
The word "returns" let me think about copying it.
Vladimir Vasilyev
@9214
>> select block 'a
== [b c d]
>> first find/tail block 'a
== [b c d]
@GiuseppeChillemi uhm, no. Again, there's no copying, you can check it yourself.
GiuseppeChillemi
@GiuseppeChillemi
Yes, I see it but I thought it did this.
@9214 So, pick does not copy too...
"pick"
Vladimir Vasilyev
@9214
@GiuseppeChillemi nope, none of the series actions do copying.
GiuseppeChillemi
@GiuseppeChillemi
:-(
And does COPY "COPY" ? :-)
Vladimir Vasilyev
@9214
Yes, obviously.
GiuseppeChillemi
@GiuseppeChillemi
Yes, I have written it just for fun

Another question: is where a way to have a subseries of a bigger one in a static way ?
Example:

a: [a b c d e f g h]

The subseries should be:

b: [d e]

But [d e] are just part of "A"

So if you change the B: to "[z e]"

>>> a 
= [a b c z e f g h]
Vladimir Vasilyev
@9214
@GiuseppeChillemi you can store such subseries as a pair of series index and number of elements, and use change/part for mutation.
>> a: [a b c d e f g h]
== [a b c d e f g h]
>> b: reduce [at a 4 2]
== [[d e f g h] 2]
>> head change/part b/1 [z e] b/2
== [a b c z e f g h]
Or:
>> a: [a b c d e f g h]
== [a b c d e f g h]
>> subseries: 4x2
== 4x2
>> head change/part at a subseries/x [z e] subseries/y
== [a b c z e f g h]
GiuseppeChillemi
@GiuseppeChillemi
@9214 If I "Insert" data , will indexes of subseries shift their position to remain in place ?
Vladimir Vasilyev
@9214
@GiuseppeChillemi no, though, you can probably implement such feature with reactors.
nedzadarek
@nedzadarek
Is this the draw dialect's syntax:
1) <optional set-word!>> <command> <arguments>
2) or a block containing 1)
And 1 or 2 may be 0 or more repeated.
Am I right?
Toomas Vooglaid
@toomasv

@nedzadarek If you consider pnly figures, then almost. In addition, optional set-word may also precede the block

view [box draw [b: box 10x10 50x50 c: circle 30x30 30]]
view [box draw [[b: box 10x10 50x50][c: circle 30x30 30]]]
view [box draw [[[[[[[b: box 10x10 50x50]]] circle 30x30 30]]]]]
view [box draw [b: [box 10x10 50x50]]]
view [box draw [b: [b2: box 10x10 50x50]]]
view [box draw [b: b2: b3: box 10x10 50x50]]
view [box draw [b:]]

So, it is more like

<draw-command>: (<command> <arguments> | '['<command> <arguments>']')
<draw-expression>: <set-word>* <draw-command>
<draw>: <draw-expression>*
nedzadarek
@nedzadarek
@toomasv thank you for the response.
A block may contain only set word (your last example: view [box draw [b:]]) so I guess 2nd line should be: <draw-expression>: <set-word>* <draw-command>*.
Are there non-figure elements that does not "use" above rules? I could not find any.
Toomas Vooglaid
@toomasv
@nedzadarek Probably not, although it is worth noting that transformation commands' last argument can be block of drawing commands and in case of push and shapethe only argument should be block!. And in both cases you can't put set-word before the block.
GiuseppeChillemi
@GiuseppeChillemi
This message was deleted
if I have a function that accepts 2 arguments, is there a way to be them provided by the return value of a second one ?
Vladimir Vasilyev
@9214
@GiuseppeChillemi
>> foo: func [x y][x + y]
== func [x y][x + y]
>> bar: does [[1 2]]
== func [][[1 2]]
>> do head insert bar :foo
== 3
In general that would require apply, but you can use tricks similar to the above one.
dsunanda
@dsunanda
If you are happy to use an intermediate word to hold the two results, you can do it like below - using Vladimir's FOO and BAR functions
foo first x: bar x/2
== 3
GiuseppeChillemi
@GiuseppeChillemi
This message was deleted

Well, thanks, I was just imaging if there where a simple way to load code words/values at the current program execution position. So, it FOO expected X and Y then something like
(I assume "<" mean: "insert the result of the code between parens at this point")

FOO <(BAR)
Print "A"

Would be interpreted like

FOO 1 2
Print "A"
Vladimir Vasilyev
@9214
@GiuseppeChillemi compose or macros.
Vladimir Vasilyev
@9214
>> foo: func [x y][x + y]
== func [x y][x + y]
>> bar: does [[1 2]]
== func [][[1 2]]
>> compose [foo (bar)]
== [foo 1 2]
>> do compose [foo (bar)]
== 3
Macros is not what you want, I guess. They can't operate on values that are presented at run-time (i.e. you can't evaluate function bar, because it doesn't exist yet).
#do [bar: [1 2]]

#macro ['< paren!] func [start end][
    get in preprocessor/exec start/2/1 
]

probe expand [
    foo <(bar)
    foo #do keep [[1 2]]
]
GiuseppeChillemi
@GiuseppeChillemi
compose and macros are totally new for me.
dsunanda
@dsunanda
Vladimir mentioned APPLY. That's available in Rebol3, but noy (yet) in Red. If it worked in Red, then your code would simply be:
apply :foo bar
Vladimir Vasilyev
@9214
@GiuseppeChillemi a bit crazier version would be:
#macro [word! '< paren!] func [start end][
    reduce ['do 'compose reduce [start/1 end/-1]]
]

foo: func [x y][x + y]
bar: does [[1 2]]

probe foo <(bar)
dsunanda
@dsunanda
The good news is that APPLY is on Red's roadmap To-Do list. One day!
GiuseppeChillemi
@GiuseppeChillemi
This message was deleted
@dsunanda , which is the purpose of APPLY ?
dsunanda
@dsunanda
Basically to treat a block of values as if they were the args to a function. (the function is "applied" to the block). This link explains a bit more, with some examples. As it says: " there are times when you want to store the arguments as a single block and pass them to the function"
GiuseppeChillemi
@GiuseppeChillemi
@dsunanda thanks
Many things still to learn
REDBOL is a small giant universe.
dsunanda
@dsunanda
Lot's to learn - that makes it fun! You can fake up a cheap version of APPLY as below -- it won't handle /refinements:
apply: func [fun data /local blk][blk: copy [] append blk data insert blk 'fun do blk]
apply :foo bar  ;; as before
Vladimir Vasilyev
@9214
Or just
apply: func [function data][do compose [function (data)]]
>> apply: func [function data][do compose reduce [function quote (data)]]
== func [function data][do compose reduce [function quote (data)]]
>> apply 'reverse/part [[a b c d] 2]
== [b a c d]
Ungaretti
@Ungaretti
The predefined word what lists all predefined words of Red. Is there a way to list the words (variables) I created? In other words, to list Red's "dictionary"? Is calling that "dictionary" wrong?
Vladimir Vasilyev
@9214
@Ungaretti words-of system/words
Ungaretti
@Ungaretti
Boy you are fast!
Thanks.
Vladimir Vasilyev
@9214
@Ungaretti though, you'll need first to mark a "clean slate" point in this series. Even then you'll be able to track only words that have different spelling from the existing ones.
And it will track any words you've mentioned :wink: