From: "Gábor Boskovits" <boskovits@gmail.com>
To: Freeman Gilmore <freeman.gilmore@gmail.com>
Cc: guile-devel@gnu.org
Subject: Re: alist and assq
Date: Fri, 20 Mar 2020 07:33:15 +0100 [thread overview]
Message-ID: <CAE4v=pg6HsUmQeKmNG4KhnzpDmbesCYGW17yuc_bxupfxw0ruA@mail.gmail.com> (raw)
In-Reply-To: <CAM=7=uQ17Vw1+XqWXdm8zq_UpdnMpqHrDM2iuExDAXjCO0QFiQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1978 bytes --]
Hello,
Freeman Gilmore <freeman.gilmore@gmail.com> ezt írta (időpont: 2020. márc.
20., Pén 1:45):
> Hi:
>
> I am not a programmer. Have some understanding of scheme. I have a
> question that I cannot find the answer to on the net. I joined this
> group to ask if someone would help me find the answer.
>
> I am looking for a manual or whatever that will explain in detail how an
> alist is stored in memory and how it works at this level. Also, how assq
> and assq-ref work, what is past to the alist at the same level. Also,
> the source code would be good.
>
Storing an atomic value is implementation dependent, but usually
implemented by a type tagged structure.
(You can think about this as a tuple of a type, buffer, where buffer is a
length,pointer there are several optimizations, but this is a possibility).
A pair is a structure holding two atomics with accessors to them.
(Possible implementation:
Type:pair, buffer is twice as long as an atomic, two atomics are stored
there. The accessors return the buffer buffer+sizeof(atomic) respectively.)
For lists there is a special value, the empty list. (This can be
implemented by setting the pointer to null)
A list is stored as a pair where the first member is a value, the current
first element, and the second is a list, the current tail.
An alist is a list of pairs.
Assq and assq-ref is just a find with a predicate on the first element of
the pair eq to the value passed in as key. Actually assq-ref is (compose
car assq).
What find does is that it recurses on the list. It is something like:
(define (find pred list)
(if (empty list)
#f
(if (pred (car list))
(car list)
(find pred (cdr list)))))
I hope it helps.
This is just a conceptual level, usually a modern implementation has a lot
of optimalizations on top of that.
An alist is a list of pairs.
> Thank you, ƒg
>
Best regards,
g_bor
>
[-- Attachment #2: Type: text/html, Size: 4493 bytes --]
next prev parent reply other threads:[~2020-03-20 6:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-20 0:34 alist and assq Freeman Gilmore
2020-03-20 6:33 ` Gábor Boskovits [this message]
2020-03-20 14:39 ` Freeman Gilmore
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='CAE4v=pg6HsUmQeKmNG4KhnzpDmbesCYGW17yuc_bxupfxw0ruA@mail.gmail.com' \
--to=boskovits@gmail.com \
--cc=freeman.gilmore@gmail.com \
--cc=guile-devel@gnu.org \
/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).