unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Mikael Djurfeldt" <mikael@djurfeldt.com>
To: "oriana paro" <orianaparo@libero.it>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: infixorder
Date: Tue, 30 Jan 2007 15:43:31 +0100	[thread overview]
Message-ID: <66e540fe0701300643k79abf83cpbe4386a6462dc552@mail.gmail.com> (raw)
In-Reply-To: <JCOOLO$091408A5CF8051856D1E62DB6556402C@libero.it>

2007/1/30, oriana paro <orianaparo@libero.it>:
> Hi. I'm learning scheme (Guile) and I have some problem with the infix order walk in a tree...
> I want to write a function infixwalk that walks though a tree in infix order (left tree - node - righ tree) so that the call
> (equal?
>    (infixwalk
>        '( (a) b ( (c) d (e) ) )
>     )
>     '(b a d c e)
> )
> returns #t.
> Anyone can help me?? Thanks in advance.

This type of question usually turns up when a student wants help with
homework and is therefore usually dismissed---in any case you wouldn't
learn anything if you got the complete code.  But I guess a couple of
hints doesn't do any harm:

Try recursion:

1. If you assume that "infixwalk" already exists and works, is there
some way you can break down a complex version of the problem (for
example the full tree above) so that you can write the solution in
terms of one or more calls to "infixwalk" applied to simpler versions
of the problem?

2. Is there some way you can distinguish such a complex version of the
problem (where you need to use infixwalk to compute the solution) from
a version of the problem which is so simple that you can return the
result directly?

3. Write infixwalk as a conditional which chooses between the simple
and complex version.  You need the simple case so that your recursion
on the complex version terminates cleanly with a simple case.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


  reply	other threads:[~2007-01-30 14:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-30 13:39 infixorder oriana paro
2007-01-30 14:43 ` Mikael Djurfeldt [this message]
2007-01-30 15:29   ` infixorder Ian Grant
2007-01-30 15:46 ` infixorder Jon Wilson
2007-02-01  5:39 ` infixorder -- more hints for Oriana, and a slightly OT but interesting consideration Luca Saiu
2007-02-05  6:41   ` Jon Wilson

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=66e540fe0701300643k79abf83cpbe4386a6462dc552@mail.gmail.com \
    --to=mikael@djurfeldt.com \
    --cc=guile-user@gnu.org \
    --cc=orianaparo@libero.it \
    /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).