home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / v / vsnbl220.zip / DEXP.INC < prev    next >
Text File  |  1991-02-14  |  1KB  |  29 lines

  1. *    DEXP.INC
  2. *
  3. *    Here's an advanced function that demonstrates the use
  4. *    of SNOBOL4's CODE function.
  5. *
  6. *    Program structuring would be enhanced if there were a simple
  7. *    way to make one line function definitions, rather than coding
  8. *    a DEFINE call and a goto around the function body.  Function
  9. *    DEXP allows these one line definitions.  A typical call:
  10. *        DEXP('AVERAGE(X,Y) = (X + Y) / 2')
  11. *    You can even have multistatement definitions.  This call defines
  12. *    function SIGN(X) that returns 1 if X is positive, -1 if negative,
  13. *    and null if X = 0:
  14. *        DEXP('SIGN(X) = GT(X,0) 1 ; SIGN = LT(X,0) -1 ;')
  15. *
  16. *    This is one of the many programs and functions from
  17. *    "Algorithms in SNOBOL4," by James F. Gimpel.
  18. *
  19.     DEFINE('DEXP(PROTO)NAME,ARGS')            :(DEXP_END)
  20.  
  21. *    Remove leading blanks, get function name and remove argument list.
  22. DEXP    PROTO POS(0) SPAN(' ') =
  23.     PROTO BREAK('(') . NAME BAL . ARGS = NAME
  24.  
  25. *    Build the code for the function body, then define it.
  26.     CODE(NAME ' ' PROTO ' :S(RETURN)F(FRETURN)')
  27.     DEFINE(NAME ARGS)                :(RETURN)
  28. DEXP_END
  29.