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
GiuseppeChillemi
@GiuseppeChillemi
(Talking about REBOL2)
Chris Prinos
@cprinos

follow up to an earlier question on storing/manipulating functions in series...
with this code:

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

funcs:  reduce [:a :b :c]

foreach f funcs [ probe f 5]
foreach f funcs [ print f 5]
foreach f funcs [ print type? f 5]

I get different results via the interpreter red test.red vs compiled red -c -o test test.red

output with the interpreter:

6
10
25
6
10
25
integer
integer
integer

and with the compiled version:

func [x][x + 1]
func [x][x * 2]
func [x][x * x]
?function?
?function?
?function?
function
function
function

why the difference ?

Palaing
@Palaing
@rebolek Thank you! I thought cd was just an alias of change-dir
Boleslav Březovský
@rebolek
@Palaing You're welcome. It's almost alias. See that change-dir takes dir, but cd takes :dir, so it does not evaluate, OTOH you can do cd dir instead of cd %dir.
Vladimir Vasilyev
@9214
@cprinos difference stems from the fact that current compiler supports only a limited set of language, and cannot handle dynamic constructs such as in your example. Try to compile with -r -e flags instead.
lepinekong
@lepinekong_twitter
@Palaing I have developped cd which combines CD and @toomasv Tree here https://redlang.red/cd
and it works with variable and is tolerant with different file path format. So for example, you can try:
do https://redlang.red/cd
windows: c:\windows
cd windows
It works except it will print Tree twice a bug not a feature :)
dsunanda
@dsunanda
I am trying to create a PANEL with spacing of 0x0 - but the SPACE 0x0 seems to be ignored. In the code below, the red box has an OFFSET of 10x10. In R2 it would be 0x0. Any ideas, thanks?
unview/all
view/no-wait layout/tight [ 
    across space 0x0
    my-panel: panel [across space 0x0
          box 100x100 red  box 100x100 blue
          return
          box 100x100 pink box 100x100 green 
          ]
    ]
foreach box my-panel/pane [box/text: form box/offset show box]
do-events
Toomas Vooglaid
@toomasv
@dsunanda Add origin 0x0 to panel:
unview/all
view/no-wait layout/tight [ 
    across space 0x0
    my-panel: panel [origin 0x0 across space 0x0
          box 100x100 red  box 100x100 blue
          return
          box 100x100 pink box 100x100 green 
          ]
    ]
foreach box my-panel/pane [box/text: form box/offset show box]
do-events
dsunanda
@dsunanda
Perfect! Thanks!!
Max
@moliad

@lepinekong_twitter

@cprinos difference stems from the fact that current compiler supports only a limited set of language, and cannot handle dynamic constructs such as in your example. Try to compile with -r -e flags instead.

Is there some complete documentation about these differences? its a big deal for my project.

Vladimir Vasilyev
@9214
Not that I know of.
Max
@moliad
:sob:
Toomas Vooglaid
@toomasv
@dsunanda You are welcome!
Palaing
@Palaing
@lepinekong_twitter great! it does much more than I needed ;)
lepinekong
@lepinekong_twitter
@Palaing sure because I didn't do it for you but for me ;)
dsunanda
@dsunanda
Is there any way as yet to rotate an image? Perferably by an arbitrary number of degrees
Vladimir Vasilyev
@9214
@dsunanda matrix transformations. I'll let @toomasv to weight in, as he has some experience with that (and examples).
Toomas Vooglaid
@toomasv

@dsunanda There are three ways to rotate a figure:
rotate (takes also floats for angle):

t: 0 view [box 200x200 rate 10 draw [
    rotate 0 100x100 box 50x50 150x150
] on-time [face/draw/2: (t: t + 1) % 360]]

transform (takes also floats for angle):

t: 0 view [box 200x200 rate 10 draw [
    transform 100x100 0 1 1 0x0 box 50x50 150x150
] on-time [face/draw/3: (t: t + 1) % 360]]

and matrix:

t: 0 view [box 200x200 rate 10 draw [
    matrix [0 0 0 0 0 0] box -50x-50 50x50
] on-time [t: t + 1 face/draw/2: reduce [
    (cosine t) (negate sine t) (sine t) (cosine t) 100 100
]]]
lepinekong
@lepinekong_twitter
@toomasv great snippets thanks
Toomas Vooglaid
@toomasv
@lepinekong_twitter Thanks. Last one was not good -- too much copying. Here is better:
t: 0 view [
    box 200x200 rate 10 draw [matrix [0 0 0 0 100 100] box -50x-50 50x50] 
    on-time [t: t + 1 
        face/draw/2/1: cosine t
        face/draw/2/2: negate sine t
        face/draw/2/3: sine t
        face/draw/2/4: cosine t
]]
Toomas Vooglaid
@toomasv

Here is matrix rotation combined with scaling...:

t: 0 view [box 200x200 rate 10 draw [matrix [0 0 0 0 100 100] box -50x-50 50x50] 
    on-time [t: t + 1 
        face/draw/2/1: cosine t face/draw/2/2: 1.5 * negate sine t 
        face/draw/2/3: 1.5 * sine t face/draw/2/4: cosine t
]]

...skewing...:

t: 0 view [box 200x200 rate 10 draw [matrix [0 0 0 0 100 100] box -50x-50 50x50] 
    on-time [t: t + 1 
        face/draw/2/1: .5 * cosine t face/draw/2/2: negate sine t 
        face/draw/2/3: sine t face/draw/2/4: 1.5 * cosine t
]]

... and translation:

t: 0 view [box 200x200 rate 10 draw [matrix [0 0 0 0 100 80] box -50x-50 50x50] 
    on-time [t: t + 1 
        face/draw/2/1: cosine t face/draw/2/2: negate sine t face/draw/2/3: sine t 
        face/draw/2/4: cosine t face/draw/2/6: face/draw/2/6 + 10 - (t % 21)
]]
dsunanda
@dsunanda
Thanks for the rotation code - I'll have some fun playing with that soon.
Toomas Vooglaid
@toomasv
This is funnier "jumping square":
t: 0 view/tight [box 200x200 rate 10 draw [rotate 180 100x100 matrix [0 0 0 0 100 80] box -50x-50 50x50] 
    on-time [t: t + 1 
        face/draw/5/1: cosine t face/draw/5/2: negate sine t face/draw/5/3: sine t 
        face/draw/5/4: cosine t face/draw/5/6: face/draw/5/6 + 10 - (t % 21)
]]
lepinekong
@lepinekong_twitter
@toomasv clap!
GiuseppeChillemi
@GiuseppeChillemi

Hi,
if I have a function which accepts a block of block like:

blk: [[a] [b]]

and I want to include this data in a bigger block like:

blk2: [one [[a] [b]] two [[c][d]]]

And provide to the function a block of my choiche without picking (copying) it

If I move the index of the series to the block next to ONE

myblock: find/tail blk2 'one

>> probe myblock
= [[[a] [b]] two [[c][d]]]

I whish to

>> probe myblock
= [[a] [b]]

Without anything which involves a (memory) copy

Vladimir Vasilyev
@9214
@GiuseppeChillemi I don't follow, you want to select a block from another block?
GiuseppeChillemi
@GiuseppeChillemi
@9214 select involves a copy, I don't want to copy on selection, I which to access it like it is a: [[a] [b]]
*I wish
Vladimir Vasilyev
@9214

select involves a copy

No, it doesn't.

GiuseppeChillemi
@GiuseppeChillemi
no ?
I supposed it in rebol
Vladimir Vasilyev
@9214
>> block: [a [b c]]
== [a [b c]]
>> append select block 'a 'd
== [b c d]
>> block
== [a [b c d]]
GiuseppeChillemi
@GiuseppeChillemi
so, which is the difference between find/tail and select ?
Vladimir Vasilyev
@9214
I don't recall any series actions doing an explicit copying.
@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]