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

Forward References

 [1/3] from: richard-boyd::worldnet::att::net at: 13-Dec-2001 21:57


The REBOL/Command User Guide page 8-29 states .. --Forward References-- Sometimes a script needs to refer to a function before it has been evaluated. This can be done as long as the variable for the function is not evaluated before it is defined. How do you determine if the referenced function is "evaluated" before it is defined? Must you order all definitions within a file so that the definitions always come before reference is made to them? Any references/weblinks with clarification? Thanx. -richard- -------------- REFERENCE BEFORE WORKS ------------------ REBOL [Title: "Forward Reference"] open-new-pane: func [] [view layout [banner "New Window" button "Quit" [quit] button "Unview" [unview]]] view layout [banner "Forward Reference Test" button "New Pane" [open-new-pane]] -------------- REFERENCE AFTER FAILS ------------------ REBOL [Title: "Forward Reference"] view layout [banner "Forward Reference Test" button "New Pane" [open-new-pane]] open-new-pane: func [] [view layout [banner "New Window" button "Quit" [quit] button "Unview" [unview]]]

 [2/3] from: al:bri:xtra at: 14-Dec-2001 19:28


-richard- wrote:
> --Forward References-- > "Sometimes a script needs to refer to a function before it has been
evaluated. This can be done as long as the variable for the function is not evaluated before it is defined."
> How do you determine if the referenced function is "evaluated" before it
is defined? Must you order all definitions within a file so that the definitions always come before reference is made to them? Any references/weblinks with clarification? Here's an example from the console:
>> f1: func [x] [print "F1" f2 x] >> f2: func [x] [print ["F2" x]] >> f1 4
F1 F2 4 Note that the function refered to by 'f1 refers to 'f2, and note that the function refered to by f2 isn't created until the next line. Here's new console session:
>> f1: func [x] [print "F1" f2 x] >> f1 2
F1 ** Script Error: f2 has no value ** Where: f1 ** Near: f2 x Note that in the second line I _haven't_ defined 'f2, but instead 'f1 is evaluated. Note that Rebol says 'f2 has no value. Everything that applies to a console session applies to a script. I hope that helps! Andrew Martin ICQ: 26227169 http://valley.150m.com/

 [3/3] from: ingo:2b1 at: 14-Dec-2001 10:37


Hi Richard, Once upon a time Richard Boyd spoketh thus:
> The REBOL/Command User Guide page 8-29 states .. > > --Forward References-- > "Sometimes a script needs to refer to a function before it has been > evaluated. This can be done as long as the variable for the function is > not evaluated before it is defined."
<..>
> -------------- REFERENCE AFTER FAILS ------------------ > REBOL [Title: "Forward Reference"]
<<quoted lines omitted: 8>>
> button "Unview" [unview]]] > --------------------------------------------------------------------
In your example, once the 'view function is reached, the value of open-new has to be present, because part of the script _after_ view, are only reached after closing the view window. e.g.: --------- Script 1 ------------ REBOL[] print 'before view layout [ label "hi" ] print 'after -------- Script 1 ------------- If you run this script, first 'before is printed, _then_ the window is opened, and 'after is only printed, if you close the window. The proper way to forward reference for you would be to create a new word holding the layout until it is viewed, like this: -------- Script 2 ------------- REBOL [] lay: layout [ banner "Forward Reference Test" button "New Pane" [open-new-pane] ] open-new-pane: func [][ view layout [ banner "New Window" button "Quit" [quit] button "Unview" [unview] ] ] view lay -------- Script 2 ------------- Now all functions are defined, before they are needed (evaluated) in the 'view function. I hope that clarifies it a bit. Kind regards, Ingo

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted