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
geekyi @geekyi assumes @AlexanderBaggett got the answer in red/help
Michael
@michaeldesu

Please help me understand about initialising a series in a function. I have the following test case. The aim is to have an empty block each time the function is run.

test-me: function [str [string!]] [
    my-series: []
    print [">" my-series]
    foreach x str [append my-series to-integer to-string x]
]

test-me "123"
test-me "456"
test-me "789"

However the output emitted by the print statement in the function shows me the series is not initialised to empty each time the function is called, i.e. I see:

>
> 1 2 3
> 1 2 3 4 5 6

so I guess my-series: [] is not the best way to init an empty series for this case.

xqlab
@xqlab
Use
my-Series: copy []
or
my-Series: clear []
in order to initialize anew
as long as no GC clear [] is recommended
Michael
@michaeldesu

@xqlab thanks alot - clear is good. This is a bit counter-intuitive, unless a series can be like a static variable (in the way I did it). I guess I take it away as another learning :-). The reason why it's confusing is in the REPL it seems to work logically:

>> a: [1 2 3]
== [1 2 3]
>> a: []
== []
>> a
== []

of course it might just be the behaviour in a function is different.

Gregg Irwin
@greggirwin
The REPL does an implicit copy, which is confusing. Learning about copying series is a rite of passage in Redbol. :^)
Michael
@michaeldesu
thanks @greggirwin
Nenad Rakocevic
@dockimbel
@michaeldesu If you create your block dynamically, you would not run into such issue:
my-series: make block! 1 or doing some preallocation: my-series: make block! length? str.
Though, the clear [] is the most memory-saving option.
Michael
@michaeldesu
thanks alot @dockimbel
Michael
@michaeldesu
is it by design that my-series: [] acts like a static variable (i.e. no clear or copy in use), or this is a side-effect of my bad coding
Gregg Irwin
@greggirwin
It is by design.
Michael
@michaeldesu
thanks @greggirwin - ok so it's a potentially useful feature to keep in mind for the future
Gregg Irwin
@greggirwin
And it is true for all series variables in functions.
GiuseppeChillemi
@GiuseppeChillemi
A good question would be: why it has been designed in such a way !
Gregg Irwin
@greggirwin
Yes, it catches everyone not long after they start Reducing, but it is definitely intentional.
Nenad Rakocevic
@dockimbel
@michaeldesu @GiuseppeChillemi There is no specific design rule there, it is just a consequence of how the language works (both Red and Rebol). It boils down to understanding what word: [] is, and how it is evaluated. It is deeply different from what you would have in another language (like in JS: v="", or v=[]). Understanding such expression is a key part of understanding Redbol.
GiuseppeChillemi
@GiuseppeChillemi
@dockimbel Is there any documentation helping us undestand this and the global picture behind this design ?
Gregg Irwin
@greggirwin
See the link I just posted.
Nenad Rakocevic
@dockimbel
@GiuseppeChillemi There is this wiki entry posted by Gregg above, and otherwise, the whole Rebol documentation.
GiuseppeChillemi
@GiuseppeChillemi
Which just disappeared as we lost rebol.com
:(((
Michael
@michaeldesu
agree - that link probably should be required reading by any newcomer
Nenad Rakocevic
@dockimbel
A fundamental cause is that there is no distinction between "code" and "data" in Redbol. word: [] is data, which eventually gets evaluated. In JS, v=[]; is just code.
Michael
@michaeldesu
wow - did rebol.com recently die?
Gregg Irwin
@greggirwin
There are just some domain expirations going on.
Michael
@michaeldesu
"there are no "variables" in Red" - wow. Yeah may as well check all the preconceived notions about other languages at the door :-)
Nenad Rakocevic
@dockimbel
"variable" is a convenient approximation we use, but we know that the meaning behind it, is different in Redbol.
Golden rule of learning Red/Rebol: forget about the programming languages you already know, that knowledge will get in the way (unless it's Lisp ;-)), start with a fresh mindset.
Michael
@michaeldesu
GiuseppeChillemi
@GiuseppeChillemi
Noooo, it makes me feel strange reading you using "Redbol" word....
I am just reading the first link
Michael
@michaeldesu
so I guess an analog for 'variables' is like a key: value pairing? where words are like the keys? and value is the actual data (or function). I guess it doesn't matter. So I can see there really are no variables, it's all just data (and even the labels).
Gregg Irwin
@greggirwin
Redbol is our word to encompass all rebol-like languages.
@michaeldesu, right, with each pairing being unique to a context.
A context (and objects are contexts) can be viewed as 2 columns, the first being the words and the second being the values they refer to.
Nenad Rakocevic
@dockimbel
@michaeldesu That R3 doc is to be taken with a grain of salt, as it tries to fit the concept of "variable" into Rebol, to ease the learning process, but I think a clear cut would be better, to avoid newcomers building a wrong mental model of how words and binding work.
PeterWAWood
@PeterWAWood
@dockimbel @greggirwin @GiuseppeChillemi Correction - The rebol.com domain name has not yet expired. I can access the homepage only. My ISP has probably cached the page.
Unfortunately this trick only seems to regain access to the Rebol.com homepage.
GiuseppeChillemi
@GiuseppeChillemi

@dockimbel The last 5 lines of the documentation cleared everything:

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.

It is time I read the Bindology article from Ladislav....
@dockimbel > but I think a clear cut would be better, to avoid newcomers building a wrong mental model of how words and binding work.
In fact I have a wrong mental model of this.
Gregg Irwin
@greggirwin
https://gist.github.com/9214/1dd30a88383a3e46edf45e33e9def3a7 if you want to melt your brain, or a spoon, a bit.
GiuseppeChillemi
@GiuseppeChillemi
I would like to see how code/data is structured underneath in a structured manner. Is there any graph/table
Nenad Rakocevic
@dockimbel
Variables in most other languages are just labels on memory storage spaces. The variable type is the type of the value stored into that memory place. In Redbol, a word is a first-class datatype, of type word! and that never changes. A word can exist and be manipulated, without referring to any other value. A word can refer to values of any type. Making a word refer to a value (let's say a string), does not change the type of the word, it is still word!. So, in Redbol, you have two distinct entities: word and the referred value. Such distinction does not exist in most other languages, which just have "variables", that's why such term can be misleading in Redbol.
Petr Krenzelok
@pekr
@greggirwin Is REPL doing an implicit copy of the series a correct behaviour? Don't remember, how it was in R2 and can't check right now, typing on a phone ...
GiuseppeChillemi
@GiuseppeChillemi
@greggirwin I am not able to translate correctly the english word SPOON.
The volcabulary say it is "cucchiaio", the food table companion tool of a FORK