From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: count char in string [The Emacs Challenge Competition - round 2, with fallout] Date: Thu, 29 Oct 2020 09:13:55 -0700 (PDT) Message-ID: References: <87r1pj41wa.fsf@zoho.eu> <87k0v9fhbi.fsf@rub.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37861"; mail-complaints-to="usenet@ciao.gmane.io" To: Stephen Berman , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 29 17:16:45 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kYAbS-0009dl-5L for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 29 Oct 2020 17:16:42 +0100 Original-Received: from localhost ([::1]:59622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYAbR-0003GL-74 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 29 Oct 2020 12:16:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYAat-0003Dl-O3 for help-gnu-emacs@gnu.org; Thu, 29 Oct 2020 12:16:07 -0400 Original-Received: from aserp2120.oracle.com ([141.146.126.78]:58238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYAao-0003ry-4u for help-gnu-emacs@gnu.org; Thu, 29 Oct 2020 12:16:06 -0400 Original-Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 09TG98Us156877; Thu, 29 Oct 2020 16:15:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=m/2xxnmaFWIeKoogBIfPXuuB4RScyyebFEK+ANaGyZM=; b=iR/XvGTngVi2m48REAG/MxzoV62JlgOeYImPLGf7YF2YP3scIWbcmBQDbt0kzIYHduCM IRPNxzzIDsSmVfUtN+Ui1JT8OXCiqEF/RsyJPB6zcAMhwC01u0fSayKHEpOsFYssHExw PTlreeWrp04xs8A7qZftQqMFLNcGeD1C2x6wwVDnilG2xtPxZ7Kp39uJRGo9Vk8eAxUQ FTTEKUvqYgHVYyUU7YPgAF7KS3B0wIq9WTyC9Rf0CeY/fHVEopKMbauHq7ho95ZzZ9nQ sb6QeRgkPbYM2rYQ61N1McM/rB0J4IOvv/gqrirZg0V/nfALUQC4407oA6WymckpCCRy 5g== Original-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 34cc7m5s4u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 29 Oct 2020 16:15:57 +0000 Original-Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 09TGAXbi175195; Thu, 29 Oct 2020 16:13:57 GMT Original-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 34cwupy29d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 29 Oct 2020 16:13:56 +0000 Original-Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 09TGDuoi010986; Thu, 29 Oct 2020 16:13:56 GMT In-Reply-To: <87k0v9fhbi.fsf@rub.de> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.5056.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9788 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2010290113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9788 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 adultscore=0 malwarescore=0 spamscore=0 clxscore=1015 mlxscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2010290113 Received-SPF: pass client-ip=141.146.126.78; envelope-from=drew.adams@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/29 12:16:00 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:124796 Archived-At: > cl-count? seq-count? seq-reduce? KISS! >=20 > (defun count-char-in-string (char str) > "Return number of occurrences of character CHAR in string STR." > (let ((count 0)) > (dotimes (i (length str) count) > (when (eq char (aref str i)) > =09(setq count (1+ count)))))) +1. Or just (cl-incf count) at the end, if you're loading `cl-lib.el' anyway, for other reasons.