Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Problem with this code
Hi,

I am having a little problem with implementing a feature that is called
from this predicate:

I need to traverse and print the leaves of a binary tree given the
database in the top predicate:

a menu system calls cmd('L', DB, DBnew)

%cmd(+CMD, +DB, -DB)

cmd(0'L, DB, DB) :-
traverse(DB).

%---------
I know that this doesn't work because the menu that calls cmd() will
fail because i do not return the new DB.

How would I modify the above (or the traverse) to enable the cmd() to
evaluate to true?


Traverse is as follows, this works on its own.
traverse(leaf(X)) :-
putl(X),    %write to output
nl.         %new line

traverse(tree(_, left, right)) :-
traverse(left),
traverse(right).

Thanks in advance


Report this thread to moderator Post Follow-up to this message
Old Post
gorans@students.cs.mu.oz.au
04-08-05 01:58 PM


Re: Problem with this code
gorans@students.cs.mu.oz.au wrote:
> Hi,
>
> ...
>
> I am having a little problem with implementing a feature that is
called
> from this predicate:
> traverse(tree(_, left, right)) :-
>    traverse(left),
>    traverse(right).
>
> ...


Do you mean "Left" instead of "left" and "Right" instead of "right"?

Kind regards.


Report this thread to moderator Post Follow-up to this message
Old Post
tmp123
04-08-05 01:58 PM


Re: Problem with this code
yes,
the problem wasn't with the traverse predicate. I just quickly copied
it so treat it like pseudo code.

The problem lies with the relation between cmd(L, DB, DB) and the call
to traverse(DB), traverse of DB returns true if the DB is valid.


Report this thread to moderator Post Follow-up to this message
Old Post
gorans@students.cs.mu.oz.au
04-08-05 01:58 PM


Re: Problem with this code
gorans@students.cs.mu.oz.au wrote:
> Hi,
>
> I am having a little problem with implementing a feature that is
called
> from this predicate:
>
> I need to traverse and print the leaves of a binary tree given the
> database in the top predicate:
>
> a menu system calls cmd('L', DB, DBnew)
>
> %cmd(+CMD, +DB, -DB)
>
> cmd(0'L, DB, DB) :-
>    traverse(DB).
>
> %---------
> I know that this doesn't work because the menu that calls cmd() will
> fail because i do not return the new DB.
>
> How would I modify the above (or the traverse) to enable the cmd() to
> evaluate to true?
>
>
> Traverse is as follows, this works on its own.
> traverse(leaf(X)) :-
>    putl(X),    %write to output
>    nl.         %new line
>
> traverse(tree(_, left, right)) :-
>    traverse(left),
>    traverse(right).
>
> Thanks in advance



One trick I use which may be applicable is to define a no_op predicate
used with a disjunction:


some_predicate_that you want_to always succeed(X) :-
( some_predicate_which_can_fail(X) ; no_op ).

no_op.

HTH,

-mg


Report this thread to moderator Post Follow-up to this message
Old Post
michael.goodrich@gmail.com
04-14-05 01:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Prolog archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:57 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.