Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 01 2018 17:34
    @greggirwin banned @BIjeuca_twitter
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:20
    @PeterWAWood banned @TimeSeriesLord
GiuseppeChillemi
@GiuseppeChillemi
try print-it many times
Vladimir Vasilyev
@9214
Body of print-it is data, just like everything else in Red. This data is represented by block of 9 elements, and while 2nd and 9th element looks identical, they're not the same thing.
Vladimir Vasilyev
@9214
perhaps my answer with pointers and stuff was misleading :confused:
Vladimir Vasilyev
@9214
>> foo: func [x][s: [no spoon] probe append s x poke body-of :foo 2 [no spoon]]
== func [x][s: [no spoon] probe append s x poke body-of :foo 2 [no spoon]]
>> foo 'whatsoever
[no spoon whatsoever]
== [no spoon]
>> body-of :foo
== [s: [no spoon] probe append s x poke body-of :foo 2 [no spoon]]
I wonder if self could be supported in specs?
Vladimir Vasilyev
@9214
>> foo: func [x][s: "before" probe append s x s: "after" probe s]
== func [x][s: "before" probe append s x s: "after" probe s]
>> foo "!!!"
"before!!!"
"after"
== "after"
>> body-of :foo
== [s: "before!!!" probe append s x s: "after" probe s]
Step by step:
  • s: means next time when you see s, evaluate it to the result of an expression that follows me, whatever it might be;
  • "before" is just a string to which s word is bound now, as implied by s: syntax;
  • append is word that is bounded to a function, that function receives two arguments that follow append word;
  • the first argument, s, evaluates to the thing that follows s:, namely "before" string, or, more specifically second element of foo's body;
  • the second argument, x, evaluates to whatever we've passed to foo;
  • now, we have second element of foo's body and some value; what append does is just this: append some value to second element of foo's body;
  • next s:, just like the first one, simply states next time when you see s, evaluate it to the result of an expression that follows me, whatever it might be;
  • and "after" is what follows s:, it's the 8th element of foo's body, all subsequent s words will be evaluated to it;
  • probe is a word that is bounded to function that blah-blah-blah;
  • finally, s is evaluated to the 8th element of foo's body, and it is what it is, just "after".
Gregg Irwin
@greggirwin

@GiuseppeChillemi, see https://github.com/red/red/wiki/Why-do-I-have-to-copy-series-values%3F

Or maybe this will help:

print-it: func [] [
    ""
    insert first body-of :print-it "ha"
    print first body-of :print-it
    ""
]
>> print-it
ha
== ""
>> print-it
haha
== ""
>> print-it
hahaha
== ""
Same as @9214's answer, without the explanation. :^) That is, the two empty strings in your func exist independently of any words that refer to them. So, at the end of your func, you have str point to the second one, but it's never used. On the next call, str is set to refer to the first string, which has now been modified, and you print that.
Vladimir Vasilyev
@9214
All modifications are happen in-place, i.e. they modify original data. If you have a cup and ask Red to break that cup, it will break that cup instead of magically poofing broken cup out of air next to the original one.
Gregg Irwin
@greggirwin

From the end of the wiki page:

One more thing. The colon (:) suffix in a word is not an assignment operator (as in other languages), it's part of the set-word! datatype literal syntax. When evaluated, it binds the word to the result of next expression. It doesn't do anything more than that. So a: "" does not "reset" or "reinitialize" the "variable" a. That is an incorrect interpretation, it just makes the word a refer to the literal string "" which follows it.

Vladimir Vasilyev
@9214
but if you're just curious how broken cup might look like and don't want your precious cup to be mutilated, use copy on your cup, that way Red will make a new cup identical to yours (yeah, Red knows pottery) and will break that copy of a cup
Gregg Irwin
@greggirwin
I thought it was a vase he broke when he met the oracle. :^\
Vladimir Vasilyev
@9214
which vase? CRUSH SOUND
Gregg Irwin
@greggirwin
Yes! Well played.
Vladimir Vasilyev
@9214
though, I still can't bridge that mental gap between when data is evaluated and becomes another data
Gregg Irwin
@greggirwin
Now you can edit your post and say "What cup?"
Vladimir Vasilyev
@9214
I mean, code is what to do, something active, and data is something to manipulate upon, something passive
if everything is data and everything is passive, how something can happen at all?
Greg T
@gltewalt
Do!
Vladimir Vasilyev
@9214
I know that this active/passive presupposition is lame and it comes from another languages, but it just doesn't click
well, do is data too
and of course you can do do, but then first do is data too...
Greg T
@gltewalt
The word is
The soul is the evaluator, isn't it?
Vladimir Vasilyev
@9214
uh-uh, so at least evaluator is code
Greg T
@gltewalt
I'm guessing
We will have to consult @dockimbel for deep diving, I think
Vladimir Vasilyev
@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?
Vladimir Vasilyev
@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
@sptorin_twitter
@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?
Vladimir Vasilyev
@9214
@sptorin_twitter tricky question
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.
Vladimir Vasilyev
@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
@sptorin_twitter
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
@sptorin_twitter

@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
@sptorin_twitter
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.