## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• Jul 01 2018 17:34
• Dec 03 2017 05:53
@PeterWAWood banned @matrixbot
• Sep 28 2016 12:20
@PeterWAWood banned @TimeSeriesLord
Greg T
@gltewalt
I'm guessing
We will have to consult @dockimbel for deep diving, I think
@9214
It actually make sense if you think of a Red program as a copy book with simple math: you see 1 + 2 on the paper and you write down answer on the same paper. 1 + 2 is data, but then you process it and come up with an answer, it's a code, but only in your head.
@gltewalt 2deep4me
how can you, oh mighty Redbol gurus, live on such mental heights without your head exploding?
well, Frankenstein is a corpse until it's explicitly revived by an electricity :shipit:
Greg T
@gltewalt
So there has to be some force or 'do', right? It can't all be inert data, can it?
@9214
it all boils down to the fact that our Universe consists of strings and at the center of the Universe is a tiny Red v42.0.0 interpreter that constantly performs do load on everything
it's that simple, no Ph.D required
Greg T
@gltewalt

@GiuseppeChillemi You might want clear, but it's important to learn the copy way.

print-it: func [/local str][
str: ""
insert str "ha"
print str
clear str
]

Many print-it:

loop 20 [print-it "ha"]
sptorin
@9214 @greggirwin read your last messages and head explodes twice... Let a: "1234567890" and after a: "". This mean what somewhere in memory exist string "1234567890" and word a bound to it. After this we create new string "" and bound a to it. Now no one pointer look on "1234567890" - and this string must be garbage collected?
@9214
Gregg Irwin
@greggirwin
@sptorin_twitter, my guess is that the string can't be collected as long as the function exists. i.e. there is a value slot in the function body for that string, even though no word refers to it.
@9214
my thoughts are that as long as something is a part of the data (and everything is data), it can't just disappear (unless you explicitly delete it, i.e. modify data at run-time)
sptorin
a: "qwerty"
b: "qwerty"
c: "qwerty"
a, b, c - bounds to same data "qwerty"? In compiler mode, in interpreter mode?
PeterWAWood
@PeterWAWood
@sptorin_twitter Each of a, b and c are bound to a string! value. All three string! values initially contain the characters q,w,e,r,t, and y
>> a: "qwerty"
== "qwerty"
>> b: "qwerty"
== "qwerty"
>> c: "qwerty"
== "qwerty"
>> append a "a"
== "qwertya"
>> append b "b"
== "qwertyb"
>> append c "c"
== "qwertyc"
>> a
== "qwertya"
>> b
== "qwertyb"
>> c
== "qwertyc
This is how to bind words to the same value:
>> a: b: c: "qwerty"
== "qwerty"
>> append a "abc"
== "qwertyabc"
>> b
== "qwertyabc"
sptorin

@PeterWAWood this make three string in memory?

a: "qwerty"
b: "qwerty"
c: "qwerty"

If we look at your first example, this right - now three string in memory with content "qwerty"

Now make:

a: "qwerty"
a: "qwerty"
a: "qwerty"

Againg three string in memory?

PeterWAWood
@PeterWAWood

On reflection, it probably doesn't but I'm not certain.

If it does then values that are not bound to a word! or included in a collection (e.g. block!) will be garbage collected, once the garbage collector has been implemented.

sptorin
loop 100 [a: "qwerty"] - 100 times bound a to same value? Because value in block!?
PeterWAWood
@PeterWAWood
I think that a is bound to the value "qwerty" in the first line, in the second and third lines, Red does not rebind to a new value.
PeterWAWood
@PeterWAWood
>> stats
== 3317760
>> loop 100000 [a: "qwerty"]
== "qwerty"
>> stats
== 3317760
>> loop 100000 [a: copy "qwerty"]
== "qwerty"
>> stats
== 6238208
As I understand, set-word!s evaluate differently if the word needs to be added to the context from when the word has already been added to the context.
geekyi
@geekyi

Typing out a word(without pressing enter) creates 4 instances. Of those, 2 instances are 2-byte word encodings, one is history of whole console.
Pressing enter gives me an obvious error about the word having no value, and 8 more instances are created (which includes the error message).
Note that it's all done in the console on Win10.

So, depending on how things are done, it may take up different memory in ways one wouldn't have thought!
Also, being alpha software, there's still space for much improvement here.

GiuseppeChillemi
@GiuseppeChillemi
@9214 @greggirwin read your last messages and head explodes twice... Let a: "1234567890" and after a: "". This mean what somewhere in memory exist string "1234567890" and word a bound to it. After this we create new string "" and bound a to it. Now no one pointer look on "1234567890" - and this string must be garbage collected?
The answer has still not solved some points like this. Hope @dockimbel will help clarify.
Gregg Irwin
@greggirwin
I answered that as best I could @GiuseppeChillemi. If nothing refers to a value, it may be garbage collected. As long as something refers to it, it can't. :point_up: September 27, 2017 11:50 AM may be corrected by @dockimbel, but these are also details that could change, and may not be worth time answering right now.
When implementation details like this become important is when they affect users directly.
@dockimbel
@geekyi How to do you end up with those counts?

@GiuseppeChillemi

The answer has still not solved some points like this. Hope @dockimbel will help clarify.

I'm not sure what is missing from above explanations, but to answer your question, a series which is no longer referenced anywhere will be garbage -collected. If you put that string in a function body block, it is referenced.

@dockimbel

@9214

how can you, oh mighty Redbol gurus, live on such mental heights without your head exploding?

With Redbol, it's most of time simpler than you think. I'm trying to write down some general explanations of the core concept, for the Red documentation and eventually a blog article.

@9214
@dockimbel that will be great, because I feel that I lack strong mental model of what is really happening then I program in Redbol and it kinda limits my power. I would say that freedom is truly paralyzing ;)
btw, currently only series! could be modified in-place, am I right that with ref! datatype such self-modification will be doable with everything?
Rudolf Meijer
@meijeru
I thought that ref! was a re-designed issue!... :worried:
Boleslav Březovský
@rebolek
IIRC ref! is for @name
(I’m not sure why, but I can't type @ in Firefox, I have to copy it)
PeterWAWood
@PeterWAWood
@9214 I'm not certain that "currently only series! could be modified in-place" is correct. Though I may not understand what you are saying. object! and map! values can be modified in place. I believe that pair! and tuple! values can be modified in place.
@9214
@PeterWAWood
>> x: [1 2 3]
== [1 2 3]
>> reverse x
== [3 2 1]
>> x
== [3 2 1]
>> x: 1x2
== 1x2
>> reverse x
== 2x1
>> x
== 1x2
>> x: 1.2.3.4
== 1.2.3.4
>> reverse x
== 4.3.2.1
>> x
== 1.2.3.4
Rudolf Meijer
@meijeru
But,
>> x: 1.2.3
== 1.2.3
>> x/1: 4
== 4
>> x
== 4.2.3
This modification in place applies to pair!, tuple!, time! and date! values.
@9214

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?

I thought that ref! is something like a pointer to series position
reference
Boleslav Březovský
@rebolek
No, probably the name is confusing and should be changed.
@9214
so, ref! is sort of a @9214 mention?
another thing that I learned today is that tuple! is not limited in it's length (I thought that it should contain exactly 4 elements)
another thing that I learned today is that tuple! is not limited in it's length (I thought that it should contain exactly 4 elements)
tuple! is limited in length.