[REBOL] Bug in 'use? Re:(3)
The following has been written: > > Hi Ladislav, 15-Jul-2000 you wrote: > > > > >you are right, the problem is caused by a context > manipulation - > > >Use unsets your Middle every time it gets executed. My > suggestion > > >is to not use Use in recursive functions, while this problem > > >doesn't get corrected. > > > > Judging from the nature of recursiveness, that's a little hard, > isn't it? ;-) > > > > Do you know if this problem has already been reported to > feedback? > > > > Kind regards, > > -- > > Ole Friis <[EMAIL PROTECTED]> > > here is a pretty simple example showing the problem: temporary: "global temporary" recfun: func [level] [ use [temporary] [ if level < 1 [ temporary: "temporary" recfun level + 1 print ["Temporary:" temporary] ] ] ] recfun 0 ; The result: ** Script Error: temporary has no value. ** Where: temporary ; let's define a function r-use like this: r-use: func [ "Defines words local to a block." words [block!] "Local word(s) to the block" body [block!] "Block to evaluate" ] [ do function [] words body ] ; and now use R-use instead of native Use temporary: "global temporary" recfun: func [level] [ r-use [temporary] [ if level < 1 [ temporary: "temporary" recfun level + 1 print ["Temporary:" temporary] ] ] ] recfun 0 ; The result: Temporary: temporary Ladislav
[REBOL] Bug in 'use? Re:(3)
Hi, > Hi Ladislav, 15-Jul-2000 you wrote: > > >you are right, the problem is caused by a context manipulation - > >Use unsets your Middle every time it gets executed. My suggestion > >is to not use Use in recursive functions, while this problem > >doesn't get corrected. > > Judging from the nature of recursiveness, that's a little hard, isn't it? ;-) > > Do you know if this problem has already been reported to feedback? > > Kind regards, > -- > Ole Friis <[EMAIL PROTECTED]> > > Amiga is a trademark of Amiga Inc. > You should probably report it to feedback. BTW, did you succeed to sort the permutations correctly? One more question for everybody. What do you want to see after executing: blk: copy [] probeblk: func [] [ prin mold blk prin ": " print mold reduce blk ] recfun: func [x] [ append blk 'x either x <= 1 [ probeblk ] [ recfun x - 1 ] ] recfun 3 probeblk Regards Ladislav
[REBOL] Bug in 'use? Re:(3)
Ole, > Thanks! In the meantime, I got it working by simply having the temporary > variables as parameters to the function. Mean, but it works. You don't need temporary variables. You can use local function variables. Either via func [x /local a-local][the-code] or via function [x][a-local][the-code] Giving you back something that you lost with a broken 'use. Brett.