From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.user Subject: Python slices in Scheme Date: Sun, 18 Jun 2023 18:58:54 +0200 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="32388"; 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 Jun 18 18:59:45 2023 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 1qAvkf-0008HA-16 for guile-user@m.gmane-mx.org; Sun, 18 Jun 2023 18:59:45 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qAvk8-0007Sv-Iy; Sun, 18 Jun 2023 12:59:12 -0400 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 1qAvk6-0007SW-NG for guile-user@gnu.org; Sun, 18 Jun 2023 12:59:10 -0400 Original-Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qAvk4-0001KW-JB for guile-user@gnu.org; Sun, 18 Jun 2023 12:59:10 -0400 Original-Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-51a270e4d57so3857918a12.3 for ; Sun, 18 Jun 2023 09:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687107546; x=1689699546; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=8LiewfhlioG25md74kVoUnzKg6JaD+V5+PD3B22dQ9Q=; b=IhlMpoV+GPVAuALmL68GrJrKhtH3Nm0HXG0HUXN3gaD+H93hMm9L/mieRdkNwWwmh7 6LXnr+JWen01GKvSGv6+IY4EAPCZ6klYxjq/uD6aCqymqQxod6LHM4mQ+DcfGCHtqjeJ tId2JXjnf+K605DOPDHDv+s20pd7beNAeV768Hrv6XjUa/ec44NLdVApzEzH4nvb4rdY 1+wBDMtW/ZFNB7GTDtYG4MzmNQ1Q8QdYZMwj04Gw2kgyXLhpntZnMhfggKtPmdzpKAXU iKARa8W3YSv7jVx230Xde29L7vKyaj2KygCFhJEcnTXsmkRITp1zMXDqYylr16s56W+4 vw9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687107546; x=1689699546; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8LiewfhlioG25md74kVoUnzKg6JaD+V5+PD3B22dQ9Q=; b=A9OCzkMxpKug4M1vrcsWH3QXZwJVIeDPEyS+b7URKx7Ejz/BP1dGPwQbMyVaodBLG0 Ps0gkJBfsh5IdYNJdNi6zEEhBJRPB7J/Q0jQ9JH9GvQJfwesXjm9Pkr1pwWVIMgk1629 6Ph78A9CCjQgr9rjVnX0ABFEh/6SahE8DgAMP72eXZpzFJHDnveIKOLhy3hlmsrPj8fr WJxbF2VCreyeC+K0sOXRSrva7+5EG9No40Fn6PgTiraOyN3hU7G2ic2t87+L4x/Ji7Gw OmGXPH6WSf/V5MX3xhbKzDMq6UaYLM/tNfnt+Kf93TdSyXlDTjA+c/bwCHnkChp8+HeH ubHg== X-Gm-Message-State: AC+VfDxGMNtFnl63950aMEscEX3wtAY2StI9isL3MUWpR9Ix1Q9Lfpgf 5jrUbo0J2pJAS5+1WrqEe3XAan16TdpOVrsJKC9gs6hDBGY= X-Google-Smtp-Source: ACHHUZ5hx7pb6JJo4y6nocPKALsB83F1jSGtbDCeFtrRl5pqN5wxaqE513cjIHdf55wbpe/xrsyY8lMN7B/7qxlpeeQ= X-Received: by 2002:aa7:c2c9:0:b0:51a:5ac3:4df3 with SMTP id m9-20020aa7c2c9000000b0051a5ac34df3mr501825edp.5.1687107545963; Sun, 18 Jun 2023 09:59:05 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=damien.mattei@gmail.com; helo=mail-ed1-x535.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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 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-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19046 Archived-At: hello, i'm porting the Python slicing ( https://docs.python.org/2/reference/expressions.html#slicings ) to Scheme Guile and Racket. examples in Scheme+ : {#(1 2 3 4 5 6 7)[2 / 5]} #(3 4 5) i'm using / instead of : because : is already used by the SRFI 42 Eager Comprehension below are my testing examples: ;;; compiled /Users/mattei/.cache/guile/ccache/3.0-LE-8-4.6/usr/local/share/guile/site/3.0/Scheme+.scm.go scheme@(guile-user)> {#(1 2 3 4 5 6 7 8)[/ / 3]} $1 = #(1 4 7) scheme@(guile-user)> {#(1 2 3 4 5 6 7 8)[/ / -2]} $2 = #(8 6 4 2) scheme@(guile-user)> {"elephant"[2 / 5]} $3 = "eph" scheme@(guile-user)> {"abcdefghijkl"[/ / -3]} $4 = "lifc" scheme@(guile-user)> {"123456789"[ / / -1]} $5 = "987654321" scheme@(guile-user)> {"abcdefghijkl"[/ / 2]} $6 = "acegik" scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[/ 7 / 2]} $7 = #(1 3 5 7) scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[/ 6 / -1]} $8 = #(6 5 4 3 2 1) scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[/ 6 / -2]} $9 = #(6 4 2) scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[/ -3 / -2]} $10 = #(6 4 2) scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[3 / / 2]} $11 = #(4 6 8) scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[3 / / -2]} $12 = #(4 2) scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[-3 / / 2]} $13 = #(7 9) scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[-3 / / -2]} $14 = #(7 5 3 1) scheme@(guile-user)> {"123456789"[/ -3 / -2]} $15 = "642" scheme@(guile-user)> {"abcdefghijklmno"[/ 7 / 2]} $16 = "aceg" scheme@(guile-user)> {"123456789"[/ -3 / -2]} $17 = "642" scheme@(guile-user)> {"abcdefghijklmno"[3 / / 2]} $18 = "dfhjln" scheme@(guile-user)> {"123456789"[3 / / 2]} $19 = "468" scheme@(guile-user)> {"123456789"[3 / / -2]} $20 = "42" scheme@(guile-user)> {"123456789"[-3 / / -2]} $21 = "7531" scheme@(guile-user)> {"123456789"[-3 / / 2]} $22 = "79" scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[2 / 5 / 1]} $23 = #(3 4 5) scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[5 / 2 / -1]} $24 = #(6 5 4) scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[2 / 5 / -1]} $25 = #() scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[-1 / 5 / -1]} $26 = #(9 8 7) scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[-0 / 5 / -1]} $27 = #() scheme@(guile-user)> {"0123456789"[5 / 2 / -1]} $28 = "543" scheme@(guile-user)> {"0123456789"[5 / / -1]} $29 = "543210" scheme@(guile-user)> {"0123456789"[5 / 0 / -1]} $30 = "54321" the syntax is derived from Python syntax: [1,2,3,4,5,6,7,8,9][-3::2] [7, 9] [1,2,3,4,5,6,7,8,9][-3::-2] [7, 5, 3, 1] [1,2,3,4,5,6,7,8,9][3::-2] [4, 2] "abcdefghijkl"[: : -3] 'lifc' [1,2,3,4,5,6,7,8,9][:5:-1] [9, 8, 7] [1,2,3,4,5,6,7,8,9][:5:1] [1, 2, 3, 4, 5] [1,2,3,4,5,6,7,8,9][0:5:-1] [] [1,2,3,4,5,6,7,8,9][-0:5:-1] [] [1,2,3,4,5,6,7,8,9][-1:5:-1] [9, 8, 7] [1,2,3,4,5,6,7,8,9][:5:-1] [9, 8, 7] [1,2,3,4,5,6,7,8,9][10:5:-1] [9, 8, 7] [1,2,3,4,5,6,7,8,9][2:5:-1] [] [1,2,3,4,5,6,7,8,9][5:2:-1] [6, 5, 4] [0,1,2,3,4,5,6,7,8,9][5:2:-1] [5, 4, 3] [0,1,2,3,4,5,6,7,8,9][5::-1] [5, 4, 3, 2, 1, 0] [0,1,2,3,4,5,6,7,8,9][5:0:-1] [5, 4, 3, 2, 1] for now it works in simple expressions,soon it will be implemented for expressions with LHS and RHS like {container1[2 / 5] <- container2[7 / 9]} for this reason all will be in the next version of Scheme+ https://github.com/damien-mattei/Scheme-PLUS-for-Guile with other features too. Damien