Subject: bug#16201: 24.3.50; error expanding pcase with a pred clause

From: Michael Heerdegen <[email-masked]>
Date: Sat, 21 Dec 2013 12:54:21 +0100

Michael Heerdegen <[email-masked]> writes:

> (defun test-buffer-file-name ()
>   (pcase buffer-file-name
>     (`nil                   'not-a-file)
>     ((pred file-writable-p) 'writable)
>     (_                      'not-writable)))
>
>   pcase-bug.el:3:1:Error: Wrong type argument: stringp, nil

pcase seems to test whether the constant (nil) from the first clause
fulfills the pred of the second clause.  Which is not legal in this
case.

I thought this could be ok:

(pcase buffer-file-name
    (`nil                   'not-a-file)
    ((and (pred stringp)
	  (pred file-writable-p)) 'writable)
    (_                      'not-writable))

but that triggers the same error.

This works, however, but doesn't look so nice:

  (pcase buffer-file-name
    (`nil                   'not-a-file)
    ((pred (lambda (x) (and (stringp x) (file-writable-p x)))) 'writable)
    (_                      'not-writable))

Regards,

Michael.