viewing paste quasi quote implementation | Javascript

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    function read_quote(port, tok) {
        if ("'" === tok) return [ sym.quote, read_port(port) ];
        if ('`' === tok) return [ sym.quasiquote, read_port(port) ];
        if (',' === tok) return [ sym.unquote, read_port(port) ];
        if (',@' === tok) return [ sym.unatquote, read_port(port) ];
        throw new Error("unknown quote "+tok+ " : "+writeString(fileHandler(port, 'info')).str);
    }
 
/* ... */
 
       qq: function (x) {
            if (!(x instanceof Array)) {
                return [ env.quote, x ];
            }
            if (x.length >= 1) {
                if (x[0][0] === sym.unatquote) {
                    if (1 < x.length)
                        return [ env.append, x[0][1], helper.qq(x.slice(1)) ];
                    else
                        return [ env.append, x[0][1] ];
                }
            }
            if (x.length === 2) {
                if (x[0] === sym.unquote) {
                    return x[1];
                }
                if (x[0] === sym.quasiquote) {
                    return helper.qq( helper.qq( x[1] ) );
                }
            }
            if (2 > x.length) {
                return [ env.list, helper.qq(x[0])];
            }
            return [ env.cons, helper.qq(x[0]), helper.qq(x.slice(1)) ];
        },
 
/* ... */
 
        quasiquote: function(a) {
            constrain['(.)']('quasiquote', a);
            var r = helper.qq(a[0]);
            debugList("quasi" , r);
            code.push({ q:r, e:this.e, p:this.p });
            return; /* continuation */
        },
 
Viewed 653 times, submitted by Guest.