Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-opus-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

Review the following function: (defvar special-notes '()) (defun define-special-note…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.0-flash-001’s answer.
  1. User

    Review the following function:

    (defvar special-notes '())

    (defun define-special-note (name &optional opening body preamble) (push name special-notes) (let* ((kebab-name (replace-regexp-in-string "\s-+" "-" (downcase name) t)) (function-name (intern kebab-name)) (buffer-name (format "%s" kebab-name)) (content (concat preamble opening body))) (defalias function-name (lambda () (interactive) (if (buffer-live-p (get-buffer buffer-name)) (kill-buffer buffer-name)) (get-buffer-create buffer-name) (with-current-buffer buffer-name (org-mode) (insert content) (goto-char (point-min)) (setq-local buffer-read-only t)) (switch-to-buffer buffer-name)))))

  2. Claude Assistant

    This Emacs Lisp function creates a system for defining "special notes" - essentially creating custom commands that open read-only Org-mode buffers with predefined content. Here's my review:

    Strengths

    The function demonstrates good Lisp practices in several ways. It uses defvar to properly declare the global variable, converts names to kebab-case for consistency with Emacs naming conventions, and creates buffer names following the standard *buffer-name* format. The use of defalias to dynamically create named functions is clever, and setting buffers as read-only prevents accidental modifications.

    Areas for Improvement

    Variable Declaration: The special-notes list is modified but never read in the provided code. If it's meant to track defined notes, consider documenting its purpose or providing a function to list available notes.

    Error Handling: The function lacks validation for edge cases. What happens if name is nil or an empty string? Consider adding checks:

    (unless (and name (not (string-empty-p name)))
      (error "Name cannot be empty"))
    

    Buffer Management: The current approach kills and recreates buffers on each invocation. This might be intentional, but it prevents users from having multiple views of the same note. Consider checking if the buffer exists and just switching to it, only recreating if the user explicitly requests it.

    Parameter Handling: The opening, body, and preamble parameters are optional but their purpose isn't clear from the code. Consider adding a docstring explaining what each represents and how they're used.

    Memory Considerations: Each call to define-special-note creates a new lambda that's permanently stored. If many notes are defined, this could accumulate. Consider whether old definitions should be removable.

    Suggested Improvements:

    (defun define-special-note (name &optional opening body preamble)
      "Define a special note command that opens a read-only Org buffer.
    NAME: The name of the note (will be converted to kebab-case for the command name).
    OPENING: Optional opening text.
    BODY: Optional body content.
    PREAMBLE: Optional preamble text (appears before opening)."
      (unless (and name (not (string-empty-p name)))
        (error "Name cannot be empty"))
      
      ;; Rest of the function...
      )
    

    The function is well-structured overall and follows Emacs conventions. With some additional error handling and documentation, it would be more robust for production use.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.