Nesting Backquotes

24 views
Skip to first unread message

ksjogo

unread,
Apr 15, 2012, 3:17:14 PM4/15/12
to program...@googlegroups.com
Hi guys,
is there any advice/experience for nesting backquotes and evals with Nu?
I am trying to write some macros expanding to other macros, but this fails because eval and splice are always evaled, even if buried under another quasiquote.

ksjogo

unread,
Apr 18, 2012, 12:21:38 PM4/18/12
to program...@googlegroups.com
Ok, I got around them (reading the source helped a lot) and added a ~ parser macro to ease the eyes and show the differences to Lisp.
The difference to Lisp is, that other quasiquotes are not evaled, so further evals are not from the inner quasiquotes, but from the most out one.
So you need to 'shield' inner quasiquotes with a ,' construct. The ~ is treated as exactly that.

(macro pairworker (name block)
    `(macro ,name (*body)
        (let ((blk ,block))
            `(progn
                ~,@(*body map: ; the ~ shields the following list from evaluation from the outest quasiquote, so the , is only 'executed' for the inner quasiquote
                        (do (pair)
                            (set p0 (car pair))
                            (set p1 (car (cdr pair)))
                            (blk p0 p1)))
                nil))))

(pairworker creators
    (do (command cls)
        `(macro ,command (*rest)
            `(mpscene createMPObject:,cls options:~,(pairs2dict *rest)))))

(creators
    (deck MPDeck)
    (playpile MPPlaypile)
    (discardpile MPDiscardpile)
    (scorer MPScorer)
    (scorerendless MPScorerEndless)
    (scorer60seconds MPScorer60Seconds))
 
Reply all
Reply to author
Forward
0 new messages