From: zimoun <zimon.toutoune@gmail.com>
To: jgart <jgart@dismail.de>, Guix Help <help-guix@gnu.org>
Subject: Re: a vector of colors
Date: Mon, 05 Sep 2022 18:37:01 +0200 [thread overview]
Message-ID: <87o7vtrd5e.fsf@gmail.com> (raw)
In-Reply-To: <20220809205815.GB29308@gac>
Hi,
A bit late. :-)
On mar., 09 août 2022 at 20:58, jgart <jgart@dismail.de> wrote:
> Why was this defined as a vector instead of a list?
>
> (define %colors
> ;; See colortbl.h in Graphviz.
> #("red" "magenta" "blue" "cyan3" "darkseagreen"
> "peachpuff4" "darkviolet" "dimgrey" "darkgoldenrod"))
and you mean replace ’pop-color’ by,
--8<---------------cut here---------------start------------->8---
(define (pop-color hint)
"Return a Graphviz color based on HINT, an arbitrary object."
(let ((index (hash hint (length %colors))))
(list-ref %colors index)))
--8<---------------cut here---------------end--------------->8---
but I guess ’list-ref’ is slower than ’vector-ref’; as specified by the
documentation:
Vectors are sequences of Scheme objects. Unlike lists, the
length of a vector, once the vector is created, cannot be
changed. The advantage of vectors over lists is that the time
required to access one element of a vector given its position
(synonymous with index), a zero-origin number, is constant,
whereas lists have an access time linear to the position of the
accessed element in the list.
However, the difference is probably not visible here.
Cheers,
simon
prev parent reply other threads:[~2022-09-05 17:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-10 1:58 a vector of colors jgart
2022-09-05 16:37 ` zimoun [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o7vtrd5e.fsf@gmail.com \
--to=zimon.toutoune@gmail.com \
--cc=help-guix@gnu.org \
--cc=jgart@dismail.de \
/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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.