@@ -2,17 +2,18 @@ package builtin
22
33import (
44 "fmt"
5+ "io"
56)
67
7- func PrintFunction (bs []byte ) {
8- _ , _ = fmt . Printf ( "%v \n " , bs )
8+ func PrintFunction (w io. Writer , bs []byte ) {
9+ _ , _ = w . Write ( bs )
910}
1011
1112// EchoFunction converts bytes to text and prints it
1213// If bytes represent a reel (array of tapes), it prints each tape in sequence
1314// If bytes represent a tape (8 bytes), it prints the tape as a character
1415// If bytes represent a number, it encodes it as text (ASCII character)
15- func EchoFunction (bs []byte ) {
16+ func EchoFunction (w io. Writer , bs []byte ) {
1617 // Check if this is a reel (array of tapes)
1718 // A reel is a concatenation of multiple 8-byte tapes
1819 // If the length is a multiple of 8 and greater than 8, it's likely a reel
@@ -32,9 +33,9 @@ func EchoFunction(bs []byte) {
3233 }
3334 }
3435 if result != "" {
35- fmt . Println ( result )
36+ _ , _ = w . Write ([] byte ( result ) )
3637 } else {
37- fmt . Println ( )
38+ _ , _ = w . Write ([] byte ( " \n " ) )
3839 }
3940 return
4041 }
@@ -53,10 +54,10 @@ func EchoFunction(bs []byte) {
5354 char := rune (significant [len (significant )- 1 ])
5455 if char >= 32 && char <= 126 {
5556 // Printable ASCII character
56- fmt . Println ( string (char ))
57+ _ , _ = w . Write ([] byte ( string (char ) ))
5758 } else {
5859 // Non-printable, print as-is
59- fmt . Println ( string (significant ))
60+ _ , _ = w . Write ([] byte ( string (significant ) ))
6061 }
6162}
6263
0 commit comments