Question about displaying the contents of a list

0 views
Skip to first unread message

wanorris

unread,
Aug 23, 2006, 7:02:04 PM8/23/06
to LSharp
The prl function does a lovely job of sending the contents of a list to
the console. For example, in this line from the sample file
Hashtable.ls, the hashtable is cast to a Cons, then printed so that it
neatly displays all its items:

(prl (the Cons foo))

By contrast, the statement

(ToString (the Cons foo))

returns "LSharp.Cons", as does any command that implicitly converts a
Cons to a string.

Is there currently a clean way to retrieve a string representation of a
list as a string rather than sending it to console?

If not, it seems like the obvious solution would be to have Cons
override ToString and produce the same string that the pr command
produces (i.e. no newline). Does that seem reasonable?

wanorris

unread,
Aug 24, 2006, 7:24:53 PM8/24/06
to LSharp
OK, I've gone through the code.

The only thing that needs to be done to fix this is that the following
additional method needs to be added to Cons.cs:

/// <summary>
/// Overrides the default ToString to return the string
representation of the list
/// as produced by the L Sharp Printer.
/// </summary>
/// <returns>The string represention of the list.</returns>
public override string ToString()
{
return Printer.WriteToString(this);
}

Is this a reasonable request?

Rob Blackwell

unread,
Aug 28, 2006, 4:02:32 PM8/28/06
to LSh...@googlegroups.com
Thanks! - I have accepted this patch and it's now in the L Sharp Subversion
repository. Rob.
Reply all
Reply to author
Forward
0 new messages