Posted: Thu Dec 14, 2006 1:17 pm Post subject: (No subject)
Imagine:
code:
%removes all whitespace from a word
fcn as_string_without (predicate : function f (ch : string) : boolean) : string
if original = "" then
original := value
end if
var oldword := value
var newword := ""
if oldword ~= "" then
for i : 1 .. length (oldword)
if not predicate (oldword (i)) then
newword += oldword (i)
end if
end for
end if
result newword
end as_stripped
Posted: Thu Dec 14, 2006 1:19 pm Post subject: (No subject)
Oh, and ericfourfour, when your string class has a method that returns a string, you should probably have it return a String object.
Clayton
Posted: Thu Dec 14, 2006 1:22 pm Post subject: (No subject)
I get it it makes so much more sense now. This way you can just pass the function and away you go
ericfourfour
Posted: Thu Dec 14, 2006 4:51 pm Post subject: (No subject)
wtd wrote:
Oh, and ericfourfour, when your string class has a method that returns a string, you should probably have it return a String object.
What? Did I miss something?
wtd
Posted: Thu Dec 14, 2006 11:45 pm Post subject: (No subject)
Well, consider:
code:
%removes all whitespace from a word
fcn as_stripped : string
if original = "" then
original := value
end if
var oldword := value
var newword := ""
if oldword ~= "" then
for i : 1 .. length (oldword)
if oldword (i) ~= " " then
newword += oldword (i)
end if
end for
end if
result newword
end as_stripped
It would seem consistent to have this method, as a single example, return a String object, rather than a value of type "string".