From: Colin Rafferty <craffert@ml.com>
Subject: Re: function to pack folders
Date: 02 Feb 1998 15:00:07 -0500 [thread overview]
Message-ID: <ocru3ahydyw.fsf@ml.com> (raw)
In-Reply-To: Mark Moll's message of "02 Feb 1998 13:22:53 -0500"
Mark Moll writes:
> I wrote this little function to renumber articles in my nnml folders. I
> don't know that much about elisp, but this seemed a reasonable way to do it.
> For some reason, however, I get the following error when I call the function
> below in the summary buffer.
> Symbol's value as variable is void: group
> It's probably something very trivial, but can anybody tell me what I'm
> doing wrong?
> ...
> (let ((group gnus-newsgroup-name)
> (folder (replace-in-string
> (replace-in-string group
> "\\(nnml\\+archive:\\)\\(.*\\)"
> "archive/\\2")
> "\\(nnml:\\)\\(.*\\)" "\\2"))
> (dir (concat message-directory folder)))
> ...
Short answers (two independent solutions):
1. Use `let*' instead of `let'.
2. Use `gnus-newsgroup-name' instead of `group' in the call to
`replace-in-string'.
Long answer:
The problem is the `group' in the call to replace-in-string. Since you
are using `let', the variables are not bound until the body is being
executed.
Specifically, a `let' form is really just syntactic sugar for calling a
lambda-expression, and you cannot use the values of some of the
arguments to evaluate the other arguments.
For example, imagine I had the following let form:
(let ((x (* 2 3))
(y (+ 5 6)))
(+ x y))
It will be translated into the following:
(funcall #'(lambda (x y)
(+ x y))
(* 2 3)
(+ 5 6))
Therefore, if you have something that looks like this:
(let ((group gnus-newsgroup-name)
(folder (replace-in-string
(replace-in-string group
"\\(nnml\\+archive:\\)\\(.*\\)"
"archive/\\2")
"\\(nnml:\\)\\(.*\\)" "\\2"))
(dir (concat message-directory folder)))
(call-process "gunzip" nil nil nil (concat dir "/*.gz"))
(call-process "folder" nil nil nil (concat "+" folder) "-pack")
(nnml-generate-nov-databases-1 (concat dir))
(call-process "gzip" nil nil nil (concat dir "/*"))
(gnus-summary-reselect-current-group))
It would be translated into this:
(funcall #'(lambda (group folder dir)
(call-process "gunzip" nil nil nil (concat dir "/*.gz"))
(call-process "folder" nil nil nil (concat "+" folder) "-pack")
(nnml-generate-nov-databases-1 (concat dir))
(call-process "gzip" nil nil nil (concat dir "/*"))
(gnus-summary-reselect-current-group))
gnus-newsgroup-name
(replace-in-string (replace-in-string group
"\\(nnml\\+archive:\\)\\(.*\\)"
"archive/\\2")
"\\(nnml:\\)\\(.*\\)" "\\2")
(concat message-directory folder))
As you can see, the reference to `group' in the `replace-in-string' is
unbound, since it only exists in the lambda-expression itself.
By the way, while I was writing this reply, I realized that, while `let'
is a built-in function, I could write it as a macro. I really need to
get a more exciting job.
(defmacro mac-let (varlist &rest body)
"Macro version of let."
(append
(list 'funcall
(append
(list 'lambda
(mapcar #'(lambda (varspec)
(cond ((symbolp varspec) varspec)
((consp varspec) (car varspec))
(error "invalid varspec %s" varspec)))
varlist))
body))
(mapcar #'(lambda (varspec)
(and (consp varspec) (car (cdr varspec))))
varlist)))
I'll leave writing `mac-let*' as an exercise to the reader. :-)
--
Colin
prev parent reply other threads:[~1998-02-02 20:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-02-02 18:22 Mark Moll
1998-02-02 20:00 ` Colin Rafferty [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ocru3ahydyw.fsf@ml.com \
--to=craffert@ml.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).