REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Concepts: Functions: Viewing Source Code

Pending Revision

This document was written for R2 and has yet to be revised for R3.

Another technique for learning about REBOL and for saving time in writing your own function is to look at how many of the REBOL mezzanine functions are defined. You can use the source function to do this.

source source
source: func [
    "Prints the source code for a word."
    'word [word!]
][
    prin join word ": "
    if not value? word [print "undefined" exit]
    either any [native? get word op? get word action? get word] [
        print ["native" mold third get word]
    ] [print mold get word]
]

Here the source function is used to print its own source code.

Note that you cannot see the source code for native functions because they exist only as machine code. However, the source function will display the native function interface specification. For example:

source add
add: native [
    "Returns the result of adding two values."
    value1 [number! pair! char! money! date! time! tuple!]
    value2 [number! pair! char! money! date! time! tuple!]
]


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin