0

Suppose I have a higher order language defined with the (rough) BNF (using Lisp notation):

c ::= constants
v ::= variables
e ::= c | v | (if e e e) | (e e_1 e_2 ... e_n) | (fn [v_1 v_2 ... v_n] e)

In the above, the option (e e_1 e_2 ... e_n) represents applying an expression e to arguments e_1 through e_n.

Is every program written in the above language also implicitly in "continuation passing style"? If not, what is the difference?

bzm3r
  • 3,113
  • 6
  • 34
  • 67

1 Answers1

0

No, in my opinion.

CPS (Continuation Passing Style) requires that the last parameter of a function call is itself a function (usually with a single parameter) that will be executed as the "return" of the main function (a callback, if you will).

The syntax of the language shown in your question allows other things, different from functions, to be passed as arguments -- namely variables and constants -- in which case not every function call would have a last argument which was also a function. Therefore, it would be possible to write programs in this language that were not in CPS.

But, on the other hand, yes, you could use such a language to implement calls in Continuation Passing Style.

Branco Medeiros
  • 729
  • 4
  • 10
  • Thank you for your answer! I wonder though if a variable/constant is simply a function that returns itself. I could write it in more long-winded form as `fn [v] v`. I think CPS has this as well? After all, at some point, you want your computation to return with some result, rather than keep going on forever? – bzm3r Nov 17 '21 at 22:42