@GiuseppeChillemi
When you set words to some values, <word>: <value>
(e.g. the-answer: 42
). <value>
will be evaluated.
integer!
(e.g. 42
) will give you 42
(the value looks the same). float!
(e.g. 3.14
) will give you 3.14
string!
, pair!
(2x14
) and some more - like aboveThere are some "special" cases:
path!
(e.g. foo/4
) will be evaluated. For example you have foo: [1 2 3 4]
, when you set value to some word, val: foo/4
, path foo/4
will be evaluated. foo/4
will be changed, in this case, to the 4th value of the foo
(4
).lit-path!
(e.g. 'foo/4
) will be evaluated to path!
foo/4
. As you know already, you can get
or reduce
it. w: foo/4
and get w
will give you 4
(4th element of the foo
).get-path!
will get you value that it points to. It is like path!
. However with path!
you cannot get function!
s for example (funs: #() funs/not-fibo: func [a] [ a - 10]
, funs/not-fibo
will try to call not-fibo
in the funs
map, it will raise an error because you haven't provided an argument). You can get such value by using lit-path!
: my-fun: :funs/not-fibo
. After this you can call it like any other function: my-fun 12
block!
every value within a block will be "the same", it won't use "special" rules that govern path!
, lit-path!
and get-path!
. For example you have a block my-block: [42 3.14 "string" word :get-word 'lit-word set-word: [another block with a word]]
, you can see that *-path
are not evaluated:
Helper:
foreach element my-block [
print "Value: "
probe element
print "Type: "
print mold type? element
print "####"
]
Output:
Value:
42
Type:
integer!
####
Value:
3.14
Type:
float!
####
Value:
"string"
Type:
string!
####
Value:
word
Type:
word!
####
Value:
:get-word
Type:
get-word!
####
Value:
'lit-word
Type:
lit-word!
####
Value:
set-word:
Type:
set-word!
####
Value:
[another block with a word]
Type:
block!
####
And last value [another block with a word]
will not evaluate words inside (you have no errors because there is no another
and a
word defined).
Red for Windows version 0.6.3 built 26-Mar-2018/1:14:22+02:00
@nedzadarek
Maybe yesterday we were after midnight but my question was different:
This is your code:
foo: [bar [baz 42]] w: 'foo/bar/baz get w ; == 42 reduce w ; == 42
I need something like:
z: bar
foo: [bar [baz 42]]
w: 'foo/(z)/baz
get w
; == 42
reduce w
; == 42
(I am just closing my day at work, I'll read it later)
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 ?
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
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
@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.
@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
]]]
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
]]
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)
]]
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)
]]
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
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.