1 REM PR_STR(AZ, B) -> R$
7 REM PRINT "AZ: "+STR$(AZ)+", T: "+STR$(T)+", U: "+STR$(U)
8 IF T
=0 THEN R
$="nil":RETURN
9 REM if metadata, then get actual object
10 IF T
>=14 THEN AZ
=U
:GOTO PR_STR_RECUR
11 ON T
GOTO PR_BOOLEAN
,PR_INTEGER
,PR_UNKNOWN
,PR_STRING_MAYBE
,PR_SYMBOL
,PR_SEQ
,PR_SEQ
,PR_SEQ
,PR_FUNCTION
,PR_MAL_FUNCTION
,PR_MAL_FUNCTION
,PR_ATOM
,PR_ENV
,PR_RECUR
,PR_FREE
22 IF U
=0 THEN R
$="false"
26 REM Remove initial space
27 IF U
>=0 THEN T
$=RIGHT$(T$,LEN(T$)-1)
32 IF LEN(R
$)=0 THEN GOTO PR_STRING
33 IF MID$(R$,1,1)=CHR$(127) THEN R
$=":"+MID$(R$,2,LEN(R$)-1):RETURN
35 IF B
=1 THEN GOTO PR_STRING_READABLY
38 S1
$="\":S2$="\\":GOSUB REPLACE
: REM escape backslash "
39 S1
$=CHR$(34):S2$="\"+CHR$(34):GOSUB REPLACE
: REM escape quotes "
40 #cbm S1
$=CHR$(13):S2$="\n":GOSUB REPLACE
: REM escape newlines
41 #qbasic S1
$=CHR$(10):S2$="\n":GOSUB REPLACE
: REM escape newlines
42 R
$=CHR$(34)+R$+CHR$(34)
48 REM push the type and where we are in the sequence
51 REM save the current rendered string
54 IF Z
%(AZ
+1)=0 THEN GOTO PR_SEQ_DONE
55 AZ
=Z
%(AZ
+2):GOSUB PR_STR
:GOSUB PEEK_Q_1
:T
=Q
56 REM append what we just rendered it
59 REM if this is a hash-map, print the next element
60 IF T
=8 THEN GOSUB PEEK_Q
:AZ
=Z
%(Q
+3):GOSUB PR_STR
:S
$(S-1)=S$(S-1)+" "+R$
62 REM restore current seq type
64 REM Go to next list element
68 IF Z%(AZ+1)<>0 THEN S$(S-1)=S$(S-1)+" "
71 REM restore the current string
73 REM pop where we are the sequence and type
75 GOSUB POP_Q
:T
=Q
: REM get type
76 IF T
=6 THEN R
$="("+R$+")"
77 IF T
=7 THEN R
$="["+R$+"]"
78 IF T
=8 THEN R
$="{"+R$+"}"
85 AZ
=Z
%(T1
+2):GOSUB PR_STR
86 REM append what we just rendered it
87 S
$(S)="(fn* "+R$:S=S+1
88 AZ=Z%(T1+1):GOSUB PR_STR
97 R$="#<env"+STR$(AZ)+", data"+STR
$(U)+">"
100 R
$="#<free"+STR$(AZ)+", next"+STR$(U)+">"
103 REM PR_STR_SEQ(AZ, B, B$) -> R$
104 REM - B is print_readably
105 REM - B$ is the separator
110 IF Z%(V+1)=0 THEN S=S-1:R$=S$(S):RETURN
111 AZ=Z%(V+2):GOSUB PR_STR
112 REM goto the next sequence element
114 IF Z%(V+1)=0 THEN S$(S-1)=S$(S-1)+R$
115 IF Z%(V+1)<>0 THEN S$(S-1)=S$(S-1)+R$+B$