05.04.2009, =D7 15:42, Henrik Mikael Kristensen =CE=C1=D0=C9=D3=C1=CC(=C1)= :
> > 2009/4/5 =3DF7=3DC1=3DCC=3DC5=3DD2=3DC9=3DCA = =3DED=3DD9=3DD4=3DC9=3DCE=3DD3=3DCB=3DC9=3DCA =20 > <valeri.mytinski=3D > @gmail.com>: >> >> >> 05.04.2009, =3D3DD7 10:34, Graham Chiu =20 >> =3D3DCE=3D3DC1=3D3DD0=3D3DC9=3D3DD3=3D3DC1=3D3DCC(=3D > =3D3DC1): >> >>> >>> If you wish to create a new empty block each time, you would do =20 >>> this =3D3D=3D > 20=3D3D >> >>> instea=3D3D3D >>> d >>> >>> loop 2 [ append copy [] 3 ] >>> >>> which would be the same as >>> >>> append [ ] 3 append [ ] 3 >>> >>> Graham Chiu >> >> >> Thanks for this example. >> Sorry, now I understood nothing. >> >> Why >> >> loop 2 [append [] 3] >> >> is equivalent to >> >> append append [] 3 3 >> >> that is some sort of "nested" expressions - result of first 'append =20= >> is >> INSERTED as parameter for second 'append, >> >> while >> >> loop 2 [ append copy [] 3 ] >> >> is equivalent to >> >> append [ ] 3 append [ ] 3 >> >> that is some sort of "sequence" expressions - first 'append is >> FOLLOWED by second 'append? Why does not parameter substitution >> done? > > You are entering a deep issue in REBOL, namely that certain values are > aggressively reused and that REBOL works by copying as little data as > possible by default to let it be very efficient. That might be a bit > hard to understand at this point. > > Let's look at the loop: > > loop 2 [append [] 3] > > And strip the stuff in front of the block: > > [append [] 3] > > When you specify the loop like this, REBOL immediately recognizes the > [] you specify as being literally the same memory position that APPEND > should work on, each time it runs through the loop. This is very > important to understand. > > In a sense the loop becomes self modifying. This is a neat trick that > lets you avoid referencing the block from a word, but it can also be a > nasty trap, if you don't realize this. > > So when you try this one: > > append [] 3 append [] 3 > > You have two different blocks at two different memory locations. > > When you do a COPY, the block you work on is never the same, but =20 > always a c=3D > opy. > > This trick works everywhere, in blocks, loops, functions, etc. But be > careful when you use it. > > REBOL has a function for testing the SAMEness of series/blocks, i.e. > whether two series you are testing on, is the same one at the same > memory location. It's called SAME?. > > --=3D20 > Regards, > Henrik Mikael Kristensen Thank you very much, Henrik! Valeri PS Do you know more tricks that anyone must know BEFORE start real coding? :-) -- To unsubscribe from the list, just send an email to lists at rebol.com with unsubscribe as the subject.
