World: r3wp
[Core] Discuss core issues
older newer | first last |
BrianH 29-Apr-2008 [10393x2] | also: func [ {Returns the first value, but also evaluates the second.} value1 [any-type!] value2 [any-type!] ][ get/any 'value1 ] |
Yes, that is the fix. You should also set data to none. | |
[unknown: 5] 29-Apr-2008 [10395] | Yeah good point. So we really don't need ALSO to free the memory then right? |
BrianH 29-Apr-2008 [10396] | ALSO is to let you return a value assigned to a variable, and still be able to unset the variable. |
[unknown: 5] 29-Apr-2008 [10397x2] | Thanks Brian. |
Why was ALSO created? | |
BrianH 29-Apr-2008 [10399] | For cleanup. |
[unknown: 5] 29-Apr-2008 [10400x2] | I don't fully comprehend the also function. I know it is getting the value but why pass it twice? |
so really you would always want the second value to be word: none correct? | |
BrianH 29-Apr-2008 [10402x2] | It's an evaluation trick. It evaluates two expressions and returns the value of the first. You can do your cleanup in the second expression. If your cleanup is more complex, put it in a paren. The value returned by the second expression is taken and ignored. |
The second expression clond be a close statement, for instance. | |
[unknown: 5] 29-Apr-2008 [10404x2] | So the get/any is just to ensure that a pointer has been established then right? |
That might not sound correct to you but I think I know why you did that. | |
BrianH 29-Apr-2008 [10406] | It is just there to pass along the first value. |
[unknown: 5] 29-Apr-2008 [10407x2] | Exactly - ok got ya. |
So this would be used as your primary evaluator not as a secondary evaluator called just to do cleanup. | |
BrianH 29-Apr-2008 [10409] | ? Sure, if I understand you correctly. |
[unknown: 5] 29-Apr-2008 [10410] | It's alright I get it now. I was thinking this function was more complex than it is. |
BrianH 29-Apr-2008 [10411] | Here's another example of its use from 2.7.6: first+: func [ {Return FIRST of series, and increment the series index.} [catch] 'word [word!] "Word must be a series." ][ throw-on-error [also pick get word 1 set word next get word] ] |
[unknown: 5] 29-Apr-2008 [10412] | yeah I recall seeing that one. |
[unknown: 5] 1-May-2008 [10413x2] | Is there anyway in REBOL2.7.x to force an immediate garbage collection? Just invoking recycle doesn't seem to do it. |
The invoking of it does work sometimes so I assume there is some type of timing algorithm at play. | |
Gregg 2-May-2008 [10415x2] | What, specifically, do you want to GC that isn't being GC'd when you think it should? |
Or, rather, why do you need to GC something immediately? | |
btiffin 2-May-2008 [10417] | Paul; It's all pretty much voodoo to me, but the few times I care, I start with http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=free-mem.r |
[unknown: 5] 2-May-2008 [10418x2] | Gregg, I was just under the impression we had that kind of control. I'm hoping your question is confirmation that we don't so at least I'm not missing something. |
Yeah brian. I have seen that free-mem function in the past and obviously, it is just setting a word to none and calling recycle. But when the recycle is invoked we don't "see" the clean-up immediately. In other words the GC doesn't immediately respond. This might be a good design but I would have hoped that when we wanted to we could immediately "see" the results of the free memory instead waiting for GC to run the task when it decides to. | |
Gregg 2-May-2008 [10420x2] | AFAIK we don't have that kind of control Paul. The best you can do is make sure the things you want to release are set to NONE and do a RECYCLE. |
Make sure things aren't referenced that is. | |
Henrik 2-May-2008 [10422] | use fewer locals and reuse global series if possible |
[unknown: 5] 2-May-2008 [10423] | Thanks Gregg and Henrik. At least I know I should expect to "see" an immediate release of the memory by the REBOL process. I just wanted to make sure I wasn't missing some REBOL magic somewhere. |
Gabriele 2-May-2008 [10424] | the GC makes the memory available again to rebol, not necessarily the OS. |
[unknown: 5] 2-May-2008 [10425] | Ahhh, thanks Gabriele. What about the OS? - can we return that freed memory to the OS instead? |
Henrik 3-May-2008 [10426x2] | should any object not drop its bindings using this: load mold/all object ? |
ah, load mold object solved it. | |
Gabriele 3-May-2008 [10428] | i don't think there is any way to force rebol to return the memory to the OS, and I don't think there's any need either, but that depends on the OS i guess. |
TimW 6-May-2008 [10429] | I looked around a bit and couldn't really find a good solution. Is there an easy way to reorder a block that's not sorting it - To just move one element. Say my-block: [a b c d e] Is there a function to just move c to the front of the block, or to push it to the back? |
PeterWood 6-May-2008 [10430x2] | This won't be the most elegant solution that you'll come across but may get you started: |
>> move-element: func [ [ blok [block!] [ element [ /to-start [ /to-end [ ][ [ either find blok element [ [ either to-end [ [ head insert tail remove find blok element element [ ][ [ head insert head remove find blok element element [ ] [ ][ [ blok [ ] [ ] >> blk: [a b c d e] == [a b c d e] >> move-element/to-start blk 'c == [c a b d e] >> move-element/to-end blk 'c == [a b d e c] >> move-element/to-end blk 'g == [a b d e c] | |
Pekr 6-May-2008 [10432] | wasn't 'move backported to 2.7? |
PeterWood 6-May-2008 [10433x2] | >> move-element: func [ [ blok [block!] [ element [ /to-start [ /to-end [ ][ [ either find blok element [ [ either to-end [ [ head insert tail remove find blok element element [ ][ [ head insert head remove find blok element element [ ] [ ][ [ blok [ ] [ ] >> blk: [a b c d e] == [a b c d e] >> move-element/to-start blk 'c == [c a b d e ] >> move-element/to-end blk 'c == [a b d e c] >> move-element/to-end blk 'g == [a b d e c] |
I've just checked and move is in Core 2.7.6 | |
sqlab 6-May-2008 [10435] | I was always expecting that I could read lines with user-defined line terminators. But unfortunately it adds them just to the already internally defined line terminators. I see this either as a bug in the handling of read/lines/with or as a ambiguous documentation. |
Gregg 6-May-2008 [10436] | I don't think I've ever used it, so it may be something that hasn't been tested enough. If you can create a small example and post it to RAMBO, that would be great. |
BrianH 6-May-2008 [10437] | PeterWood, you should definitely try MOVE. We were very careful to avoid the aliasing and overlap issues that often happen with move functions; getting it right the first time was the whole point of its inclusion. :) |
TimW 6-May-2008 [10438x2] | Thanks. The move function is nice. Does it have anyway to specify what to move? Because with my-block: [a b c d e], moving c to the front involves my-block: skip my-block 2 |
move/to my-block 1 my-block: head my-block | |
BrianH 6-May-2008 [10440x3] | >> head move/to at [a b c d e] 3 1 == [c a b d e] |
It's those aliasing issues. We realized that specifying any other offset than the current one as the source led to a lot of errors in the corner cases. It was tricky to limit the features of the function to just those that could be used safely. | |
Fortunately you can still use AT, SKIP and HEAD if you need to :) | |
older newer | first last |