From: Conrad Taylor
Subject: Lisp/Scheme programming question...???
Date:
Message-ID: <C58HDy.DAD@cs.uiuc.edu>
I have done the following in Pascal:
begin
write('Please enter an expression => ');
Tree := ReadExpression;
.
.
.
end;
Where ReadExpression returns type TreeType. In my program, I'm using input^
which looks ahead without taking the argument from the buffer. For example,
function ReadExpression { : TreeType};
var Expression : TreeType;
data: DataType;
begin
SkipBlanks;
data.kind := OperatorNode;
Expression := ReadTerm; {read first term}
while ((not eoln) and (input^ in ['+','-')) do
begin
case (input^) of {read in operator}
'+' : data.operator := plus;
'-' : data.operator := minus;
end;
get(input);
SkipBlanks;
Expression := NewTree(data, Expression, ReadTerm);
end;
SkipBlanks;
ReadExpression := Expression; {set return value of function}
end;
Where ReadExpression and ReadTerm are functions. My question is...how does
one accomplish this in Scheme/Lisp because input^ is used to read from the
input stream instead of a string of chars? Would peek-char be the equivalent
of of Pascal's input^ for looking head in an input stream? Also, how does one
define the equivalent Pascal record using (define-structure ...) and the eq?
in Lisp?:
TreeType = ^TreeNode;
TreeNode = record
Data : DataType;
Left : TreeType;
Right: TreeType;
end;
Also, it is possible to define a variant record and enumerated types in Scheme
/Lisp? Well, I know that there are a alot of question and please understand
that I have a complete working model in Pascal that I would like to translate
to Scheme/Lisp.
Thanks in advance,
-Conrad