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
[18281]
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
sqlab
20-Sep-2010
[18302]
I disagree. Alternatives are not always better.

If I traverse a series and depending of the data, I change an element 
or remove it, then I regard forall as appropriate.
Ladislav
20-Sep-2010
[18303x2]
You can do whatever you like, but removal of N elements from a block 
of length N is O(N * N) usually, if not done cleverly.
(this has been discussed at length on the ML)
sqlab
20-Sep-2010
[18305]
I do not dispute, that there a faster methods for removal.
But removal is not the only way to deal with series.
Ladislav
20-Sep-2010
[18306]
Gabriele, having a look at

http://www.rebol.org/ml-display-message.r?m=rmlXHTS


, I wonder, whether it can handle equivalents of such expressions 
as [3 ** 3 ** 3], which my

http://www.fm.tul.cz/~ladislav/rebol/evaluate.r

handles as follows:

>> std [3 ** 3 ** 3] translate
== [power 3 power 3 3]
Anton
20-Sep-2010
[18307]
It doesn't, unless you use parens.
>> eval [3 ^ 3 ^ 3] ;== none
>> eval [3 ^ (3 ^ 3)] ;== 7625597484987.0
Gabriele
20-Sep-2010
[18308]
Ladislav: I don't remember, I guess Anton is right. I wrote that 
rather quickly, mostly as a PARSE example. I haven't really used 
that script after that, so I've never had a good reason to improve 
/ complete it.
Ladislav
20-Sep-2010
[18309]
No problem, sure, I was just curious
Gabriele
20-Sep-2010
[18310]
:-) it would be nice to write a proper, complete compiler (including 
optimization etc.). your script may be already be close enough?
Ladislav
20-Sep-2010
[18311x4]
I hope it is simpler to start with, since it uses USE-RULE ;-)
...and it already describes more variants, so it shows how one can 
adjust it
nevertheless, it was originally meant as a "teaching code", so I 
do not claim completeness, or fitness for other purposes
But, as Gregg mentioned, I think that one of its advantages is that 
it shows how to implement different priority/associativity rule sets
DideC
20-Sep-2010
[18315]
Thanks to all for your "path related" thought..
Maxim
20-Sep-2010
[18316]
Anton... did you CC your idea of lit word in paths?
Anton
20-Sep-2010
[18317]
Maxim, yes.  [now I can sleep].
Maxim
20-Sep-2010
[18318]
;-)
Geomol
21-Sep-2010
[18319x3]
Something to consider:

blk/'a/b
is a valid path today:

>> blk: ['a [b 0]]
>> blk/'a/b
== 0


If ' is made to be an escape, when followed by an integer, then it 
might be a bit confusing. On the other hand, I see lit-paren! as 
an usable new datatype, and in that case, it's kinda like an escape, 
when used in path notation. Something like:

>> blk [(a b) 0]
>> blk/'(a b)

which isn't valid today.
It should have been with a colon:
>> blk: [(a b) 0]
Remember you can always do:

>> blk: [1 a 2 b]
== [1 a 2 b]
>> second find blk 2
== b

But of course that's way more than just writing: blk/'2
Maxim
21-Sep-2010
[18322x2]
why do you say blk/'1/is confusing?  it means use the integer litterally, 
not as an index.
or should I say, not as an ordinal index
Geomol
21-Sep-2010
[18324x5]
It can be a bit confusing, because blk/'a mean: search for lit-word 
'a in blk. So I would guess, blk/'1 mean: search for lit-integer 
'1 in blk. That would be my initial though, when I saw this the first 
time.
*thought*
Or not lit-integer, but lit-word '1 (assuming '1 would be a valid 
lit-word).
When reconsidering all this again, I would like to question, how 
blk/'a works today. Why not evaluate 'a to a? Parens are evaluated 
in paths:

>> blk: [1 a 2 b]
== [1 a 2 b]
>> blk/(1 + 1)
== a
The reason, I would expect  'a to be evaluated in a path, is because 
it is when standing alone:

>> type? 'a
== word!

Like parens are:

>> (1 + 1)
== 2


It can be argued, that different behaviour, when used in a path, 
is a bad thing.
Ladislav
21-Sep-2010
[18329]
Geomol:

>> blk: [(a b) 0]
== [(a b) 0]

>> blk/(quote (a b))
== 0
Geomol
21-Sep-2010
[18330]
:-) Yeah, you've pointed me to QUOTE several times in the past. I 
haven't learned to use it yet though.