* Syntactic significance of dot @ 2014-09-22 18:12 Richard Shann 2014-09-22 18:32 ` Panicz Maciej Godek 2014-09-22 21:01 ` Marko Rauhamaa 0 siblings, 2 replies; 6+ messages in thread From: Richard Shann @ 2014-09-22 18:12 UTC (permalink / raw) To: guile-user I've come across some (working) scheme code whose meaning I can't unravel. The problem is there is a "." character whose significance eludes me. The guile reference doesn't index this character, and I can only find references to it in writing literal pairs. But I'm sure someone experienced would recognize what this could be (the dot occurs on the eleventh line): (define (ignatzek-format-exception root exception-markup bass-pitch lowercase-root?) (make-line-markup `( ,(name-root root lowercase-root?) ,exception-markup . ,(if (ly:pitch? bass-pitch) (list (ly:context-property context 'slashChordSeparator) (name-note bass-pitch #f)) '())))) Richard Shann ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Syntactic significance of dot 2014-09-22 18:12 Syntactic significance of dot Richard Shann @ 2014-09-22 18:32 ` Panicz Maciej Godek 2014-09-22 18:38 ` Panicz Maciej Godek 2014-09-22 18:43 ` Panicz Maciej Godek 2014-09-22 21:01 ` Marko Rauhamaa 1 sibling, 2 replies; 6+ messages in thread From: Panicz Maciej Godek @ 2014-09-22 18:32 UTC (permalink / raw) To: richard; +Cc: guile-user@gnu.org [-- Attachment #1: Type: text/plain, Size: 2257 bytes --] 2014-09-22 20:12 GMT+02:00 Richard Shann <richard@rshann.plus.com>: > I've come across some (working) scheme code whose meaning I can't > unravel. The problem is there is a "." character whose significance > eludes me. The guile reference doesn't index this character, and I can > only find references to it in writing literal pairs. > But I'm sure someone experienced would recognize what this could be (the > dot occurs on the eleventh line): > > (define (ignatzek-format-exception > root > exception-markup > bass-pitch > lowercase-root?) > > (make-line-markup > `( > ,(name-root root lowercase-root?) > ,exception-markup > . > ,(if (ly:pitch? bass-pitch) > (list (ly:context-property context 'slashChordSeparator) > (name-note bass-pitch #f)) > '())))) > > The dot is used in the default representation of improper lists, i.e. lists whose last element is not the '() object. The element appearing after the dot is the element pointed to by the last cdr in the sequence of cons pairs. Therefore, if you do (cons 'a 'b), you get (a . b) and if you nest it in other conses, e.g. (cons 'c (cons 'a 'b)), you get (a b . c) this is a syntactic equivalent of (a . (b . c)) (i.e. it makes no difference to the reader whether you write '(a b . c) or '(a . (b . c)). Likewise, instead of writing (+ 2 3), you can write (+ . (2 . (3 . ()))) and you'll still get 5. Try it out!) The limitation is that only one element can (and has to) appear after the period, and at least one element needs to appear before it. Otherwise you get a syntax voilation: '(1 2 . 3) ===> (1 2 3) '(1 2 . 3 4) ===> error '(. 3) ===> 3 (it seems to work in guile incidentally, but fails in racket) This behaviour is coherent in the context of quasiquote: (let ((a 1) (b 2) (c 3)) `(,a ,b . ,c)) yields (1 2 3) Note however, that if c was a list, it would be appended to the end: (let ((a 1)(b 2)(c '(3 4 5))) `(,a ,b . ,c)) ===> (1 2 3 4 5) Note also, that using unquote in the tail position is equivalent to using unquote-splicing with the last element, so the last example is equivalent with: (let ((a 1)(b 2)(c '(3 4 5)) `(,a ,b ,@c)) HTH M. [-- Attachment #2: Type: text/html, Size: 3256 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Syntactic significance of dot 2014-09-22 18:32 ` Panicz Maciej Godek @ 2014-09-22 18:38 ` Panicz Maciej Godek 2014-09-22 18:43 ` Panicz Maciej Godek 1 sibling, 0 replies; 6+ messages in thread From: Panicz Maciej Godek @ 2014-09-22 18:38 UTC (permalink / raw) To: richard; +Cc: guile-user@gnu.org [-- Attachment #1: Type: text/plain, Size: 481 bytes --] A little errata: > The limitation is that only one element can (and has to) appear after the > period, and at least one element needs to appear before it. Otherwise you > get a syntax voilation: > > '(1 2 . 3) > ===> (1 2 3) > Should be: ===> (1 2 . 3) Also, the dotted pair syntax and its eqivalent list syntax were both established by John McCarthy in his 1960 paper which introduced LISP to the world: http://www-formal.stanford.edu/jmc/recursive/recursive.html (section 3) [-- Attachment #2: Type: text/html, Size: 1037 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Syntactic significance of dot 2014-09-22 18:32 ` Panicz Maciej Godek 2014-09-22 18:38 ` Panicz Maciej Godek @ 2014-09-22 18:43 ` Panicz Maciej Godek 1 sibling, 0 replies; 6+ messages in thread From: Panicz Maciej Godek @ 2014-09-22 18:43 UTC (permalink / raw) To: richard; +Cc: guile-user@gnu.org [-- Attachment #1: Type: text/plain, Size: 208 bytes --] A little more errata :) [sorry for the confusion] > This behaviour is coherent in the context of quasiquote: > (let ((a 1) (b 2) (c 3)) > `(,a ,b . ,c)) > yields > (1 2 3) > Should be: yields (1 2 . 3) [-- Attachment #2: Type: text/html, Size: 646 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Syntactic significance of dot 2014-09-22 18:12 Syntactic significance of dot Richard Shann 2014-09-22 18:32 ` Panicz Maciej Godek @ 2014-09-22 21:01 ` Marko Rauhamaa 2014-09-23 8:49 ` Richard Shann 1 sibling, 1 reply; 6+ messages in thread From: Marko Rauhamaa @ 2014-09-22 21:01 UTC (permalink / raw) To: richard; +Cc: guile-user Richard Shann <richard@rshann.plus.com>: > I've come across some (working) scheme code whose meaning I can't > unravel. The problem is there is a "." character whose significance > eludes me. The guile reference doesn't index this character, and I can > only find references to it in writing literal pairs. That's what it's for and nothing else, including in your example. (a b . c) is equivalent to (a . (b . c)) Marko ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Syntactic significance of dot 2014-09-22 21:01 ` Marko Rauhamaa @ 2014-09-23 8:49 ` Richard Shann 0 siblings, 0 replies; 6+ messages in thread From: Richard Shann @ 2014-09-23 8:49 UTC (permalink / raw) To: Marko Rauhamaa, Panicz Maciej Godek; +Cc: guile-user On Tue, 2014-09-23 at 00:01 +0300, Marko Rauhamaa wrote: > Richard Shann <richard@rshann.plus.com>: > > > I've come across some (working) scheme code whose meaning I can't > > unravel. The problem is there is a "." character whose significance > > eludes me. The guile reference doesn't index this character, and I can > > only find references to it in writing literal pairs. > > That's what it's for and nothing else, including in your example. > > (a b . c) > > is equivalent to > > (a . (b . c)) Thank you for the replies to my email. I see that in the case I cited it is being used to construct a list - the last element is a list. This looks like a major omission in the guile documentation, under pairs http://www.gnu.org/software/guile/manual/html_node/Pairs.html#Pairs it says: "Pairs can literally get entered in source code or at the REPL, in the so-called dotted list syntax. This syntax consists of an opening parentheses, the first element of the pair, a dot, the second element and a closing parentheses." and under lists http://www.gnu.org/software/guile/manual/html_node/List-Syntax.html#List-Syntax "The syntax for lists is an opening parentheses, then all the elements of the list (separated by whitespace) and finally a closing parentheses." but the syntax for a list can also be ...then elements of the list (separated by whitespace) a dot followed by a list followed by a closing parenthesis" - this doesn't quite describe using this syntax for improper lists though. Anyway, I am thoroughly educated on this topic now :) Thank you both very much. Richard ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-09-23 8:49 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-09-22 18:12 Syntactic significance of dot Richard Shann 2014-09-22 18:32 ` Panicz Maciej Godek 2014-09-22 18:38 ` Panicz Maciej Godek 2014-09-22 18:43 ` Panicz Maciej Godek 2014-09-22 21:01 ` Marko Rauhamaa 2014-09-23 8:49 ` Richard Shann
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).