Here's another example.
This one puts out the usual SWI-Prolog SGML/XML representation of an HTMl DIV if the quasiquoted content is all whitespace it says empty, if it contains foo then the next letter should match a variable name in the argument list, and the value of that variable will be inserted in the output.
If foo isn't present, the value of the first variable will be reported. Both Vars and Dict are needed in case the argument isn't a variable (as in second test case).
:- module(jetpack, [jet/4]). :- use_module(library(dcg/basics)). :- use_module(library(quasi_quotations)). % so we recognize {|jet(X)||.... |} :- quasi_quotation_syntax(jet). %! jet_syntax(+Vars:list, +Dict:list, -DOM:list) is det % % called at compile time to convert the quasiquote to % the target language % % We make ourselves look like the html quoter % so you can insert jet in the content fed to html//1 % or {|html(X)||<p>some html with X</p>|} % jet_syntax(_Vars, _Dict, [element(div, [], ['empty'])]) --> blanks, eos. jet_syntax(_, Dict, [element(div, [], ['has foo, matching var is', V])]) --> string(_), "foo", [VarName], { atom_codes(AtomName, [VarName]), member(AtomName=V, Dict) }, string(_), eos, !. jet_syntax([VH|_], _Dict, [element(div, [], ['no foo, first var is', VH])]) --> string(_), eos. % actually does the conversion, jet_syntax does the heavy lifting jet(Content, Vars, Dict, DOM) :- phrase_from_quasi_quotation(jet_syntax(Vars, Dict, DOM), Content). testjet :- X=7, Y={|jet(X)|| fooX |}, writeln(Y), Z = {|jet(7)|| oogle |}, writeln(Z). results [debug] ?- testjet. Correct to: "jetpack:testjet"? yes [element(div,[],[has foo, matching var is,7])] [element(div,[],[no foo, first var is,7])] true.
Props to Carlo, I started with his example.