New to Red language? Ask any question about it here, move to red/help room for deeper help with your Red code.
@
in Firefox, I have to copy it)
pair!
, tuple!
, time!
and date!
values.
not sure what I meant either :D
>> f: func [x][y: 0 y: y + x]
== func [x][y: 0 y: y + x]
>> f 5
== 5
>> body-of :f
== [y: 0 y: y + x]
>> f: func [x][y: [0] y/1: y/1 + x]
== func [x][y: [0] y/1: y/1 + x]
>> f 5
== 5
>> body-of :f
== [y: [5] y/1: y/1 + x]
what if I want y
in the first example to be modified as in the second example, only without explicit block wrapping?
ref!
is something like a pointer to series position
>> 1.2.3.4.5.6.7.8.9.10.11.12
== 1.2.3.4.5.6.7.8.9.10.11.12
>> 1.2.3.4.5.6.7.8.9.10.11.12.13
*** Syntax Error: invalid tuple! at "1.2.3.4.5.6.7.8.9.10.11.12.13"
*** Where: do
*** Stack: load
float!
handle!
datatype for that?
The ref!
name was discussed quite heavily at one point, on atlme too, but is not finalized. We also have tuple!
with a different meaning than in other languages. What we need to do is ask: "What is the main purpose of this datatype? What does it represent?" People new to Red have a lot of concepts to learn, and old habits and ideas to un-learn.
I'm short on time, but will try to write up thoughts in the future. But ref!
values aren't just for human handles in chat (e.g. @pekr). They could be used to refer to locations in code, as in a cross-reference, a specific message in a chat, a point in time, etc. That is, it refers to something. And since Red has no concept of a pointer, though R/S does, there shouldn't be much confusion after initial exposure.
set-word!
is - it's just this type of marker. set-word!
points to location in source code, while variables usually point to location in memory. But there's no variables in Redbol. In a vague sense, script's body is it's own memory. Entire script is just one big chunk of self-modifiable state, which can be trivially serialized, saved and restored.
When you:
STR: "" ;"" is data structure position 2
insert STR "ah"
STR: "" ;"" is data structure position 7
insert STR "bb"
you are stating: SET STR to what you find at position 2 of your data structure ("")
Then: insert on what is rapresented in position 5 (word "ah") on position 2
Then: set STR to what is rapresented in position 7 (second "") and use THIS POSITION in further reference to get/set the contend of STR
then insert on POSITION 7 "bb"
If this code loops, the first STR will take again the value "ah" insted of "BB" as it will use the content of position 2. The second one will use te conent of position 7.