You are viewing lhealy

Liam Healy - A CL workbook

Jun. 21st, 2010

10:36 pm - A CL workbook

Previous Entry Add to Memories Share Next Entry

I am looking for a way to conveniently keep a session of Lisp interaction. For example, when I write down a problem and solution for class, I define a succession of variables with defparameter (or a slightly more convenient form I've defined). In a later year, if I give the problem again with different numbers, I just change the defining parameters, and recalculate. This is clumsy, but it mostly works. What I'd really like is to define a few input parameters, and stepwise calculate the intermediate quantities. A single defun isn't appropriate because I need the intermediate values to show to the students. The defparameter approach is tedious and prone to error.

What I envision is a structure or class instance with "given values" provided at the beginning, and steps consisting of the form and the value. A new instance of the same problem would have the same forms to evaluate, but different values. It might also be nice to branch, i.e., at some step in the calculation, continue with a different set of calculations. but still be able to keep the tree structure (kind of like git for Lisp forms? hmmm).

Is there anything like this (in any language) out there? I tried some googling but if there's something along these lines out there, I'm not using the right keywords. For lack of a better word, I'm calling it a Lisp workbook or notebook. Bonus if it will integrate with LaTeX and/or org-mode.

Tags:

Comments:

From:(Anonymous)
Date:June 22nd, 2010 05:15 am (UTC)

babel + org + git?

(Link)
I've not quite gotten org + babel + slime working quite as you describe, but it is a start (trying to make the R/ESS and emacs-lisp babel modes merge into a Common Lisp + slime mode).

Will post if I get it working, though...

best,
-tony
(blindglobe@gmail.com)
From:lhealy
Date:June 23rd, 2010 02:04 am (UTC)

Re: babel + org + git?

(Link)
Sounds interesting. Have you seen MMM Mode?
From:(Anonymous)
Date:June 22nd, 2010 05:57 am (UTC)

A CL workbook

(Link)
Maybe trace does some of what you want?

Eivind
From:lhealy
Date:June 23rd, 2010 02:06 am (UTC)

Re: A CL workbook

(Link)
No, too crude. I would like a neat and readable (and re-runnable) output; some of my output is formatted directly in LaTeX and I use that directly. Also, it be very hard to specify e.g. which '+ is the one I want to see.
From:(Anonymous)
Date:June 22nd, 2010 06:10 am (UTC)
(Link)
> I am looking for a way to conveniently keep a session of Lisp interaction.

See what your implementation does for "(dribble filename)".

http://www.lispworks.com/documentation/lw51/CLHS/Body/f_dribbl.htm#dribble
From:lhealy
Date:June 23rd, 2010 02:07 am (UTC)

dribble

(Link)
Useful, but it's one-way, i.e., output only. It doesn't lend itself to changing parameters and rerunning.
From:(Anonymous)
Date:June 22nd, 2010 11:47 am (UTC)

CLWEB

(Link)
CLWEB may work for you. It's a literate programming system for Common Lisp with good emacs integration. You can easily separate parameters from solution code, use sections to create different versions of solutions, and you can write about the problems in LaTeX in the same file.

http://www.cs.brandeis.edu/~plotnick/clweb/
From:(Anonymous)
Date:June 22nd, 2010 11:49 am (UTC)

Re: CLWEB

(Link)
Made a thinko, plain TeX not LaTeX
From:lhealy
Date:June 23rd, 2010 02:10 am (UTC)

Re: CLWEB

(Link)
I'm superficially familiar with Knuth's work, so this is interesting. But, there's no (specific) documentation. Do you have examples?
From:(Anonymous)
Date:June 22nd, 2010 11:52 am (UTC)

Example Paste

(Link)
An example paste would be useful. ~ tmh
From:lhealy
Date:June 23rd, 2010 02:25 am (UTC)

Re: Example Paste

(Link)
Sure. Notice how I paste in some multi-line output from CL inside
a comment, then I have individual line comments. And this is
a "real life" example, so instead of (sidereal-time (epoch lageos))
I repeat the time:
(sidereal-time #d2010-03-01T13:20:00)
meaning that I if that changed I'd have to repeat it.
And then I define it later, this time with (epoch lageos). Ugh.

      \begin{comment}
(DEFPARAMETER LAGEOS
  (MAKE-SIR :TYPE 'SATELLITE-INFORMATION-RECORD :GEOCENTRIC-EQUATORIAL-POSITION
            #(#_-4323.000000000000000_km #_-784.700000000000000_km
              #_11410.000000000000000_km)
            :GEOCENTRIC-EQUATORIAL-VELOCITY
            #(#_-2.674000000000000_km/s #_5.011000000000000_km/s
              #_-0.685600000000000_km/s)
            :EPOCH
            (MAKE-TIMEPOINT :TIMEPARSE '(0 20 13 1 3 2010) :DAY-ONLY NIL :SCALE
                            :UTC)
            :SUMMARY 'NIL))
    \end{comment}
     %% (sidereal-time #d2010-03-01T13:20:00)
    The sidereal time is $\gst{} = -0.7614\dgr$ from the formula
      given in class, so using 
      $\rv_{\text{ITRF}} = \rotz(\gst{}) \rv_{\text{IJK}}$, 
      \begin{equation}
        \label{eq:4}
        %% (defp lageos-st (sidereal-time (epoch lageos)))
        %% (ijk-to-ecef-rot lageos-st)
        \rv =
        \left[\begin{array}{rrr}
        0.9999 & \fltpt{-1.329}{-2} & 0.000 \\
        \fltpt{1.329}{-2} & 0.9999 & 0.000 \\
        0.000 & 0.000 & 1.000
      \end{array}\right]
        %% (nf (pos lageos))
    \left[\begin{array}{r}-4323\\-784.7\\\fltpt{1.141}{4}\end{array}\right]\unit{km}
      \end{equation}
      which is
      %% (defp lageosb-posvel (ijk-to-ecef lageos-st lageos))
      \begin{boxeqn}
        %% (numerica-format (subseq lageosb-posvel 0 3))
        \rv =
        \left[\begin{array}{r}
            -4312\\-842.1\\\fltpt{1.141}{4}\end{array}\right]\unit{km}.
      \end{boxeqn}
From:(Anonymous)
Date:June 23rd, 2010 12:34 pm (UTC)

Re: Example Paste

(Link)
My first thought is that you need something along the lines of WEB or NOWEB. (Disclaimer: I am biased towards NOWEB). It would need to be able to evaluate the chunks of code, so it would be an extension of NOWEB. Then, I realized that you also need macro like control over evaluation to store intermediate values. It wasn't clear to me what the semantics of that might look like.

Regardless, I'm not aware of any tool that does that. Looks like an opportunity to develop one for fun and profit or fame and glory. :-)

~ tmh
From:http://tentpost.com/openid/dherring.php
Date:June 22nd, 2010 03:16 pm (UTC)

Possible comparables

(Link)
Sounds somewhat like a spreadsheet, mathcad, mathematica, or matlab.
From:lhealy
Date:June 23rd, 2010 02:14 am (UTC)

Re: Possible comparables

(Link)
Somewhat, don't know, not really, not really.

Spreadsheet idea is interesting. I think there was a CL
spreadsheet at one point. Not sure how I'd embed that
in LaTeX, but that's only an optional extra anyway.

I don't know mathcad, but suspect it's similar (for
these purposes) to mma and matlab. There's nothing wrong
with mma and matlab, but lisp has the REPL and to that
extent has the same features of mma and matlab.
I want more than that. At one point mma had a thing
called "notebooks" (I haven't used mma in years, so
it might be something different now) and that is
kind of what I'm getting at.
From:(Anonymous)
Date:June 24th, 2010 01:22 pm (UTC)

Re: Possible comparables

(Link)

Maxima has something like latex(expresion) and you can also use Lisp with maxima. There is a maxima to Lisp translator.

So you can program in Lisp using maxima commands to extend the language and use tex(expr) or latex(expr) to write the result. Also there is a maxima command to be used inside emacs
From:(Anonymous)
Date:June 27th, 2010 04:34 pm (UTC)

Do you mean something like this?

(Link)
(defclass hash-slots-object (standard-object)
  ((slot-table :initform (make-hash-table) :reader slot-table)))

(defmethod slot-missing ((class standard-class) (object hash-slots-object)
                         slot-name operation &optional new-value)
  (ecase operation
    (setf (setf (gethash slot-name (slot-table object)) new-value)) 
    (slot-boundp (nth-value 1 (gethash slot-name (slot-table object))))
    (slot-makunbound (remhash slot-name (slot-table object)) object)
    (slot-value (multiple-value-bind
                    (value foundp)
                    (gethash slot-name (slot-table object))
                  (if foundp value
                    (slot-unbound class object slot-name))))))
    
(defmacro object-let (object (&rest bindings) &body body)
  `(with-slots ,(mapcar #'car bindings) ,object
     (psetq ,@(loop for (var value) in bindings
                    nconc (list var value)))
     ,@body))

(defmacro object-let* (object (&rest bindings) &body body)
  (let ((obj (gensym)))
    (if bindings
      `(let ((,obj ,object))
         (object-let ,obj (,(car bindings))
           (object-let* ,obj ,(cdr bindings) ,@body)))
      `(progn ,@body))))

(defun example ()
  (let ((object (make-instance 'hash-slots-object)))
    (object-let* object
        ((x 1)
         (y 2)
         (z (+ x y))
         (a (/ z y))
         (b (+ a a)))
      object)))


...at the end, you can inspect the object and it will have all the slots set to the intermediate results.

Pascal Costanza
From:(Anonymous)
Date:July 2nd, 2010 12:34 pm (UTC)
(Link)
Emacs Calc has an embeded mode. Take a look at it!