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

World: r3wp

[Core] Discuss core issues

[unknown: 5]
5-Mar-2008
[9377]
I figure if I created a block it would update the counter for each 
new block created as long as the older ones were still set as well.
btiffin
5-Mar-2008
[9378]
Well, yes, but it could well replace an unused slot etc etc ... (I'm 
GC clueless) etc etc.  Wrapped in recycle you should see the numbers 
change a little more sensibly.
[unknown: 5]
6-Mar-2008
[9379]
That's just it Brian.  All I did was open up the console and assigned 
a word a block value and check the stats/types for the block counter 
and it didn't change.  I added another one and still didn't change. 
 So I'm a bit perplexed.
btiffin
6-Mar-2008
[9380]
Yeah, even after boot there are reallocatable blocks.   Try recycle 
first thing in the console, then run the experiments.  Once again, 
this is only afaik, 'cause I don't.
Gregg
6-Mar-2008
[9381]
REBOL may allocate things in "pools" for efficiency. You shouldn't 
care Paul, except in extreme cases.
[unknown: 5]
6-Mar-2008
[9382]
Yeah but if I know how they work I might be able to utilize that 
functionality in the future ;-)
[unknown: 5]
7-Mar-2008
[9383x4]
Here is a total flatten function:
b: func [blk [block!]][to-block trim/with mold/only blk "[]"]
forgot to name it - here instead:
flatten: func [blk [block!]][to-block trim/with mold/only blk "[]"]
BrianH
7-Mar-2008
[9387]
That kills the bindings of the words - is that intentional?
[unknown: 5]
7-Mar-2008
[9388x5]
Yes it is intentional if someone wants to completely flatten a block.
I can't see where someone would want to keep context if they are 
deciding to flatten it to that extreme.
I have a more useful flatten function that encompasses that one that 
will be more useful for someone that wants to keep contexts of no 
so flattened blocks.
It could probably be a mezz as it is very useful
Brian, I'll see if I can whip up my comprehensive flatten function 
to include a context sensitive full flatten and post it here.
BrianH
7-Mar-2008
[9393]
Here's a version which modifies in place:

flatten: func [blk [block!] /local rule a b] [
	parse blk [some [a: set b block! (change/part a b 1) :a | skip]]
	blk
]
[unknown: 5]
7-Mar-2008
[9394]
Nice Brian
BrianH
7-Mar-2008
[9395]
I've had to do something like it before. It doesn't preallocate or 
copy, but what can you do.
[unknown: 5]
7-Mar-2008
[9396x2]
yeah true
Are they planning to put something like a flatten function in R3?
BrianH
7-Mar-2008
[9398]
You can copy/deep first if you like, though that has allocation overhead. 
A version was proposed in the R3 discussions, but hasn't made it 
through the screening process (not general-use enough I guess).
[unknown: 5]
7-Mar-2008
[9399]
to bad I can see why we need it.
BrianH
7-Mar-2008
[9400]
Here's the thing: How often are you going to use it?


We are modularizing REBOL so that you don't have to bundle the whole 
thing together. Functions like FLATTEN would make a great addon module, 
but if the core code doesn't need it, or it's usage would be uncommon, 
it doesn't make the cut.


For that matter, the functions in R3 that I am backporting to R2 
are only those that I have actually seen in regular use in R3 mezzanine 
code. There are some more advanced functions that just won't be making 
it because their design hasn't been settled yet.


Picking something to go into the core is an involved process. And 
you can always make code libraries.
[unknown: 5]
7-Mar-2008
[9401x7]
I agree with that.  keep it out and use it as a module.
>> help flatten
USAGE:
    FLATTEN blk /fine /semi /full

DESCRIPTION:
     Returns a new block with desired blocks flattened or removed
     FLATTEN is a function value.

ARGUMENTS:
     blk -- block to flatten (Type: block)

REFINEMENTS:
     /fine -- Flattens blocks to finest representation
     /semi -- Flattens to support 'select operations
     /full -- Flatten fully - ignored with other refinements
flatten: func [

    {Returns a new block with desired blocks flattened or removed}
    blk [block!] "block to flatten"
     /fine "Flattens blocks to finest representation"
     /semi "Flattens to support 'select operations"
     /full "Flatten fully - ignored with other refinements"
     /local blk2
    ][
    blk2: copy []
    fl: func [b][
        either parse b [block!][
            b: first b
            fl b
        ][
            either semi [
                insert tail blk2 b
            ][
                either full [

                    foreach val b [either block? val [fl val][insert tail blk2 val]]
                ][
                    insert/only tail blk2 b
                ]
            ]
        ]
    ]

    if fine [full: none while [parse blk [block!]][blk: first blk]]
    foreach item blk [
        either block? item [fl item][insert tail blk2 item]
    ]    
    blk2
]
>> test: [[1 ["select"]] [2 ["me"]]]
== [[1 ["select"]] [2 ["me"]]]
>> flatten/semi test
== [1 ["select"] 2 ["me"]]
>> test: [[[1 ["Select"]] [[2 ["Me"]]]]]
== [[[1 ["Select"]] [[2 ["Me"]]]]]
>> flatten/fine/semi test
== [1 ["Select"] 2 ["Me"]]
>> test: [[["this"]] [[["is"]]] ['a] 'big [[['mess]]]]
== [[["this"]] [[["is"]]] ['a] 'big [[['mess]]]]
>> flatten/fine test
== [["this"] ["is"] ['a] big ['mess]]
>> test: [[["this"]] [[["is"]]] ['a] 'big [[['mess]]]]
== [[["this"]] [[["is"]]] ['a] 'big [[['mess]]]]
>> flatten/full test
== ["this" "is" a big mess]
[unknown: 5]
8-Mar-2008
[9408]
I'm not sure I care for the refinement names I chose with the exception 
of /full.  I kinda like that name as it gives me a better perspetive 
of what it is doing.
Pekr
12-Mar-2008
[9409]
how can I make object words local to the context of object? I mean

obj: context [a: 1 pri: does [print a]]


I would like to be able to use 'a in the closed context, but I don't 
want it to be available via obj/a ..... I tried to enclose it to 
'use, but then it is not available to 'pri function :-)
Gregg
12-Mar-2008
[9410]
See these ML threads on REBOL.org.


http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-thread.r?m=rmlRJCC

http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-thread.r?m=rmlTLVQ
Pekr
12-Mar-2008
[9411]
thanks ...
BrianH
12-Mar-2008
[9412]
Wrap the USE around the CONTEXT, rather than the other way around.
[unknown: 5]
12-Mar-2008
[9413]
This topic comes at a good time for me as I have a complex issue 
that I need to address which is similiar to what Pekr's sounds like 
except that I'm binding object/words to object/some-func.  I'm going 
to have the need to not allow someone to access object/words by probing 
object/words.  Object words is to large to have all of it inside 
of object/some-func which is why it is external to that function 
and only parts of it get bound to that some-func.
Ingo
13-Mar-2008
[9414]
I just remembered the 'self trick, don't know whether it's officially 
supported, but it works ...

given: ....

o: make object! [ 
	self: make object! [
		p: does [print [a b c d]]
		ca: func [x][a: x]
		d: 4		
	 ]
	a: 1 b: 2 c: 3
]

you have ...

>> o/p
1 2 3 4
>> o/ca 7
== 7
>> o/p
7 2 3 4
>> probe o
make object! [
    p: func [][print [a b c d]]
    ca: func [x][a: x]
    d: 4
]
>> o/a
** Script Error: Invalid path value: a
** Near: o/a
>> o/self/a
** Script Error: Invalid path value: a
** Near: o/self/a
[unknown: 5]
13-Mar-2008
[9415]
nice that is what I'm looking for.
Pekr
13-Mar-2008
[9416]
o/p is directly known? I did not know 'self allows such functionality 
:-)
[unknown: 5]
13-Mar-2008
[9417]
It's sweet for sure.  Another one of those hidden REBOL perks.
Gabriele
14-Mar-2008
[9418x2]
i don't think this is intentional, but it's something i've used quite 
a few times. basically make is returning self, whatever you make 
that be :)
>> make object! [self: "blabla"]
== "blabla"
[unknown: 5]
14-Mar-2008
[9420x3]
Objects are kinda strange.  For example, if you set 'self after you 
created the context it can be referenced but remains hidden in a 
sense:
>> obj: context []
>> obj/self: "hidden"
== "hidden"
>> probe obj
make object! [
]
>> obj/self
== "hidden"
But this highly not recommened unless your aware of what your using 
your object for as self will not refer back to itself any longer.
btiffin
16-Mar-2008
[9423]
I'd like to thank the 2.7.6 team for all the great new stuff.  In 
particular  Brian Hawley  - well done.  Kudos; the new mezz features 
are awesome.  ALSO and FIRST+ being just two of many that will make 
for more concise code.

Long Live R2.
Graham
16-Mar-2008
[9424]
Perhaps someone can post examples of how the new mezzanines are used 
...
btiffin
16-Mar-2008
[9425]
ALSO;   instead of  
    tmp: first series  series: next series  tmp
   also  first series  series: next series

No tmp required,  ALSO  will return the first result of the two expressions 
 BUT in this case why?   :) 
FIRST+;   instead of the (now) useless example I just wrote;

    first+ series    ;; return value at current reference and then advance 
    reference
No tmp, no next required.  All in one expression. 


Note:  SOURCE ALSO   it's cool and will make a lot of sense when 
you see it.
[unknown: 5]
16-Mar-2008
[9426]
Yeah the mezzanines will be very useful and should be in there just 
because of the frequency they will be used.