0
   (defun func (in s f l)
      (cond 
       ((null in) (append l (list (list 'end (+ 1 f)))))
       ((eq (car in) 'foo) (foo-asd (cdr in) s f l)) 
       ((atom (car in))(atom-asd in (+ 1 s) (+ 1 f) l))
       ))

.

(defun atom-asd (in s f l)
  (cond ((eql in nil) ())
    (append l (list (list 'frob s (car in) (+ 1 f))))))

.

(defun foo-asd (in s f l)
  (cond 
   ((eql in nil) (append l (list (list 'frob s 'myst f))))
   ((func in s f (append l (list (list 'frob s 'myst (+ 1 f))))))
   ((foo-asd (cdr in) s f l))
  ))

. Regarding this code if call (func '(foo x y) 0 0 ()) the function foo-asd will be called, then func is called again and it will enter the function atom-asd, when atom-asd ends it execution, all the program ends, without calling the recursive call foo-asd. I need foo-asd to be called, but i do not understand why it isn't called after atom-asd ends.

1
  • Your atom-asd is severely broken. Commented Sep 17, 2019 at 14:30

1 Answer 1

3
[4]> (trace func)
;; Tracing function func.
(func)
[5]> (trace atom-asd)
;; Tracing function atom-asd.
(atom-asd)
[6]> (trace foo-asd)
;; Tracing function foo-asd.
(foo-asd)
[7]> (func '(foo x y) 0 0 ())
1. Trace: (func '(foo x y) '0 '0 'nil)
2. Trace: (foo-asd '(x y) '0 '0 'nil)
3. Trace: (func '(x y) '0 '0 '((frob 0 myst 1)))
4. Trace: (atom-asd '(x y) '1 '1 '((frob 0 myst 1)))
*** - cond: variable append has no value
The following restarts are available:
USE-VALUE      :R1      Input a value to be used instead of append.
STORE-VALUE    :R2      Input a new value for append.
ABORT          :R3      Abort main loop
Break 1 [8]>

So in atom-asd:

(defun atom-asd (in s f l)
  (cond
    ((eql in nil)
     ())
    (append
     l (list (list 'frob s (car in) (+ 1 f))))))

You have two predicates. one tests (eql in nil) which obviously is nil, then it checks if the variable append has a non nil value. Problem is append is not a bound variable. It is a binding in the function namespace, but here every term is inclused in one set of parentheses so append is by itself th eexpression that gets tested. You might have meant that it should do (append ...) when the first term didn't kick in and you should have written it like this:

(defun atom-asd (in s f l)
  (cond
    ((eql in nil)
     ())
    (t
     (append l (list (list 'frob s (car in) (+ 1 f)))))))

With this version we get a result:

[8]> (func '(foo x y) 0 0 ())
5. Trace: (func '(foo x y) '0 '0 'nil)
6. Trace: (foo-asd '(x y) '0 '0 'nil)
7. Trace: (func '(x y) '0 '0 '((frob 0 myst 1)))
8. Trace: (atom-asd '(x y) '1 '1 '((frob 0 myst 1)))
8. Trace: atom-asd ==> ((frob 0 myst 1) (frob 1 x 2))
7. Trace: func ==> ((frob 0 myst 1) (frob 1 x 2))
6. Trace: foo-asd ==> ((frob 0 myst 1) (frob 1 x 2))
5. Trace: func ==> ((frob 0 myst 1) (frob 1 x 2))
((frob 0 myst 1) (frob 1 x 2))
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, but foo-asdstill it isn't called, the result must be ((frob 0 myst 1) (frob 1 x 2) (frob 2 y 3) (frob 3 myst 4))
@Aonna You clearly see from the trace that foo-asd is called once and the reason is that the cond stop at the very first truthy predicate. Thus it finished since (func in s f (append l (list (list 'frob s 'myst (+ 1 f))))) returns a non nil value. If you want it to handle both you need to program it like that instead. Just like if elseif else it will never do else if it hit one if the if caluses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.