Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CDep fun.
THIS IS THE ORIGINAL BEHAVIOR (all fixed now).
$define(myecho,$echo($0))
$define(myecho2,$myecho($0))
$echo(comma=$,)
$myecho(comma=$,)
$myecho(comma=$$$,)
$myecho2(comma=$$$,)
prints:
comma=,
comma=
comma=,
comma=
...but wait, if I need to escape it as "$$$," when calling myecho, does that mean I just need to add an
extra $$ when calling myecho2?
No. In fact you need to write _six_ $ signs to get 3 dollar signs by the time myecho evaluates something,
and of course you need to escape the actual comma too, so the magic sequence to make myecho2 print a ',' is in fact:
$myecho2(comma=$$$$$$$,)
and in general, if you want to escape something, you need to add (2^k)-1 dollar signs in front of it, where k is
the level of the call tree where you want to use it.
Furthermore, this:
$define(funcABC,
$echo(ABC!)
$echo(ABC-0: $0)
$echo(ABC-1: $1)
$echo(ABC-2: $2)
$echo(ABC done!)
)
$define(funcAB,
$echo(AB!)
$echo(AB-0: $0)
$echo(AB-1: $1)
$funcABC($0,$1)
$0 $// ignored return value
$echo(AB done!)
)
$funcAB(A,B)
$funcAB(A$,B,C)
$funcAB(A$$$,B,C)
$funcAB(A$echo(holy side effect batman!),B)
$funcAB(A$$echo$(holy side effect batman!$),B)
prints:
AB!
AB-0: A
AB-1: B
ABC!
ABC-0: A
ABC-1: B
ABC-2:
ABC done!
AB done!
AB!
AB-0: A
AB-1: C
ABC!
ABC-0: A
ABC-1: C
ABC-2:
ABC done!
AB done!
AB!
AB-0: A,B
AB-1: C
ABC!
ABC-0: A
ABC-1: C
ABC-2:
ABC done!
AB done!
holy side effect batman!
AB!
AB-0: A
AB-1: B
ABC!
ABC-0: A
ABC-1: B
ABC-2:
ABC done!
AB done!
AB!
holy side effect batman!
AB-0: A
AB-1: B
holy side effect batman!
ABC!
ABC-0: A
ABC-1: B
ABC-2:
ABC done!
holy side effect batman!
AB done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment