<div dir="ltr">Hi<div><br></div><div>In the pattern matcher I wrote I tried to add a setter for the defined variables in the pattern; after a lot of work I've got the following implementation (close to it):</div><div>
<p class="">(<span class="">let</span> ((acc-x) (prev-x) (x 5))</p>
<p class=""> (<span class="">flet</span> (((setf foox) (value x) (funcall x value)))</p>
<p class=""> (<span class="">macrolet</span> ((it (x)</p>
<p class=""> (<span class="">let</span> ((xacc (intern (<span class="">for</span>mat nil <span class="">"ACC-~A"</span> (symbol-name x))))</p>
<p class=""> (xprev (intern (<span class="">for</span>mat nil <span class="">"PREV-~A"</span> (symbol-name x)))))</p>
<p class=""> `(foox (<span class="">cond</span></p>
<p class=""> ((null ,xacc) (<span class="">lambda</span> (v) (setf ,x v)))</p>
<p class=""> ((eq ,xacc 'car) (<span class="">lambda</span> (v) (setf (car ,xprev) v)))</p>
<p class=""> (t (<span class="">lambda</span> (v) (setf (cdr ,xprev) v))))))))</p>
<p class=""> (setf (it x) 3) x)))</p><p class="">PS: I cannot use (setf x y) instead of (setf (it x) y) because the variables x, y are defined within the match macro: (let ((x) (y)) ...)</p><p class="">I spent a lot of time figuring out this solution, but I am wondering if there is a better implementation.</p><p class="">Example of usage:</p><p class="">
</p><p class=""><b>? (let ((a '(1 (2 3)))) (match a ((1 (?x ?y)) (setf (it x) y) a)))</b></p><p class="">
</p><p class="">(1 (3 3))</p><p class="">Kind regards</p><p class="">Taoufik</p><p class=""><br></p><p class=""><br></p></div></div>