zlacker

[return to "Rama on Clojure's terms, and the magic of continuation-passing style"]
1. robert+uo1[view] [source] 2024-10-14 16:19:19
>>nathan+(OP)
This article is written for people who know Clojure, or at least the examples are. It might be nice to see the examples written in a non-LISP as well.

E.g.

  (?<-
    (ops/explode [1 2 3 4] :> *v)
      (println "Val:" *v))
Is (I believe) the equivalent of Python's

  for element in [1, 2, 3, 4]:
    print(element)
◧◩
2. nathan+uI1[view] [source] 2024-10-14 18:13:21
>>robert+uo1
That Python code has the same effect, but the equivalent Python in CPS would be:

  def explode(args, cont):
    for e in args:
       cont(e)
  
  (explode [1, 2, 3, 4], print)
◧◩◪
3. gpdere+In3[view] [source] 2024-10-15 09:17:52
>>nathan+uI1
That's not in CPS form as cont returns into explode. Even if we treat the for loop in explode as an implementation detail, cont should take the next continuation as a parameter.
[go to top]