I’m currently writing a LISP parser that iterates through some AutoLISP code and does its best to make it a little easier to read (changing prefix notation to infix notation, changing setq assignments to “=” assignments, etc.) for those that aren’t used to LISP code/only learned object oriented programming.
While writing commands that LISP uses to add to a “library” of LISP commands, I came across the LISP command “progn”. The only problem is that it looks like progn is simply executing code in a specific order and sometimes (not usually) assigning the last value to a variable.
Am I incorrect in assuming that for translating progn to object-oriented understanding that I can simply forgo the progn function and print the statements that it contains? If not, what would be a good equivalent for progn in an object-oriented language?
Everything in Lisp is an expression, meaning that it returns a value. The progn
function executes a series of functions/forms, ignoring the return values of all but the last call/form, which it returns as its own return value.
E.g. in the following code
(progn
(some-method 'a 'b 'c)
(another-method 1 2 3)
(final-method "x" "y" "z"))
the value returned by the call to final-method
would be the value returned by the enclosing progn
call.
An OOP equivalent would be:
public FinalReturnType prognImpl123()
{
someMethod(Sym("a"), Sym("b"), Sym("c"));
anotherMethod(1, 2, 3);
return finalMethod("x", "y", "z");
}
As progn
s you encounter will likely be nested in other expressions, you’ll want your translations to return something.
4