From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Aleix_Conchillo_Flaqu=C3=A9?= Newsgroups: gmane.lisp.guile.user Subject: vector-last / vector-ref with negative indices? Date: Sat, 19 Dec 2020 22:58:40 -0800 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30300"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Dec 20 07:59:10 2020 Return-path: Envelope-to: guile-user@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 1kqsgQ-0007mQ-2u for guile-user@m.gmane-mx.org; Sun, 20 Dec 2020 07:59:10 +0100 Original-Received: from localhost ([::1]:55330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqsgP-0000HS-64 for guile-user@m.gmane-mx.org; Sun, 20 Dec 2020 01:59:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqsgF-0000HL-Tl for guile-user@gnu.org; Sun, 20 Dec 2020 01:59:00 -0500 Original-Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:37125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kqsgA-0007VR-AF for guile-user@gnu.org; Sun, 20 Dec 2020 01:58:59 -0500 Original-Received: by mail-pl1-x634.google.com with SMTP id be12so3929993plb.4 for ; Sat, 19 Dec 2020 22:58:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=PIM0+vWImd01VPa87il8JiAG5U7WoCG3OP8lViiKKVM=; b=N8Ky5wSgxEL515xJnRqlb38oia3xf7OYWSNAUggmKjjbBtv35OeKLsrzaYJFcWxspJ jxEo1CRL8V/ESexRJh4N7Vw3fMaESrZZDDU4B78bbzC3jGFVNcXK4QvMhaARRnRYWwFS 02BeqUo0GxFnqdyQcRu8xqodYmIZ37tBmkAAIpuq0kkMPt9TKaNfnPFabD53iRRpbGXc tJ49oaw6Ph7pzutL6VAGIKhFzFqsKjfYuKkvX49gXfccQYKBQaynypxAB76MSA4Slaph gkCMduhxRUgo9T70eoJMR7iCbQctHcmM/ViDgbZv/Q5ejOhZFUGO3aFOBJAvU6LA+ktH 5aSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=PIM0+vWImd01VPa87il8JiAG5U7WoCG3OP8lViiKKVM=; b=BsQzrGlcoYTRFNL6+khbJGktDSUz0eMvhnV4W0dSjAuInph54z38z4BkT5xeCf33Nd 6vZX3S/ZBm1xbCjwinNLv9HI8yaaDbfK0YXO4LULHlsVpKMY9xZu5ThccJlh8Pfj0YqH NBlZzrOe53NxXQRrvtUBv3ov+b4YGYG8GYHen79iaabFt4QBmjBLJREwTFsBkr4C+AjS ArCHSDOjxmwdVdPQj0rgPaNU+iD2LTVaJga3EB++rn0ydhq9/WysuBmcqqi/44a29EjE hSWxlWALvAC7ozSn8P+QHxageM3xlMuUD4eAgyK3Env5+NIsQVG4fpju2H9VYMU9Yw0w SPWw== X-Gm-Message-State: AOAM533CDeyQKSWno9fRPJ5LnaZvbf7I7S4CJ9/UzYfbDNwBl3afla7V BOZNvhmgz5kZzp6Q8Ah8YezHYIGrxl9akHd3HyuFC6FHcQE= X-Google-Smtp-Source: ABdhPJzZyIuTZKsVzc/Kr/gMZ9R8u3bNv69lXedfOSNqx1Qm8tQqkyzGsg+OgDH3DwdhKXwQn/F0uEA/RXkVkocKFbA= X-Received: by 2002:a17:902:694c:b029:da:afba:beab with SMTP id k12-20020a170902694cb02900daafbabeabmr11489569plt.32.1608447531616; Sat, 19 Dec 2020 22:58:51 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=aconchillo@gmail.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17090 Archived-At: Hi, This month I'm trying to go through Advent Of Code one more year (previous years I didn't get too far) and I've been finding myself writing the same patterns multiple times that could be avoided by just having a helper function. One of them is getting the last element of a vector. It is a quite common operation when solving these types of problems. For example Python as you might know uses negative indices. I have looked around and haven't seen it (unless I completely missed it which would be shameful) but wouldn't it be good to have this built-in by default? Instead of having to write: (vector-ref v (- (vector-length v) 1)) you would write: (vector-last v) or even better (vector-ref v -1). Interestingly Racket doesn't offer those functions either as far as I can tell. Basic use case? Get the maximum element of a sorted vector which would be done in constant time. I'm trying to solve the problems idiomatically, to the best of my limited knowledge, with Scheme. It is possible that the times I'm using vectors I should think about it differently and not use them, but I'm not 100% sure. What am I missing? Thank you in advance, Aleix