Waldek Hebisch <[email protected]> writes:

| Serge D. Mechveliani wrote:
| > 
| > On Sun, Feb 05, 2012 at 01:56:20AM +0100, Ralf Hemmecke wrote:
| > > On 02/04/2012 06:13 PM, Serge D. Mechveliani wrote:
| > >> [..]
| > >>>>    dropWhile(p: Character ->  Boolean, xs: List Character) :
| > >>>>                                                List Character ==
| > >>>>                              empty? xs   =>  xs
| > >>>>                              p first(xs) =>  dropWhile(p, rest xs)
| > >>>>                              xs
| > >>>> Is this more efficient?

[...]

| Spad compiler will inline "simple enough" functions.  Unfortunately,
| currently this means functions consisting of single operation.
| 
| Your version will generate the following Lisp code:
| 
| (DEFUN |TTT;dropWhile;M2L;1| (|p| |xs| $)
|   (COND ((OR (NULL |xs|) (NULL (SPADCALL (|SPADfirst| |xs|) |p|))) |xs|)
|         ('T (SPADCALL |p| (CDR |xs|) (QREFELT $ 8)))))

OpenAxiom resolves these SPADCALLs within the same package/domain and
produces 

  (DEFUN |SERGEI;dropWhile;M2L;1| (|p| |xs| $)
    (COND ((OR (NULL |xs|) (NOT (SPADCALL (|SPADfirst| |xs|) |p|))) |xs|)
          (T (|SERGEI;dropWhile;M2L;1| |p| (CDR |xs|) $)))) 

which any of the free Lisp supported by OpenAxiom is capable of
recognizing as tail-recursive, and therefore optimize appropriately.

-- Gaby

-- 
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