From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: Program problem Date: Wed, 29 Nov 2023 17:37:31 +0100 Message-ID: <87jzq0tt10.fsf@rub.de> References: <446414867.4957940.1701217006858.ref@mail.yahoo.com> <446414867.4957940.1701217006858@mail.yahoo.com> <87o7fctttd.fsf@rub.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13938"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Lewis Creary via Users list for the GNU Emacs text editor , Lewis Creary To: Stephen Berman Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 29 17:38:18 2023 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 1r8NZk-0003DX-Ss for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Nov 2023 17:38:12 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8NZE-0005EC-V5; Wed, 29 Nov 2023 11:37:40 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8NZD-0005E0-PS for help-gnu-emacs@gnu.org; Wed, 29 Nov 2023 11:37:39 -0500 Original-Received: from mout.gmx.net ([212.227.17.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8NZB-0003wR-FZ for help-gnu-emacs@gnu.org; Wed, 29 Nov 2023 11:37:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1701275852; x=1701880652; i=stephen.berman@gmx.net; bh=BscedxMod7/i5O77uhdD/97qBeNen3J8aMpsC8bmz9g=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References: Date; b=smXdoRQvz7pOes0E6jGRfmwf3OPYUeUFw7utcoFDbBZlQjA6Er62MgbN2wHC4+X3 KNSimWHaQ83s9lgp0sECtExORRuk2c/4B4LHv+n7adBQcBAZJ3us34hUw4JEHCxZJ yhMxeWV5Qx3pguvGSRNqEz4QdT/mH6fuK/Gc23jmeywx/kBIDdxtcqAQE0br6zlYN Th9araVKIon7oTRywC47aVmEH1Db2TJNRaSV1CkK4VvRVt/unQztuDJsTT6+Q+Kr2 K9zxRvkqFfgyd2xt4UUX+l+zYV1QfiKLkwV70mtEwbTgsc4OaR7dhWM9X6LeBvRlG jyfV0I8BuQVR4dOErA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs2 ([88.130.50.245]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MYNNy-1qlkMA1keI-00VQRj; Wed, 29 Nov 2023 17:37:32 +0100 In-Reply-To: <87o7fctttd.fsf@rub.de> (Stephen Berman's message of "Wed, 29 Nov 2023 17:20:30 +0100") X-Provags-ID: V03:K1:9RLxjul/z4b4DJNX0m4AdPtuYYVhVJweIspn6/r2tkZrJSQ17Pp xyvoMsxdzLEyyFx+qs4fVMnYBTS4JrE4StQHYmR4AQlqeFB5WphgX1rHREPTkiw2r77PRL6 VNXjYJqJujMCW7rSC29UBk4KpJeUutbU+5U9/ZXsoL4jGKQUgcnPjMP0DgpND6QkFY8cYJf cXsrA+vqNd3X9HPZrgOYw== UI-OutboundReport: notjunk:1;M01:P0:J4MPKL6nGW0=;7iMAWyN+y1IohilLsbaOZ4xFlu1 swS49zHjTo6WiepjrzDkuqdII4sWYNbnGBNGprB/emq3v1/Q6zN+bBnIsjt+LcflS1CyTUD1K +L2+QCM5qSWwGqlrgxs6zQaG2Ynp9utvMzqBYvPrBXetGnNaWeZWmyPnitUj53V/A/Zk3uQiH EBA8TvufSrR8WeLHrxPX9qbxiBmvOcZhHqPkwU/ndUDVopdxkA90v/woXKl/lZizc3P9JIO43 TjS9Qo1fHYaRHen0wsWZWZdv4uZTwaR519I3GTwIgRjYhLmA0uvMcC6M5RVOj53fbbVHP2RtQ 9/1jgeiczL3z8/Wb+PpYazRk/fNhVV3nbmWR3OGElhq3BxbUU1z18RqFl7x7cYqwPQJCEkBtA Of97WhMfaTTgS1dNLT2IRd2oDLSqSqrwoYpwgOQHGG/Mn2MqOObIkpKh+cijxfBV3Iy74t1ZP jyrDWFRu83LsOWtK+v+7IQW5SDLwAOkOOa75sXIPtJxEuE24idiqsWuPLCfd0/02q5cjBErbf RksgH4jZ9ArhrgucSxMXWufs0UUr7SUgKgZ++msdVc0rKRQVnuw0e1DoD9AigJRu9Z6hG5w6Z EtgDRv4qn/CHwjnIKR9wzs3FvUdugncHV9qD05ToAXyMtJK1vP7zpTMe7bQRTp93uoRmJ5RFY l0YQbdqYzUMKPm98LvSOSKoY/sSno5AU3piplK3CPN7xCXTMzi8Qzh/Lsdx9cjLC/mRv4fxHm OAAYdq11LlYfSJUbhE3uxXGG0ZQNqzX4yhOAsI/NGRFLy2XPDYANy7KqlUG3pp2SbOtgEhnB Received-SPF: pass client-ip=212.227.17.20; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 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-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:145583 Archived-At: On Wed, 29 Nov 2023 17:20:30 +0100 Stephen Berman wrote: [...] > As food for thought and for you to experiment with, here is an > alternative implementation that uses some higher-level elisp functions > to avoid lower-level functions like setcar and nthcdr, and hence shorten > the code. Also, it restructures the data into a form that seems to me > better suited to what you want, given your description. The doc string > tries to explain that: I meant to add here that the last sentence of the doc string suggests how to check for bad input, but I omitted adding such code for the sake of brevity. Steve Berman > (defun fill-rows (dim rows) > "Fill a square matrix of dimensions DIM with values from ROWS. > DIM is an integer specifying the number of rows and columns in > the matrix. ROWS is an alist with elements (ROW . ELEMENTS), > where ROW specifies the (1-based) row number of the matrix and > ELEMENTS is a string whose characters are numerals specifying the > contents of the cells of ROW (in which each numeral in ELEMENTS > has been converted to the corresponding integer). Each cell of > the rows not specified by ROWS is filled with 0. Since the > result should be a square matrix, the lengths of ROWS and > ELEMENTS must equal DIM and each ROW must be an integer between 1 > and DIM (inclusive)." > (let (matrix) > (dotimes (i dim) > (let* ((rpair (assq (1+ i) rows)) > (row (if rpair > (mapcar #'string-to-number > (mapcar #'string > (string-to-list (cdr rpair)))) > (make-list dim 0)))) > (setq matrix (append matrix (list row))))) > matrix)) > > Here's the invocation with your test data: > > (fill-rows 9 '((1 . "123456789") (3 . "987654321") (5 . "123498765"))) > > I hope that was helpful. > > Steve Berman