Thanks to people for their advices.
To my 

>> I define
>>   dropWhileInStr(p: Character -> Bool, xs: String) : String ==   
>>                     empty? xs   => ""
>>                     p first(xs) => dropWhileInStr(p, delete(xs, 1))
>>                     xs
>> 
>> for dropping first letters from  xs  which satisfy a predicate  p.
>> It this a reasonable code?

Waldek Hebish  writes

> IMHO reasonable, but potentally quite inefficient: delete creates copy.  
> If the string has length n delete allocates new string of length n-1 
> and then copies characters. 
> [..]

Is a  string  represented in FriCAS as a  C array? 
Is this total copying due to the array representation?
What may be an efficient code for  dropWileInStr ?
(in Haskell, I never use arrays, somehow forgotten the style).
Consider the List approach:
 
  dropWhile(p: Character -> Boolean, xs: List Character) :
                                              List Character ==
                            empty? xs   => xs
                            p first(xs) => dropWhile(p, rest xs)
                            xs
Is this more efficient?
I expect this variant will do much less copying (?).
This is, probably, similar to a list processing in Lisp, 
and String probably works very differently.
-- ?

Regards,

------
Sergei
[email protected]


-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en.

Reply via email to