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

World: r3wp

[Core] Discuss core issues

BrianH
13-Oct-2011
[2449]
The ++ and -- functions are in R2 for convenience and compatibility, 
not for speed.
Ladislav
13-Oct-2011
[2450]
++ is native in R3
Geomol
13-Oct-2011
[2451]
yes and yes
BrianH
13-Oct-2011
[2452]
Still, I made them as fast as I could while still being compatible.
Geomol
13-Oct-2011
[2453]
So we would expect things like

	next 'series

to be faster aswell than

	series: next series
BrianH
13-Oct-2011
[2454]
But not as useful. The current NEXT can operate on values returned 
from functions, or series referred to by protected variables.
Geomol
13-Oct-2011
[2455]
My suggested NEXT can do that also. I just suggest adding the possibility 
to call those with call-by-word.
Ladislav
13-Oct-2011
[2456x3]
NEXT cannot do it
It does not have that kind of argument evaluation
You would need to change the argument evaluation standard for it
BrianH
13-Oct-2011
[2459x2]
Geomol, if you change NEXT to call-by-word then in order to have 
it work on the results of a function you will need to assign those 
results to a temporary word, then in a separate statement run the 
NEXT. No more chaining.
If you try to support both then you lose the ability of NEXT to trigger 
an error if it is passed a word by accident, a valuable debugging 
aid.
Geomol
13-Oct-2011
[2461x2]
:)
I didn't suggest changing NEXT to call-by-word. I suggest adding 
that possibility beside its current behaviour.
Ladislav
13-Oct-2011
[2463]
Do you happen to know how?
Geomol
13-Oct-2011
[2464x2]
>> f: func [v] [either word? v [get v] [v]]
>> f 1
== 1
>> a: 2
== 2
>> f 'a
== 2
That's the thought.
BrianH
13-Oct-2011
[2466]
Yeah, that will make NEXT cause unintentional side effects instead 
of triggering errors. Does it have side effects or not? Who knows?
Ladislav
13-Oct-2011
[2467]
aha, so you are suggesting to just accept word as yet another type 
of argument, i.e. to support NEXT 'A
Geomol
13-Oct-2011
[2468x2]
yes
Mezzanine example:


>> my-next: func [series] [either word? series [set series next get 
series] [next series]]
>> my-next [a b c]
== [b c]
>> block: [a b c]
== [a b c]
>> my-next 'block
== [b c]
>> block
== [b c]
Ladislav
13-Oct-2011
[2470]
Anyway, it does not look like a best idea to me. Besides, in the 
case of ++ a new (special) function with a different argument passing 
convention was defined
Endo
13-Oct-2011
[2471]
We talked about to change the value of non-series values by this 
way:
>> a: 5
>> multiply 'a 5
>> ? a
== 25


But ofcourse we are not sure about performance overhead or possible 
other problems.
Geomol
13-Oct-2011
[2472x3]
I've been thinking about this before, and there was a discussion 
on Carl's blog long time ago. It came to me again, when I looked 
at LOWERCASE and UPPERCASE. They work on strings, and does change 
the sting. But many functions work on string without changing them. 
That's a bit odd, or maybe difficult for new users to understand.
I think, the ideas can be seen as: like other languages have call-by-value 
and call-by-reference (maybe using pointers as in C), REBOL could 
have call-by-value and call-by-word, both working with the same functions, 
as it's all by value, but we just give the word (REBOL's kind of 
reference) as an argument.
Leading to shorter notation and most likely also faster evaluation. 
I can't see any problem yet, but maybe there is!?
Ladislav
13-Oct-2011
[2475]
we are not sure about performance overhead
 - there are greater concerns than just performance here
BrianH
13-Oct-2011
[2476]
Then we would have one more class of arguments that we need to treat 
carefully, rather than trusting the type checking to do it for us. 
This is similar to the none propagation problem.
Geomol
13-Oct-2011
[2477]
Well, REBOL already has double type checking:

>> 4 > 2
== true
>> [4] > [2]
== true
>> [4] > 2
** Script Error: Expected one of: block! - not: integer!
BrianH
13-Oct-2011
[2478x2]
For all those series functions that are non-modifying, except for 
ports, all we have to do to use them safely is to avoid putting ports 
in our data. This isn't usually a problem because it's rare to put 
ports in data; but words, on the other hand, are really common in 
data. This would make a misplaced word in your data not only not 
caught, but also *modified*. That is really bad.
I wasn't joking about the "a valuable debugging aid" comment. That's 
a deal-killer for me.
Henrik
16-Oct-2011
[2480]
What exactly does this mean:

>> a: make bitset! [#"-" - #"+"]
** Script Error: Out of range or past end
** Near: a: make bitset! [#"-" - #"+"]
GrahamC
16-Oct-2011
[2481]
>> make bitset! [ #"+" - #"-" ]
== make bitset! #{
0000000000380000000000000000000000000000000000000000000000000000
}
Sunanda
16-Oct-2011
[2482]
bitset likes its args in ascending order (but Graham beat me to it)
Henrik
16-Oct-2011
[2483]
that seems a bit impractical, but I guess it could complicate the 
function to have both ways.
james_nak
28-Oct-2011
[2484]
Is there a simple way to transform a block of blocks into a single 
block and maintain their types? As follows:
a: [  [1] [2] [3] ]
Changing that to
b: [  1 2 3 ]

You know, outside of looping thru each value and building a new block 
(which I don't mind doing but if there was some simple way)
BrianH
28-Oct-2011
[2485x6]
Only one level, or all the way?
Also, in-place or as a copy?
>> a: [[1][2][3][[4]]]
== [[1] [2] [3] [[4]]]

One level:

>> b: copy a while [not tail? b] [either block? first b [b: change 
b first b] [++ b]] b: head b
== [1 2 3 [4]]

All levels (not cyclic reference safe):

>> b: copy a while [not tail? b] [either block? first b [change b 
first b] [++ b]] b: head b
== [1 2 3 4]
ChristianE's ODBC extension for R3 includes a native FLATTEN command, 
but I haven't tested whether or not it manages memory properly, and 
it doesn't help R2, or R3 not on Windows.
Using R3 PARSE:
>> b: copy a parse b [any [change [set x block!] x | skip]] b
== [1 2 3 [4]]

>> b: copy a parse b [while [and change [set x block!] x | skip]] 
b
== [1 2 3 4]
Or simpler:
>> parse copy a [return while [change [set x block!] x | skip]]
== [1 2 3 [4]]

>> parse copy a [return while [and change [set x block!] x | skip]]
== [1 2 3 4]
Sunanda
28-Oct-2011
[2491]
For some types of data (not embedded objects)
    to-block form [ .... ]
Andreas
28-Oct-2011
[2492]
in-place:
forall a [change a first a]

copying:
collect [foreach x a [keep x]]
BrianH
28-Oct-2011
[2493]
Andreas, FORALL won't work here:
>> a: [[1] [2] [3 [4]] [[5]]] forall a [change a first a] a
== [1 2 3 4]


If it's shallow, it should be [1 2 3 [4] [5]], if deep it should 
be [1 2 3 4 5].
Andreas
28-Oct-2011
[2494]
Sure, neither will it work in n other arbitrarily constructed border 
cases :)
BrianH
28-Oct-2011
[2495]
The PARSE and WHILE versions above will work in all cases where you 
don't run out of memory, and for the deep versions when there are 
no cyclic references.

>> parse [[1] [2] [3 [4]] [[5]]] [return while [change [set x block!] 
x | skip]]
== [1 2 3 [4] [5]]

>> parse [[1] [2] [3 [4]] [[5]]] [return while [and change [set x 
block!] x | skip]]
== [1 2 3 4 5]
Andreas
28-Oct-2011
[2496]
For the common flatten use-case of regular one-level nested blocks, 
it's fine. If that's not what you need, no warranties :)
BrianH
28-Oct-2011
[2497x2]
The FORALL version won't work if the embedded blocks have more than 
one element in them.
That is the common case :)