<div dir="ltr">Hi<div><br></div><div>Thank you for the rapid reply</div><div><br></div><div>the select accepts a pattern with special variables (?x, ?y, ...)</div><div><br></div><div>The select when it founds a bound special variable ?x it will replace it by its value in the pattern</div>
<div><br></div><div>Example: with ?x unbound (select-loop (p ?x a) collect it) will return all expressions in the db where the first and the third </div><div>elements are p and a respectively, but if ?x is bound to Z say, then the select will return (p Z a) if it exists in the db</div>
<div><br></div><div>I did this in order to embed queries like the following:</div><div><br></div><div>(select-loop (p ?x a) append (select-loop (?x ?y) collect it) (the second ?x will be bound to the value of ?x returned by the </div>
<div>first select (nested loops)</div><div><br></div><div>I did not see the infinite loop I will check again and see if I can solve this</div><div><br></div><div>Thanks</div><div>Taoufik</div><div><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sat, Dec 28, 2013 at 10:06 PM, Ron Garret <span dir="ltr"><<a href="mailto:ron@flownet.com" target="_blank">ron@flownet.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
You have an infinite loop in your macroexpansion:<br>
<br>
? (macroexpand-all '(ancestor ?x a))<br>
> Error: Stack overflow on value stack.<br>
<br>
Also, I have no idea what this code is intended to do, but whatever it is this almost certainly isn’t helping:<br>
<br>
? (pprint (macroexpand '(ancestor ?x a)))<br>
<br>
(LET ((?X '?X) (?Y 'A))<br>
(DECLARE (SPECIAL ?X ?Y))<br>
(IF (VAR? ?X) (MAKUNBOUND ?X))<br>
(IF (VAR? ?Y) (MAKUNBOUND ?Y))<br>
(UNION (SELECT-LOOP (P ?X ?Y) COLLECT IT)<br>
(SELECT-LOOP (P ?X ?Z) APPEND (ANCESTOR ?Z ?Y))))<br>
<br>
You are binding ?X to itself, and then immediately making it unbound again. That is almost certainly not what you want to do.<br>
<br>
rg<br>
<div><div class="h5"><br>
<br>
On Dec 28, 2013, at 12:05 PM, Taoufik Dachraoui <<a href="mailto:dachraoui.taoufik@gmail.com">dachraoui.taoufik@gmail.com</a>> wrote:<br>
<br>
> Hi<br>
><br>
> Could you please check this "Unhandled exception" and explain what is wrong<br>
> with my code<br>
><br>
> (defun var? (x)<br>
> (and (symbolp x) (not (keywordp x)) (eq (char (symbol-name x) 0) #\?)))<br>
><br>
> (defun vars-in (expr)<br>
> (if (atom expr)<br>
> (if (var? expr) (list expr))<br>
> (union<br>
> (vars-in (car expr))<br>
> (vars-in (cdr expr)))))<br>
><br>
> (defmacro aif (test-form then-form &optional else-form)<br>
> `(let ((it ,test-form))<br>
> (if it ,then-form ,else-form)))<br>
><br>
> (defun select! (pat) ; returns a list of bindings<br>
> (print pat)<br>
> '((it . (p b a)) (?x . 'b)))<br>
><br>
> (defmacro select-loop (pat &rest keywords-and-forms)<br>
> (let ((bind (gensym))<br>
> (vars (cons 'it (vars-in pat))))<br>
> `(block select-loop<br>
> (aif (select! ',pat)<br>
> (progn<br>
> (let ((binds it) ,@(mapcar #'list vars))<br>
> (declare (special ,@vars))<br>
> (loop for ,bind in binds<br>
> do (progn<br>
> (setf it (cdr (assoc 'it ,bind)))<br>
> ,@(mapcar #'(lambda (v) `(setf ,v (cdr (assoc ',v ,bind))))<br>
> vars))<br>
> ,@keywords-and-forms)))))))<br>
><br>
> (defmacro defrule (name args &rest body)<br>
> `(defmacro ,name ,args<br>
> (list 'let (list ,@(mapcar #'(lambda (x) `(list ',x `',,x)) args))<br>
> '(declare (special ,@args))<br>
> ,@(mapcar #'(lambda (x) `'(if (var? ,x) (makunbound ,x))) args)<br>
> ,@(mapcar #'(lambda (x) `',x) body))))<br>
><br>
> (defrule ancestor (?x ?y)<br>
> (union<br>
> (select-loop (p ?x ?y) collect it)<br>
> (select-loop (p ?x ?z)<br>
> append (ancestor ?z ?y))))<br>
><br>
> ? (ancestor ?x a)<br>
><br>
> Unhandled exception 10 at 0x28545, context->regs at #xb01641fc<br>
> Exception occurred while executing foreign code<br>
> at compact_dynamic_heap + 965<br>
> received signal 10; faulting address: 0xd360000<br>
> ? for help<br>
> [3422] Clozure CL kernel debugger: ?<br>
> (G) Set specified GPR to new value<br>
> (R) Show raw GPR/SPR register values<br>
> (L) Show Lisp values of tagged registers<br>
> (F) Show FPU registers<br>
> (S) Find and describe symbol matching specified name<br>
> (B) Show backtrace<br>
> (T) Show info about current thread<br>
> (M) Show memory areas<br>
> (X) Exit from this debugger, asserting that any exception was handled<br>
> (P) Propagate the exception to another handler (debugger or OS)<br>
> (K) Kill Clozure CL process<br>
> (V) Show Subversion revision information<br>
> (?) Show this help<br>
> [3422] Clozure CL kernel debugger: B<br>
> current thread: tcr = 0x2000f0, native thread ID = 0xbe03, interrupts enabled<br>
><br>
><br>
> Bogus frame 606b40<br>
> [3422] Clozure CL kernel debugger: L<br>
> [3422] Clozure CL kernel debugger:<br>
><br>
><br>
> Kind regards<br>
> Taoufik<br>
><br>
</div></div>> _______________________________________________<br>
> Openmcl-devel mailing list<br>
> <a href="mailto:Openmcl-devel@clozure.com">Openmcl-devel@clozure.com</a><br>
> <a href="http://clozure.com/mailman/listinfo/openmcl-devel" target="_blank">http://clozure.com/mailman/listinfo/openmcl-devel</a><br>
<br>
</blockquote></div><br></div>