Commit 81cd9638 authored by Jesse McGrew's avatar Jesse McGrew

Added QQ package for quasiquoting.

After loading the package with <USE "QQ">, ` and ~ can be used to quote values while replacing the inner parts.

Before:

<DEFMAC PROB ('N) <FORM L? '<RANDOM 100> .N>>

After:

<DEFMAC PROB ('N) `<L? <RANDOM 100> ~.N>>

Fixes ZILF-180.
parent 077f65d1a5f9
<PACKAGE "QQ">
<ENTRY QUASIQUOTE TILDE>
<NEWTYPE TILDE LIST '!<<PRIMTYPE LIST> ANY>>
<DEFINE QUASIQUOTE ("BIND" ENV 'STRUC "AUX" (ALLOW-SPLICING? <>))
<QQ-IMPL .ENV .STRUC>>
<DEFINE UNQUOTE? (OBJ)
<TYPE? .OBJ TILDE>>
<DEFINE UNQUOTE-SPLICING? (OBJ)
<DECL? .OBJ '<TILDE SEGMENT>>>
<DEFINE QQ-IMPL (ENV STRUC "AUX" (P <PRIMTYPE .STRUC>) (T <TYPE .STRUC>))
<COND (<UNQUOTE-SPLICING? .STRUC>
<OR .ALLOW-SPLICING? <ERROR UNQUOTE-SPLICING-NOT-ALLOWED-THERE .STRUC>>
<MAPRET !<EVAL <CHTYPE <1 .STRUC> FORM> .ENV>>)
(<UNQUOTE? .STRUC>
<EVAL <1 .STRUC> .ENV>)
(<OR <==? .T STRING>
<NOT <STRUCTURED? .STRUC>>>
.STRUC)
(<NOT <AND <GBOUND? .P> <APPLICABLE? ,.P>>>
<ERROR CANNOT-RECREATE-PRIMTYPE .P>)
(ELSE
<CHTYPE <APPLY ,.P !<QQ-ELEMS .ENV .STRUC>> .T>)>>
<DEFINE QQ-ELEMS (ENV STRUC "AUX" (ALLOW-SPLICING? T))
<MAPF ,VECTOR
<FUNCTION (I) <QQ-IMPL .ENV .I>>
.STRUC>>
<DEFINE WRAP-QQ ("ARGS" A) <FORM QUASIQUOTE !.A>>
<DEFINE WRAP-UQ ("ARGS" A) <CHTYPE .A TILDE>>
;"TODO: USE READER-MACROS"
<COND (<GASSIGNED? MAKE-PREFIX-MACRO!-READER-MACROS>
<MAKE-PREFIX-MACRO!-READER-MACROS !\` ,WRAP-QQ>
<MAKE-PREFIX-MACRO!-READER-MACROS !\~ ,WRAP-UQ>)>
<ENDPACKAGE>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment