Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Newbie: need help with COMPOSE

From: lmecir:mbox:vol:cz at: 13-Oct-2003 13:34

Hi Arie, ----- Original Message ----- From: "Arie van Wingerden"
> Hi list, > > below a extracted piece of program containing 2 times a "do rejoin". > I tried hard to not use rejoin, but compose instead, but it did'nt work out properly. > Could you show me how to rewrite the code in both cases? > > Thanks in advance, > Arie van Wingerden > > http://home.zonnet.nl/rebolution > > ;;; ========================= Code follows here > REBOL [] > ; > ; This function extends a 2nd level object with a function > ; > add-affix-func: does [ > do rejoin [ "rules/" fxname ": " > "make rules/" fxname " [ " ; Extend 2nd level object > "rule" fxcount ": func" ; Function name > "[ inword [ string! ] ]" ; Function spec block > "[ print 200 ]" > "]" > ] > ] > ; > ; Main program starts here > ; > fxname: "A" ; name of 2nd level object > fxcount: 1 ; counter > rules: make object! [] ; create 1st level object > do rejoin [ > "rules: make rules [" ; create 2nd level object > fxname ": make object! [ x: 100 ]]" > ] > probe rules ; show intermediate result > input ; pause console > add-affix-func ; extend 2nd level object > probe rules ; show final result > input ; pause console >
I (and the documentation) suggest you to avoid doing strings. Try the code below: add-affix-func: has [fxn] [ fxn: in rules fxname set fxn make get fxn compose [ (to set-word! join "rule" fxcount) ; Function name func [inword [string!]] ; Function spec block [print 200] ] ] fxname: 'A ; name of 2nd level object fxcount: 1 ; counter rules: make object! [] ; create 1st level object rules: make rules compose [ ; create 2nd level object (to set-word! fxname) make object! [x: 100] ] probe rules ; show intermediate result ; input ; pause console add-affix-func ; extend 2nd level object probe rules ; show final result ; input ; pause console -L