LC ==> List Character
dropWhile(p: Character -> Boolean, xs: LC): LC ==
while not empty? xs and p first xs repeat xs := rest xs
xs
[..]
(DEFUN |TTT;dropWhile;M2L;1| (|p| |xs| $)
(SEQ
(SEQ G190
(COND
((NULL
(COND ((NULL |xs|) 'NIL) ('T (SPADCALL (|SPADfirst| |xs|) |p|))))
(GO G191)))
(SEQ (EXIT (LETT |xs| (CDR |xs|) |TTT;dropWhile;M2L;1|))) NIL (GO G190)
G191 (EXIT NIL))
(EXIT |xs|)))
however, it will probably generate less machine istructions and
run faster. Note that there is only single 'SPADCALL' is Ralf
version.
I'm surprised. Why is rest translated into CDR and first not into CAR?
Oh, because of
first x == SPADfirst(x)$Lisp
rest x == CDR(x)$Lisp
and
(defmacro |SPADfirst| (l)
(let ((tem (gensym)))
`(let ((,tem ,l)) (if ,tem (car ,tem) (first-error)))))
This makes it somehow not crash because of errors.
Ummm, I have some issues.
1) The call
rest []
should fail or even crash FriCAS instead of silently return
the empty list.
2) The call
first []
should fail or crash FriCAS.
3) My wish for 1) and 2) applies to spad programs only, in the
Interpreter, I would certainly like to keep my FriCAS session if by
mistake I take the first element of an empty list.
The implementation of List internally uses Qfirst ==> QCAR$Lisp.
(defmacro qcar (x) `(car (the cons ,x)))
(I don't understand why QCAR is not simply CAR, but that would be a lisp
question.)
Unfortunately the fast version isn't exported. :-( I didn't know.
Maybe it's too early, but, Waldek, do you see a chance that one could
have failsafe versions for first/rest and by default the quick versions
if the code is compiled by the spad compiler.
I somehow think of
SomeDomain_Interpreter: SameExportsAsSomeDomain == SomeDomain add
...
-- override functions that are not failsafe.
...
I.e. each potentially crashing domain would have a corresponding
..._Interpreter wrapper domain that does the error handling.
I guess catching crashes by the Interpreter without such wrapper domains
it probably impossible in general.
Anyway, I think, that the error test that first currently performs, is a
waste of time. It is testing for something that should never happen. It
helps debugging, yes, but why would one want it to be there in a program
that one has carefully proved to be correct?
Ralf
--
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.