From: Pal-Kristian Engstad <engstad@naughtydog.com>
To: Oleg <oleg_inconnu@myrealbox.com>,
Pal-Kristian Engstad <engstad@slave-dog.naughtydog.com>,
caml-list@inria.fr
Subject: Re: [Caml-list] Why is (@) written in O'Caml?
Date: Thu, 5 Dec 2002 13:55:41 -0800 [thread overview]
Message-ID: <200212051355.41175.engstad@naughtydog.com> (raw)
In-Reply-To: <200212051624.37333.oleg_inconnu@myrealbox.com>
On Thursday 05 December 2002 01:24 pm, Oleg wrote:
> On Thursday 05 December 2002 04:16 pm, Pal-Kristian Engstad wrote:
> > But, that is _exactly_ what the function above does!
>
> It's not about *what* it does, but *how* (@) does it. (@) is recursive and
> not tail-recursive.
Okey - I see where you're coming from. Since we know that we're creating a new
copy of a list, we know there will be references to it elsewhere, hence we
may see it as a mutable list and do something like:
struct cell { value *hd; cell* tl; };
newlist = nil;
prev = nil;
list = l1;
/* copy l1 */
while (list != nil) {
pnew = alloc(list); /* Allocate new cell. */
if (!newlist) newlist = pnew; /* Mark first cell. */
pnew->hd = list->hd; /* Copy data at cell. */
pnew->tl = nil; /* Init to nil. */
if (prev) prev->tl = pnew; /* Link previous cell to this. */
prev = pnew; /* Update previous. */
list = list->tl; /* Get next l1 cell. */
}
if (prev) {
prev->tl = l2;
return newlist;
}
else {
return l2;
}
Is that what you mean?
PKE.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2002-12-05 21:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-05 20:47 Oleg
2002-12-05 21:16 ` Pal-Kristian Engstad
2002-12-05 21:24 ` Oleg
2002-12-05 21:55 ` Pal-Kristian Engstad [this message]
2002-12-05 23:27 ` Oleg
2002-12-05 23:53 ` Pal-Kristian Engstad
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=200212051355.41175.engstad@naughtydog.com \
--to=engstad@naughtydog.com \
--cc=caml-list@inria.fr \
--cc=engstad@slave-dog.naughtydog.com \
--cc=oleg_inconnu@myrealbox.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