Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Reverse Macro-Expansion

Name: Anonymous 2011-08-05 11:06

Is there a way to get macro back from its expanded form?

For examble, can we reconstruct LOOP back from gotoes and labels?

Name: Anonymous 2011-08-05 11:11

only if it has referential transparency I guess.

Name: Anonymous 2011-08-05 11:31

>>1
Forget it, it's NP complete.

Name: Anonymous 2011-08-05 11:39

Not if you don't keep the intermediate expansions.
(defmacro I (x) x)
(defmacro K (x y) x)

(unexpand (expand (if (<= 5 (random 10)) '(I x) '(K x y))))

Name: Anonymous 2011-08-05 21:22

>>3
Then how human mind does it?

Name: Anonymous 2011-08-05 21:36

>>5
It can't do it for any case.
The problem is similar to saying: Here's the output of a program, what program generates this output and given what input? Obviously the answer is an infinity of such programs and thus you should ask only for the shortest program. It becomes a problem of compression, and thus >>3's answer. For a set of given macro expanders (functions which generate code), you may ask which expanders generate some given expansion and given what input. It's still a hard problem as there may be multiple expanders and an unknown number of possible inputs that give the same expansion. In practice, macro expanders can be classified and you can pattern match over the expansion to find out some possible solutions, sometimes using heuristics to resolve various conflicts, and this is what the human mind does, based on the patterns it has learned. This does mean that reversing macro-expansion is similar to compression and decompilation and it can be done, but it's a hard problem and it may be impossible to get ideal/perfect solutions (as the original input), although ``good-enough'' solutions may exist. The other option is to limit macro expanders considerably in such a way as to make it reversible or merely to have your implementation remember all the expansions and let you search over old macro-expansions.

Name: Anonymous 2011-08-06 0:24

>>6
It can't do it for any case.
How do invent new macros then and use already present ones?

Name: Anonymous 2011-08-06 0:26

>>6
you may ask which expanders generate some given expansion and given what input. It's still a hard problem
Just pick the more concise one.

Name: >>6 2011-08-06 0:49

>>7
Instead of ``any'', I should have said every. That is, we're good at finding solutions to particular problems, but we can't find solutions to all the problems.
>>8
In >>6, I say:
thus you should ask only for the shortest program. It becomes a problem of compression, and thus >>3's answer.

Name: Anonymous 2011-08-06 1:33

You've all been trolled, retards.

Name: Anonymous 2011-08-06 21:47

>>9
It becomes a problem of compression
AI is the "problem of compression"? I mean, pattern-matching is just way to do compression by separating common parts (macro form).

Name: Anonymous 2011-08-06 22:16

>>8-9
(define (unexpand code) (lambda _ code))
(define (let-1 var val . body) `(let ((,var ,val)) ,@body))
(define expansion (let-1 'x 1 'x))
(equal? ((unexpand expansion) 'x 1 'x) expansion)

Don't change these.
Name: Email:
Entire Thread Thread List