home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / string < prev    next >
Text File  |  2020-01-01  |  2KB  |  62 lines

  1. ; From: Dat Thuc Nguyen
  2. ; Date: Wed Apr 21 11:57:01 1999
  3. ; URL: http://www.smalltickle.com
  4. ;
  5. ; Following is a rudimentary string class based on the Smalltalk model.
  6.  
  7. ;********************************************************
  8. ;    DEFINITION OF THE STRING CLASS                     *
  9. ;********************************************************
  10.  
  11. define string {
  12.     _assign string::\%1 \%2
  13.     _define \%1 {
  14.         string.\%1 \v(macro) \%2 \%3 \%4
  15.     }
  16. }
  17.  
  18. ;********************************************************
  19. ;    IMPLEMENTATION OF THE PUBLIC USAGE INTERFACE       *
  20. ;    OF THE STRING CLASS                                *
  21. ;********************************************************
  22.  
  23. define string.echo {
  24.     echo \m(string::\%1)
  25. }
  26.  
  27. define string.length {
  28.     echo \flength(\m(string::\%1))
  29. }
  30.  
  31. define string.concat {
  32.     if define \m(string::\%2) {
  33.          _assign string::\%1 \m(string::\%1)\m(string::\%2)
  34.     } else {
  35.          _assign string::\%1 \m(string::\%1)\%2
  36.     }
  37. }
  38.  
  39. define string.write {
  40.     if define \m(string::\%2) {
  41.          _assign string::\%2 \m(string::\%1)
  42.     } else {
  43.          _assign \%2 \m(string::\%1)
  44.     }
  45. }
  46.  
  47. ;********************************************************
  48. ;    USAGE SAMPLES                    *
  49. ;********************************************************
  50.  
  51. string abc hello         ; Create a string abc initialized with 'hello'
  52. abc echo                 ; Display the string abc
  53. abc length               ; Display the length of the string abc
  54. abc write s1             ; Assign the variable s1 with the content of
  55.                          ; the string abc.
  56. echo \m(s1)              ; Display the value of the variable s1
  57. string greet _world      ; Create a string greet initialized with '_world'
  58. abc concat greet         ; Concatenate the string abc with the string greet
  59. abc echo                 ; Display the string abc
  60.  
  61. End
  62.