1

I cannot figure out how to call a function n times to be used in another function

I have a function

(defun right-shift (l)
   (append l '(0))) 

And I need to write another function that needs to shift '(l) n times

(defun right-shift-n-times (l n)
   (natp n)
       ...)

I am not even sure I started that function right and I cannot figure out how to call it n times.

tswiggy
  • 11
  • 3
  • 2
    Note that ACL2 is not a full Common Lisp. ACL2 is a theorem prover implemented in Common Lisp, though. See the manual for the programming language in ACL2: http://www.cs.utexas.edu/users/moore/acl2/v7-4/manual/index.html?topic=ACL2____PROGRAMMING – Rainer Joswig Oct 25 '17 at 19:45

1 Answers1

3

You should given some more background of your problem. If you want to shift bit-wise data there are way more efficient ways, I guess.

For a homework-style solution, I would start with something like this:

 (defun right-shift-n-times (l n)
       (if (zerop n)
           l
           (right-shift-n-times (right-shift l) (1- n))))

but I am not a very experienced lisper.

Martin Buchmann
  • 1,161
  • 7
  • 14
  • 3
    It seems like this will work if you use `ZP` instead of `ZEROP`. ACL2 has to prove that the recursion will terminate, which is not true with `ZEROP`, because it can take any number as an argument and `(1- n)` might never produce a zero. Using `ZP` tells ACL2 that the argument must be a natural number (and thus will eventually reach zero). – jkiiski Oct 25 '17 at 20:30
  • Hmm, thanks for clarification. I was just focusing on CL. – Martin Buchmann Oct 25 '17 at 20:32