emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [babel] Code for simple set-operations on two tables. Asking for


From: Eric Schulte
Subject: Re: [O] [babel] Code for simple set-operations on two tables. Asking for some input.
Date: Sun, 15 Jan 2012 09:10:13 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Hi Marc-Oliver,

I would recommend two small coding style points for writing lisp code
(especially for inclusion into the library of babel).

1. You *never* want to leave trailing ")"'s on a line by themselves,
   but rather you should always stack these, indentation is used to
   visually identify nesting in lisp. e.g., this

    (defun lob-table-operations-filter (what table filter)
      "Internal function for table-operations in orgmodes library of babel"
      (let (keys
            result)
        (setq keys (mapcar 'car filter))
        (dolist (line table) 
          (if (equal (not (not (member (car line) keys)))
                     (equal what 'keep))
              (setq result (cons line result))
            )
          )
        (nreverse result)
        )
      )

   should be

     (defun lob-table-operations-filter (what table filter)
       "Internal function for table-operations in orgmodes library of babel"
       (let (keys result)
         (setq keys (mapcar 'car filter))
         (dolist (line table) 
           (when (equal (not (not (member (car line) keys)))
                        (equal what 'keep))
             (setq result (cons line result))))
         (nreverse result)))

   Using `paredit-mode' makes this behavior very easy to maintain.  This
   point is true for any lisp coding (not just in the library of babel).

2. When writing code for the library of babel, please try to keep all
   lines <= 79 characters long.  I like to use [1] to identify overlong
   lines by adding the following to my .emacs

      (require 'column-marker)
      (add-hook 'emacs-lisp-mode-hook
        (lambda () (column-marker-3 80)))

Also, two non-style suggestions;

1. If you set "results" to "silent" as a subtree property in your
   "Internals" subtree you won't have to remove empty results.

2. In one function you save many functions into local variables and then
   call them using funcall, it may be simpler to use flet to define
   local functions which can then be called directly.

I'm very pleased to hear that you're enjoying babel, and look forward to
your contribution to the library of babel.

Cheers,

Marc-Oliver Ihm <address@hidden> writes:

> Hello,
>
> please find attached an early draft of lob-table-operations.org.
>
> It already has a reasonable documentation and working examples, so it
> should be easy to play with.
>
> Some features are still missing (e.g. handling of column names and hlines)
> and the coding needs some improvement (using the cl-package ?).
> So it is probably not yet fit for official inclusion into the library of 
> babel.
>
> with kind regards,
> Marc-Oliver Ihm
>
> As a side note: I am very pleased and fascinated, how easily babel and
> org have made the task of keeping together
> all aspects of development; from user documentation to implementation
> and (of course !) organisation.
>
> This has made my coding even more fun !
>
>


Footnotes: 
[1]  http://www.emacswiki.org/emacs/ColumnMarker

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]