* bug#66057: (ice-9 match) allows invalid usages of ... or ..1 @ 2023-09-17 18:17 Maxim Cournoyer 2023-09-17 18:36 ` Jean Abou Samra 0 siblings, 1 reply; 4+ messages in thread From: Maxim Cournoyer @ 2023-09-17 18:17 UTC (permalink / raw) To: 66057 Hi, After attempting the following: --8<---------------cut here---------------start------------->8--- (match (string-split "./Bootloaders/Printer/Documentation/html" #\/) (("." path ..1 "Documentation" "html") (pk 'path path))) => ;;; (path "Bootloaders") Expected (and works with '...'): ;;; (path "Bootloaders" "Printer") --8<---------------cut here---------------end--------------->8--- and asking about it in #scheme or #guile, it seems the '..1' and '...' patterns *must* be used strictly to match at the end of lists, but this isn't explicitly mentioned in the manual, and even works for ... but not for ..1, which is inconsistent/econfusing. It was suggested by Zipheir in #scheme that Guile should return a syntax error when ..1 or ... are used somewhere else than at the end of a list. It seems a good suggestion. -- Thanks, Maxim ^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#66057: (ice-9 match) allows invalid usages of ... or ..1 2023-09-17 18:17 bug#66057: (ice-9 match) allows invalid usages of ... or ..1 Maxim Cournoyer @ 2023-09-17 18:36 ` Jean Abou Samra 2023-09-18 0:59 ` Maxim Cournoyer 0 siblings, 1 reply; 4+ messages in thread From: Jean Abou Samra @ 2023-09-17 18:36 UTC (permalink / raw) To: Maxim Cournoyer, 66057 [-- Attachment #1.1: Type: text/plain, Size: 1300 bytes --] Le dimanche 17 septembre 2023 à 14:17 -0400, Maxim Cournoyer a écrit : > Hi, > > After attempting the following: > > --8<---------------cut here---------------start------------->8--- > (match (string-split "./Bootloaders/Printer/Documentation/html" #\/) > (("." path ..1 "Documentation" "html") For a start, where does that "..1" syntax come from? To my knowledge, no such syntax is supported by Guile's pattern matcher, which AFAIK is the one described in SRFI-204. https://srfi.schemers.org/srfi-204/srfi-204.html So your example is just binding the string "Printer" to the variable "..1": since "..1" doesn't have any special meaning, it's just a pattern variable. > (pk 'path path))) > > => ;;; (path "Bootloaders") > > Expected (and works with '...'): > ;;; (path "Bootloaders" "Printer") > --8<---------------cut here---------------end--------------->8--- > > and asking about it in #scheme or #guile, it seems the '..1' and '...' > patterns *must* be used strictly to match at the end of lists, ?? This is not what SRFI 204 says, and it's not consistent with syntax-rules and syntax-case patterns either. [-- Attachment #1.2: Type: text/html, Size: 2532 bytes --] [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#66057: (ice-9 match) allows invalid usages of ... or ..1 2023-09-17 18:36 ` Jean Abou Samra @ 2023-09-18 0:59 ` Maxim Cournoyer 2023-09-18 9:28 ` Jean Abou Samra 0 siblings, 1 reply; 4+ messages in thread From: Maxim Cournoyer @ 2023-09-18 0:59 UTC (permalink / raw) To: Jean Abou Samra; +Cc: 66057 Hello, Jean Abou Samra <jean@abou-samra.fr> writes: > Le dimanche 17 septembre 2023 à 14:17 -0400, Maxim Cournoyer a écrit : >> Hi, >> >> After attempting the following: >> >> --8<---------------cut here---------------start------------->8--- >> (match (string-split "./Bootloaders/Printer/Documentation/html" #\/) >> (("." path ..1 "Documentation" "html") > > > For a start, where does that "..1" syntax come from? To my knowledge, no such > syntax is supported by Guile's pattern matcher, which AFAIK is the one described > in SRFI-204. > > https://srfi.schemers.org/srfi-204/srfi-204.html It's mentioned in the Guile Reference manual; see info "(guile) Pattern Matching": --8<---------------cut here---------------start------------->8--- -- Scheme Syntax: match exp clause1 clause2 ... Match object EXP against the patterns in CLAUSE1 CLAUSE2 ... in the order in which they appear. Return the value produced by the first matching clause. If no clause matches, throw an exception with key ‘match-error’. Each clause has the form ‘(pattern body1 body2 ...)’. Each PATTERN must follow the syntax described below. Each body is an arbitrary Scheme expression, possibly referring to pattern variables of PATTERN. The syntax and interpretation of patterns is as follows: patterns: matches: pat ::= identifier anything, and binds identifier | _ anything | () the empty list | #t #t | #f #f | string a string | number a number | character a character | 'sexp an s-expression | 'symbol a symbol (special case of s-expr) | (pat_1 ... pat_n) list of n elements | (pat_1 ... pat_n . pat_{n+1}) list of n or more | (pat_1 ... pat_n pat_n+1 ooo) list of n or more, each element of remainder must match pat_n+1 | #(pat_1 ... pat_n) vector of n elements | #(pat_1 ... pat_n pat_n+1 ooo) vector of n or more, each element of remainder must match pat_n+1 | #&pat box | ($ record-name pat_1 ... pat_n) a record | (= field pat) a ``field'' of an object | (and pat_1 ... pat_n) if all of pat_1 thru pat_n match | (or pat_1 ... pat_n) if any of pat_1 thru pat_n match | (not pat_1 ... pat_n) if all pat_1 thru pat_n don't match | (? predicate pat_1 ... pat_n) if predicate true and all of pat_1 thru pat_n match | (set! identifier) anything, and binds setter | (get! identifier) anything, and binds getter | `qp a quasi-pattern | (identifier *** pat) matches pat in a tree and binds identifier to the path leading to the object that matches pat ooo ::= ... zero or more | ___ zero or more | ..1 1 or more quasi-patterns: matches: qp ::= () the empty list | #t #t | #f #f | string a string | number a number | character a character | identifier a symbol | (qp_1 ... qp_n) list of n elements | (qp_1 ... qp_n . qp_{n+1}) list of n or more | (qp_1 ... qp_n qp_n+1 ooo) list of n or more, each element of remainder must match qp_n+1 | #(qp_1 ... qp_n) vector of n elements | #(qp_1 ... qp_n qp_n+1 ooo) vector of n or more, each element of remainder must match qp_n+1 | #&qp box | ,pat a pattern | ,@pat a pattern The names ‘quote’, ‘quasiquote’, ‘unquote’, ‘unquote-splicing’, ‘?’, ‘_’, ‘$’, ‘and’, ‘or’, ‘not’, ‘set!’, ‘get!’, ‘...’, and ‘___’ cannot be used as pattern variables. --8<---------------cut here---------------end--------------->8--- > > So your example is just binding the string "Printer" to the variable "..1": > since "..1" doesn't have any special meaning, it's just a pattern variable. Unless I misread the doc, it should '..1' is a special case '...', which means "one or more" instead of "zero or more". > >> (pk 'path path))) >> >> => ;;; (path "Bootloaders") >> >> Expected (and works with '...'): >> ;;; (path "Bootloaders" "Printer") >> --8<---------------cut here---------------end--------------->8--- >> >> and asking about it in #scheme or #guile, it seems the '..1' and '...' >> patterns *must* be used strictly to match at the end of lists, > > > ?? > > This is not what SRFI 204 says, and it's not consistent with syntax-rules and > syntax-case patterns either. OK! I hope it's just a bug in Guile that can be addressed then. Thanks for tipping in. -- Maxim ^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#66057: (ice-9 match) allows invalid usages of ... or ..1 2023-09-18 0:59 ` Maxim Cournoyer @ 2023-09-18 9:28 ` Jean Abou Samra 0 siblings, 0 replies; 4+ messages in thread From: Jean Abou Samra @ 2023-09-18 9:28 UTC (permalink / raw) To: Maxim Cournoyer; +Cc: 66057 [-- Attachment #1.1: Type: text/plain, Size: 783 bytes --] Le dimanche 17 septembre 2023 à 20:59 -0400, Maxim Cournoyer a écrit : > It's mentioned in the Guile Reference manual; see info "(guile) Pattern > Matching": > > > > So your example is just binding the string "Printer" to the variable "..1": > > since "..1" doesn't have any special meaning, it's just a pattern variable. > > Unless I misread the doc, it should '..1' is a special case '...', which > means "one or more" instead of "zero or more". OK, my bad, I didn't know that. You're right that "..1" is mistreated here, it should be compiled as "one or more repetitions" but instead gets compiled as a pattern variable. That's a bug, indeed — I believe the expected behavior is that "..1" behaves like "...", namely being allowed in the middle of a list. [-- Attachment #1.2: Type: text/html, Size: 1429 bytes --] [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-18 9:28 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-09-17 18:17 bug#66057: (ice-9 match) allows invalid usages of ... or ..1 Maxim Cournoyer 2023-09-17 18:36 ` Jean Abou Samra 2023-09-18 0:59 ` Maxim Cournoyer 2023-09-18 9:28 ` Jean Abou Samra
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).