Chris Riesbeck <Chris.Riesbeck@gmail.com> wrote:
+---------------
| Rob Warnock wrote:
| > Chris Riesbeck <Chris.Riesbeck@gmail.com> wrote:
| > | For contrast, here's a straight macro version. Every _ is replaced by a
| > | gensym, every _n is replaced by a previous _ variable (one-based). Any
| > | other use of _xxx is left alone.
| > ...
| > | > (mapcan (_ (and (> _ _) (list _1))) '(3 5 7) '(1 6 5))
| > | (3 7)
| > +---------------
| >
| > I understand that you can back-reference already used "_"s, but
| > how do you specify order *without* backreference. E.g., how do you
| > do the same as the following in my "#$" readmacro:
| >
| > > (mapcar #$(list $2 $1) '(3 5 7) '(1 6 5))
| >
| > ((1 3) (6 5) (5 7))
|
| I had a different semantics in my head. How do non-indexed forms fit in
| with indexed ones, e.g., what's the lambda equivalent for
|
| $(list $3 $ $1)
+---------------
I don't know what you mean by that form. But if you meant
#$(list $3 $ $1), well, my current "#$" readmacro doesn't do
anything special with a naked "$" [unlike your macro with "_"],
so it's simply this:
> (read-from-string "#$(list $3 $ $1)")
(LAMBDA (&OPTIONAL $1 $2 $3 $4 $5 $6 $7 $8 $9 &REST $*)
(DECLARE (IGNORABLE $1 $2 $3 $4 $5 $6 $7 $8 $9 $*))
(LIST $3 $ $1))
16
>
and "$" is a free variable.
If you really meant to type #$(list $3 $* $1), then in the improved
version of "#$" I was discussing before [where the &REST parameter
"$*" occurs just after the highest "${n}" seen], the expansion would be:
(LAMBDA ($1 $2 $3 &REST $*)
(DECLARE (IGNORE $2))
(LIST $3 $* $1))
But to ask my question again, with your "_" macro, how do you
(or can you) re-order arguments without providing dummy occurrences
of "_" to provide anchors for back-references? That is, you can write a
(PAIRLIS LIST1 LIST2) in my "#$" as (MAPCAR #$(CONS $1 $2) LIST1 LIST2)
and in your "_" macro as (MAPCAR (_ (CONS _ _)) LIST1 LIST2) -- no problem
there.
And one can write a [hypothetical] (SWAPPED-PAIRLIS LIST1 LIST2) in "#$" as
(MAPCAR #$(CONS $2 $1) LIST1 LIST2), but in your "_" the only way I could
figure out how to write it was (MAPCAR (_ _ _ (CONS _2 _1)) LIST1 LIST2).
Is there a simpler way? One that leaves \_\___ these out?
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607