-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the `display` and `newline` builtins to the Serefa library. Here we can hopefully extend them with better support for displaying external representation and add a `write` impl too.
- Loading branch information
1 parent
1743285
commit 02ca7e0
Showing
5 changed files
with
76 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
|
||
namespace Serehfa | ||
{ | ||
/// <summary> | ||
/// The unspecified / undefined value. Instances of this type are returned | ||
/// from scheme functions where no specific return value is specified in | ||
/// the standard. | ||
/// </summary> | ||
public class Undefined | ||
{ | ||
private static Lazy<Undefined> s_Instance = new Lazy<Undefined>(); | ||
public static Undefined Instance => s_Instance.Value; | ||
|
||
public override string ToString() => "; Unspecified value"; | ||
|
||
/// <summary> | ||
/// Instances of these values are never equal to anything else. | ||
/// </summary> | ||
public override bool Equals(object obj) => false; | ||
|
||
public override int GetHashCode() => base.GetHashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace Serehfa | ||
{ | ||
using System; | ||
using static ArgHelpers; | ||
|
||
public static class Write | ||
{ | ||
[LispBuiltin("newline")] | ||
public static object Newline(object[] args) | ||
{ | ||
CheckNoArgs(args); | ||
|
||
Console.WriteLine(); | ||
|
||
return Undefined.Instance; | ||
} | ||
|
||
/// <summary> | ||
/// Display builtin. This is intended for user-readable output rather than | ||
/// any machine readable round tripping. Printing out strings & chars should | ||
/// display their raw form. All other objects is up to the implementation. | ||
/// | ||
/// This implementation calls `ToString` on the underlying .NET object and | ||
/// uses that directly. | ||
/// </summary> | ||
[LispBuiltin("display")] | ||
public static object Display(object[] args) | ||
{ | ||
var obj = UnpackArgs<object>(args); | ||
|
||
var repr = obj == null ? | ||
"'()" : obj.ToString(); | ||
|
||
Console.Write(repr); | ||
|
||
return Undefined.Instance; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters