[Top][All Lists]

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

Re: Generalize and standarize dired-plural-s

From: Tino Calancha
Subject: Re: Generalize and standarize dired-plural-s
Date: Mon, 19 Sep 2016 04:28:44 +0900 (JST)
User-agent: Alpine 2.20 (DEB 67 2015-01-07)

On Sun, 18 Sep 2016, Yuri Khan wrote:

It is also easier to extend to other languages, if and when we deem it
necessary. (It would require passing an additional argument to specify
language, and more forms (singular, dual, trial, paucal, plural).)

I also suggest that the function be split in two: a core function
dealing with integers only, and a convenience wrapper that also
accepts sequences.

Thank you Yuri for your suggstions.
Something like this? With the additional forms and the language argument
keep unimplemented:

(defsubst string--plural-s-1 (arg singular plural _dual _trial _paucal _lang)
  (if (= arg 1) singular plural))

(defun string--plural-s-2 (arg singular plural _dual _trial _paucal _lang)
  (cond ((null arg) plural)
        ((consp arg)
         (if (null (cdr arg)) singular plural))
        ((arrayp arg)
         (if (= (length arg) 1) singular plural))))

(defun string-plural-s (arg &optional string plural dual trial paucal lang)
Return plural of STRING if ARG is nil, or an integer >1, or a seq of length >1.
If ARG is =1 or a sequence of length =1, return STRING.
If STRING is nil, return \"s\" or \"\".
Optional arg PLURAL is the plural of STRING.
Optional arg DUAL is the =dual of STRING.
Optional arg TRIAL is the trial of STRING.
Optional arg PAUCAL is the paucal of STRING.
Optional arg LANG is the language of STRING.  Default to english."
  (let ((sin (or string ""))
        (plu (if (and string plural) plural
               (apply #'string (append string "s" nil)))))
    (cond ((natnump arg)
           (string--plural-s-1 arg sin plu dual trial paucal lang))
          ((sequencep arg)
           (string--plural-s-2 arg sin plu dual trial paucal lang))
           (signal 'wrong-type-argument
                   (list arg 'natnump 'listp 'arrayp))))))

reply via email to

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