r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Ladislav
19-Sep-2010
[18252x3]
To make it absurd, even REPEAT could be modified to use the "two 
in one argument passing method". Would you find it proper?
...and if not, why?
...and I don't think, that an argument "because that is how REPEAT 
differs from FORALL" makes any sense as an argument
Maxim
19-Sep-2010
[18255x2]
well repeat already uses 2 arguments.
ah sorry... read your statement the wrong way.
Ladislav
19-Sep-2010
[18257x3]
In my opinion, different functions are defined not because we like 
to have different functions, but because they do different things 
for us
Assuming (hypothetically), that FORALL did not use the "two in one" 
method, the Graham's example would look as follows:

forall b a/b [print a/b/1]


, which is preferable, since it clearly suggests, that the word 'b 
in the BODY is actually not the same word as in a 'b
Aha, it seems, that I noticed one more strangeness in this. Why actually 
the expression:

forall (in a 'b) [print a/b/1]

prints what it does in R3?
Graham
19-Sep-2010
[18260]
the reason I use 'forall is so I can remove elements of a series 
as I traverse it.

so

forall series [ if series/1 = something [ remove series ]]


which 'foreach doesn't allow because you don't have a reference to 
where you are in the series
Maxim
19-Sep-2010
[18261x3]
use remove-each its MUCH faster.
using your example it becoms.

remove-each [if series/1 = something]
actually... its:
remove-each [series/1 = something]
Henrik
19-Sep-2010
[18264]
remove-each is indeed much faster and it's a native.
Maxim
19-Sep-2010
[18265]
argh... I'm reallly tire.
Graham
19-Sep-2010
[18266]
Only because Carl made it native!
Maxim
19-Sep-2010
[18267x2]
remove-each item series [item = something]
not just because its native... its in the way it actually manages 
the removal... it only re-creates the series once, when its done.


using other methods, you are tampering with the series at each change, 
and it has to copy the series over and over.
Graham
19-Sep-2010
[18269x2]
remove-each mistake maxs-mistakes [ true ] ?
Is that the syntax?  :)
Maxim
19-Sep-2010
[18271]
yep
Steeve
19-Sep-2010
[18272]
Maxim about remove-each, what do you mean by: 
- "it only re-creates the series once, when its done".
Maxim
19-Sep-2010
[18273]
what I have been explained is that it makes a new series and only 
copies when remove is false.  then replaces the pointer within the 
series to the new one.
Ladislav
19-Sep-2010
[18274x2]
Steeve, removal of one object from a block is an O(n) operation, 
where n is the length of the series. That would make a naive implementation 
O(n ** 2), while REMOVE-EACH is just O(n)
...but, actually, no re-creation of series happens anyway
Maxim
19-Sep-2010
[18276x3]
ah yes.. true.. it just copies over itself.
Ladislav, one question I've always wondered and I'm sure you know.
does CLEAR only set the soft size of a series or does it actually 
truncate the internal buffer of a series?
Ladislav
19-Sep-2010
[18279x3]
the former
CLEAR is just O(1)
although,maybe, that in some cases, the GC is able to reassign a 
smaller part of memory to the series, but I doubt it
Steeve
19-Sep-2010
[18282]
Are you sure about that ?
I don't tink remove-each create any temporary buffer.

when I compare the footprint of foreach and remove-each, they are 
the same

(which means nothing, because i don't see why foreach need to create 
so much temporary blocks)
Ladislav
19-Sep-2010
[18283]
Sure about what? I did not tell, that REMOVE-EACH was creating any 
memory buffer
sqlab
19-Sep-2010
[18284]
I prefer the actual "two in one" behavior of forall , it allows to 
retrospect where an error happened.
Ladislav
19-Sep-2010
[18285]
Anton: how?
sqlab
19-Sep-2010
[18286]
and to continue from that point
Ladislav
19-Sep-2010
[18287]
did you check whether your approach is usable in R3?
sqlab
19-Sep-2010
[18288]
seems to work
>> a: [ 1 2 3 4]
== [1 2 3 4]

>> forall a [if a/1 = 3 [a/1 / 0] print a]
1 2 3 4
2 3 4
** Math error: attempt to divide by zero
** Where: / if forall
** Near: / 0

>> a
== [3 4]
Steeve
19-Sep-2010
[18289]
(i was aiming Maxim)
Ladislav
19-Sep-2010
[18290]
Aha, then it was an error on my part (the behaviour of FORALL). I 
thought, that its behaviour changed.
Izkata
19-Sep-2010
[18291]
Using 'forall with 'remove will skip the element after a removed 
one (in R2 at least, don't know if it changed in R3)

>> X: [1 1 2 2 3 3 4 4 5 5 6 6 7 7]
== [1 1 2 2 3 3 4 4 5 5 6 6 7 7]
>> forall X [if odd? X/1 [remove X]]
== [7]
>> X
== [1 2 2 3 4 4 5 6 6 7]
Maxim
19-Sep-2010
[18292]
which is one reason why I use until   ;-)
Anton
19-Sep-2010
[18293]
Gregg, I should make it clear that my alternate suggestion was *not* 
to add a new datatype, but to extend the path syntax with an escape 
char (which, if it would be ^, would also unfortunately reduce the 
syntax of words a little bit).


Perhaps ' is a better path escape char, because '1 is currently not 
any valid rebol datatype, so adding it would not require reducing 
the syntax of any existing datatype, as using ^ would. So,  values/'1/dos/new 
 would not contain any new datatype, it would simply extend the path 
syntax with an escape char which must be followed by an integer.


This escape mechanism should also work when followed by a paren, 
allowing evaluation of any expression (as long as the evaluation 
of the paren results in an integer). eg.
	n: 3
	values/'(n - 2)/dos/new
Maxim
19-Sep-2010
[18294x4]
it nicely follows the use of lit words too.  I really like this idea.
and as you say, its a simple added case in the run-time evaluation 
of paths, as well as an additional variation to add in the lexical 
parsing of paths.
overall, not such a big deal to implement.
with the recent change of issue  to word base type, this becomes 
even more usefull.
Ladislav
19-Sep-2010
[18298]
Everyone using FORALL to remove more elements deserves what he gets 
(sloooow performance, and complications)
Maxim
19-Sep-2010
[18299]
there should be a note in the 'FORALL help ...   

** do not use this function  **  all the alternatives are better 

;-D
Gregg
19-Sep-2010
[18300]
Anton, sorry if I misspoke. I think it was Steeve that followed up 
your idea with lit-integer!
Ladislav
19-Sep-2010
[18301]
Actually, if you want to remove more elements from a block, then 
you either need to know what you are doing, or you should use the 
REMOVE-EACH function, eitherwise you quite likely get O(n ** 2) time, 
which is sloooow