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

[REBOL] Help function for contracts

From: jan:skibinski:sympatico:ca at: 17-Oct-2002 14:59

Hi, As an exercise in learning the basics of Rebol I made a little script supporting the Design By Contract. (Yes, I am aware of Maartens' contract.r) I uploaded it as file dbc.r to the library. The script provides, among few other things, the help' function which extends the standard help with notion of assertions. Attached is an output from <help' factorial>. It tells us quite a bit about how the example "factorial" function should be used: - It does not accept negative inputs, x - It limits the input to x <= 12, if x is an integer - etc., etc. Suggestions on how to improve the script are welcome and expected. For example, I am not sure how to control the layout of sources of "contracted" functions. Also, my script lost its "neat" appearance after upload. I edited the stuff in MS notepad, since I cannot afford using anything sophisticated, such as Jedit editor, due to too little memory on my machine. 128 Mb is not enough any more. :-). Used to run (with some limitations) in 32 Mb on Linux boxes. Anyway, enjoy the script if you find it useful, Jan P.S. I am begining to like and appreciate Rebol. =================================================== USAGE: FACTORIAL x DESCRIPTION: Factorial of a number 'x' computed recursively without a help of an accumulator. Example of a function with assertions. FACTORIAL is a function value. ARGUMENTS: x -- (Type: integer decimal) (SPECIAL ATTRIBUTES) catch PRECONDITIONS: [ [x >= 0] [implies (integer? x) (x <= 12)] [implies (decimal? x) (x <= 170)] [implies (decimal? x) (integral? x)] ] POSTCONDITIONS: [ [result >= 1] [result <= max-factorial] [(type? x) == (type? result)] ]