Why this works ?
[1/8] from: gchillemi::aliceposta::it at: 20-Nov-2005 1:29
Here is a piece of code taken from the server monitor.
sites: [
; List of URLs (http or tcp are allowed)
http://www.rebol.com
http://www.rebol.net
http://mail.rebol.net
http://mail.rebolot.com
tcp://www.altme.com:5400
]
foreach site sites [
; Convert any http to tcp on port 80
if find/match site http:// [
insert remove/part site 7 tcp://
append site ":80"
]
]
I have supposed that "site" contains a copy of the value taken from
sites
block. Ok, lets suppose it referrers to the site series: why does
append works on the single block entry and not on the end of the block ?
Giuseppe
[2/8] from: antonr::lexicon::net at: 20-Nov-2005 12:53
Hi Giuseppe,
Your assumption that SITE is a copy is incorrect.
Each iteration through the FOREACH body block,
SITE is set to a new url. Essentially, SITE is a
pointer
to the original url. There is no copying
happening.
Therefore, INSERT, REMOVE and APPEND are all working
on the original urls.
Anton.
[3/8] from: gchillemi::aliceposta::it at: 20-Nov-2005 9:59
> Hi Giuseppe,
> Your assumption that SITE is a copy is incorrect.
> Each iteration through the FOREACH body block,
> SITE is set to a new url. Essentially, SITE is a
> "pointer" to the original url. There is no copying
> happening.
SITE points to a subseries whose first element is the first char of the
element of the series and whose tail is set to to the last charc.
> Therefore, INSERT, REMOVE and APPEND are all working
> on the original urls.
And on the original series which is enlarged according.
This is written nowhere in the manual and you should read it plus some
articles plus you must read some code to understand they are not copies but
pointers. Ok, we already know this: documentation needs to be revised.
Giuseppe Chillemi
[4/8] from: greggirwin:mindspring at: 21-Nov-2005 8:36
Hi Giuseppe,
GC> I have supposed that "site" contains a copy of the value taken from
GC> "sites" block.
In REBOL, variables don't "contain" values, they reference them; hence
Anton's pointer metaphor. This is how REBOL can be dynamic, yet
strongly typed. Values have type; variables don't, they can refer to
anything.
GC> Ok, lets suppose it referrers to the site series: why does append
GC> works on the single block entry and not on the end of the block ?
It will work on the last value in a block if that value, itself, is a
series. If the last value in SITES was, say, $100.00 or 'testing, it
would fail.
Even better than assuming, sprinkle some print statements in there.
See what the values are, what type they are, whether they're EQUAL? or
the SAME?, etc.
-- Gregg
[5/8] from: antonr:lexicon at: 22-Nov-2005 11:11
Hi Giuseppe,
There *is* good documentation on copying series, here:
http://www.rebol.com/docs/core23/rebolcore-6.html#section-5
See especially section 5.2 Deep Copies.
Anton.
[6/8] from: gchillemi:aliceposta:it at: 24-Nov-2005 13:00
> Hi Giuseppe,
> There *is* good documentation on copying series, here:
> http://www.rebol.com/docs/core23/rebolcore-6.html#section-5
Ciao Anton,
When I find this sentence:
The foreach loop moves through a series setting a word or multiple words in
to the values in the series.
I suppose that the word or multiple words get the value in the block
and not a reference to the value of the block.
Don't forget I and many other are old type programmers. The
documentation must explicit tell us that a reference is happening because we
think about a copy as the first and only working.
Giuseppe Chillemi
[7/8] from: volker:nitsch:gma:il at: 24-Nov-2005 15:13
On 11/24/05, Giuseppe Chillemi <gchillemi-aliceposta.it> wrote:
> > Hi Giuseppe,
> > There *is* good documentation on copying series, here:
<<quoted lines omitted: 8>>
> documentation must explicit tell us that a reference is happening because we
> think about a copy as the first and only working.
Good point. We really need a comparison with other languages, because
some things are special. Things like this:
- In rebol references are values. Series are not, you must reference them.
Copies are very explicit in rebol, when they are not mentioned, better
expect they do not happen.
That is true for functions too,
a: []
references the block in the functions code, not a copy of it.
Thats why you see all the
a: copy[]
in code.
- series-references contain a reference to a position in a series, not
only to the series itself. like a cursor in a text.
> Giuseppe Chillemi
>
> --
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
>
--
-Volker
Any problem in computer science can be solved with another layer of
indirection. But that usually will create another problem.
David
Wheeler
[8/8] from: antonr:lexicon at: 1-Dec-2005 2:09
Ciao Giuseppe,
Sorry if I was a bit quick with you.
I reboled so long it seems to me it should be "common knowledge".
I think you got the idea about series already, but I thought
about it, and I wanted to try to explain it better.
So please take a look at this new doc:
load-thru/update http://www.lexicon.net/antonr/rebol/gui/scroll-panel.r
do-thru/update http://www.lexicon.net/antonr/rebol/doc/rebol-values.r
Regards,
Anton.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted