Example String addMethod 001
|
Notes and Hints It is important to remember that String constants that are 9 characters or less are by
default assigned a type of Text unless explicitly assigned to a String Symbol variable.
All functions that are applicable to Strings (append, mid, right, etc.) are
applicable Text constants as well. The fact that a constant is a Text or String is
normally transparent to the user. The Methods Dictionary exists for both the String type and the Text type. The constant
"Hello" would by default be assigned as a Text constant if the following Lisp statement was used: (setq SText "Hello") The method Eat: which was installed as a method for the String type by the addMethod
function would not be able to the understand the following Lisp instruction: (Eat: SText) Since Stext is a Text String, the Lisp compiler will go the Methods Dictionary for the
Text data type and search for the Eat: method and will fail, since the Eat: method
was installed in the String data type. See the send function.
vars: (NewString, i, j, len)
(setq NewString (new String: ""))
(setq j 0)
(setq len (length S))
(loop for i from 0 until len do
;;Move the character to the buffer only if it isn't a space
(if (<> S[i] #\space)
(begin
(setq NewString[j] S[i])
(setq j (add1 j ))
) ;; end begin
) ;; end if
) ;; end loop
NewString) ;; End EatSpace Returns:
Returns:
Returns:
Returns:
Returns:
Here are examples of the addMethod function at work.
Here is the link to the current function used in this example.
Here are a number of links to other related functions.
defmethod(#void) | send(#void) | methodsOf(#void) |
Here are the links to the data types of the arguments used in this example. Here are a number of links to examples having similar argument types.
String
Text
Dictionary
Analytic Information Server (AIS)AIS Component Systems
|