Note that there are some explanatory texts on larger screens.

plurals
  1. POElisp recursive macro
    primarykey
    data
    text
    <p>Trying to define resursive macro in elisp</p> <pre><code>(defmacro remacro (keys) (if keys `(func1 ,(car keys) ,(remacro (cdr keys))) )) (macroexpand '(remacro '(a b c))) </code></pre> <p>But it is ended up in</p> <pre><code> Lisp nesting exceeds `max-lisp-eval-depth' </code></pre> <p>error.</p> <p>Wanted to get result like</p> <pre><code>(func1 a (func1 b (func1 c nil nil) '(c)) '(b c)) </code></pre> <p>from</p> <pre><code>(remacro '(a b c)) </code></pre> <p>Please let me know how I can correct this definition.</p> <p>One more thing could I defined `keys' as rest parameter like</p> <pre><code>(defmacro remacro (&amp;rest keys) (if keys `(abc ,(car keys) ,(remacro `,@(cdr keys))) )) </code></pre> <p>tried this one but it is not working.</p> <p>USE CASE:</p> <p>Basically I wanted to define a function</p> <p>to set a tree node that is arranged in alist way</p> <p>(it is still not working, have to work on it)</p> <pre><code>(defmacro set-tree-node (tree e &amp;rest keys) `(setcdr ,(if keys `(assoc (car keys) (pushnew (list ,(car keys)) (cdr ,(set-tree-node `(cdr ,xtree) e `,@(cdr keys))) :key 'car)) tree) e)) (setq egtree nil) </code></pre> <p>After running</p> <pre><code>(set-tree-node egtree new-node n b c) </code></pre> <p>should get</p> <p>egtree eq</p> <pre><code>((n (b (c . new-node)))) </code></pre> <p>or</p> <pre><code>(n (b (c . new-node))) </code></pre> <p>I had defined it as function</p> <pre><code>(defun set-tree-node (tree e &amp;rest keys) (setcdr (reduce (lambda (xtree k) (message "tree %s k %s" xtree k) (assoc k (pushnew (list k) (cdr xtree) :key 'car))) keys :initial-value (cons nil tree)) e)) </code></pre> <p>But it could work only for existing list</p> <p>It can successfully change (tree if full path exists)</p> <pre><code> egtree from (setq egtree '((n (b (c . d))))) </code></pre> <p>to</p> <pre><code> egtree eq '((n (b (c . replaced-d)))) </code></pre> <p>after called like this</p> <pre><code> (set-tree-node jt 'replaced-d 'n 'b 'c) </code></pre> <p>But this function do not work with if list if complete path do not exits</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload