unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: richard@rshann.plus.com
Cc: "guile-user@gnu.org" <guile-user@gnu.org>
Subject: Re: Syntactic significance of dot
Date: Mon, 22 Sep 2014 20:32:06 +0200	[thread overview]
Message-ID: <CAMFYt2aD6FqnXx6wAhCFoXwTRW+_JDd1-1dHQTkPwNuOhJH3pw@mail.gmail.com> (raw)
In-Reply-To: <1411409556.3458.145.camel@DebianBox.loc>

[-- 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 --]

  reply	other threads:[~2014-09-22 18:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-22 18:12 Syntactic significance of dot Richard Shann
2014-09-22 18:32 ` Panicz Maciej Godek [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMFYt2aD6FqnXx6wAhCFoXwTRW+_JDd1-1dHQTkPwNuOhJH3pw@mail.gmail.com \
    --to=godek.maciek@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=richard@rshann.plus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).