From: Philippe Lorin
Subject: How to determine the top caller in Slime's REPL
Date: 
Message-ID: <447dc36d$0$29899$636a55ce@news.free.fr>
In Slime, I need to be able to determine dynamically whether the "top 
caller" of the currently executing code is some specifically marked 
expression, or just one of all the other expressions typed at the REPL 
which might be running in parallel.

An example should make the idea clearer.

(defun f ()               ; This function is just here to show that the
   (in-marked-expression)) ; test is not necessarily lexically enclosed
                           ; in the marked expression.

(mark-and-eval
  (do () (nil)         ; Just an infinite loop, to make sure the
                       ; expression will be running forever in parallel.
    (assert (f))))     ; Here, IN-MARKED-EXPRESSION must always return T.

(f)                 ; Note that the preceding (DO ...) is still running.
=> NIL              ; Here, IN-MARKED-EXPRESSION must always return NIL.



I can write the marked expression with complete freedom (for instance, I 
can add wrappers around it or preprocess it), but all the other 
expressions typed after it at the REPL are not under my control.
Among the ideas I've tested, the following one sounded the most 
promising, but it doesn't work. I don't understand why.

(defun in-marked-expression ()
   (not (null (find-restart 'restart-in-restart-case)))) ; Are we in the
                                                         ; restart-case?

(defun f ()
   (in-marked-expression))

(restart-case
     (do () (nil)
       (assert (f)))
   (restart-in-restart-case () nil))

(f)
=> T                ; :(



Can anybody help?

From: Geoffrey Summerhayes
Subject: Re: How to determine the top caller in Slime's REPL
Date: 
Message-ID: <1149188866.148038.71850@i40g2000cwc.googlegroups.com>
Philippe Lorin wrote:
> In Slime, I need to be able to determine dynamically whether the "top
> caller" of the currently executing code is some specifically marked
> expression, or just one of all the other expressions typed at the REPL
> which might be running in parallel.
>
> An example should make the idea clearer.
>
> (defun f ()               ; This function is just here to show that the
>    (in-marked-expression)) ; test is not necessarily lexically enclosed
>                            ; in the marked expression.
>
> (mark-and-eval
>   (do () (nil)         ; Just an infinite loop, to make sure the
>                        ; expression will be running forever in parallel.
>     (assert (f))))     ; Here, IN-MARKED-EXPRESSION must always return T.
>
> (f)                 ; Note that the preceding (DO ...) is still running.
> => NIL              ; Here, IN-MARKED-EXPRESSION must always return NIL.

Why not just:

(defparameter *in-marked-expression* nil)

(defmacro mark-and-eval (&body body)
  `(let ((*in-marked-expression* t)) ,@body))

(defun in-marked-expression () *in-marked-expression*)

--
Geoff
From: Philippe Lorin
Subject: Re: How to determine the top caller in Slime's REPL
Date: 
Message-ID: <44817ee3$0$19179$626a54ce@news.free.fr>
Geoffrey Summerhayes wrote:
> Why not just:
> 
> (defparameter *in-marked-expression* nil)
> 
> (defmacro mark-and-eval (&body body)
>   `(let ((*in-marked-expression* t)) ,@body))
> 
> (defun in-marked-expression () *in-marked-expression*)

Well, that doesn't work. I guess it's because, *IN-MARKED-EXPRESSION* 
being special, LET does not create a new binding for it. Or am I wrong? 
I did test it (using CMUCL + Slime).
From: Nikodemus Siivola
Subject: Re: How to determine the top caller in Slime's REPL
Date: 
Message-ID: <1149476409.283522.167510@i39g2000cwa.googlegroups.com>
Philippe Lorin wrote:

> Geoffrey Summerhayes wrote:
> > (defparameter *in-marked-expression* nil)
> >
> > (defmacro mark-and-eval (&body body)
> >   `(let ((*in-marked-expression* t)) ,@body))
> >
> > (defun in-marked-expression () *in-marked-expression*)

> Well, that doesn't work. I guess it's because, *IN-MARKED-EXPRESSION*
> being special, LET does not create a new binding for it. Or am I wrong?
> I did test it (using CMUCL + Slime).

It should work perfectly. LET most definitely binds the
*IN-MARKED-EXPRESSION* there. How did you test it?

By the by, the more idiomatic usage would be WITH-MARKED-EXPRESSION for
the
macro, whereas MARK-AND-EVAL would look something like

(defun mark-and-eval (expression)
  (let ((*in-marked-expression* t)) ; assuming a previous defvar /
defparameter
    (eval expression)))

Cheers,

 -- Nikodemus Siivola
From: ············@gmail.com
Subject: Re: How to determine the top caller in Slime's REPL
Date: 
Message-ID: <1149771592.849502.148980@u72g2000cwu.googlegroups.com>
> It should work perfectly. LET most definitely binds the
> *IN-MARKED-EXPRESSION* there. How did you test it?

Thank you for trying to help me. I do admit I don't understand what's
going wrong. Here is what I'm doing, step by step.

Using Ubuntu (6.04?), GNU Emacs 21.4.1, Slime 1.2.1, CMUCL (19?)
Launch Emacs
M-x slime

(defparameter *in-marked-expression* nil)

(defmacro mark-and-eval (&body body)
  `(let ((*in-marked-expression* t)) ,@body))

(defun in-marked-expression () *in-marked-expression*)

(mark-and-eval (do () (nil) (assert (in-marked-expression))))

RET
=> ; No value

(in-marked-expression)
=> T

I want this to be NIL. Did I miss something, or did I not state my
problem clearly enough?