24

According to Emacs documentation:

progn is a special form in `C source code'.

(progn BODY...)

Eval BODY forms sequentially and return value of last one.
  1. What does progn stands for (or its origin)?
  2. Useage: Is it equivalent to Clojure's -> macro?
wasamasa
  • 21,803
  • 1
  • 65
  • 97
Nick
  • 4,423
  • 4
  • 24
  • 41

1 Answers1

34
  1. progn is a special form borrowed from CL-like Lisp dialects. In their implementations it's composed from multiple progs, expressions that are evaluated and a number that specifies which expression value is returned. prog1 for instance evaluates all expressions and returns the value of the first, prog2 evaluates all expressions and returns the value of the second, progn evaluates all expressions and returns the n'th, or rather, the last expression's value.

  2. progn in Emacs Lisp is the equivalent of Clojure's do which is used as means to bundle multiple expressions into a single one. You'll need to use it for Clojure's if conditional for instance.

wasamasa
  • 21,803
  • 1
  • 65
  • 97
  • 1
    Good answer, I upvoted it. However, for the sake of formality: you don't really *need* it for conditionals, `cond` has an implicit `progn`. – mbork Dec 28 '14 at 21:01
  • 2
    Uh, I was speaking of Clojure which does not have implicit `progn` in its `if`. – wasamasa Dec 28 '14 at 21:04
  • 3
    Emacs also has `prog1` and `prog2` as built-in special forms. – cjm Dec 29 '14 at 06:32
  • 1
    I have seen this used in a lot of users' configurations. Is there a performance boost from "bundling" multiple expressions this way as opposed to evaluating them one after the other outside of `progn`? – elethan Dec 03 '15 at 03:41
  • Not sure what makes you think that. `progn` is the equivalent of a braced block in a C-like language... – wasamasa Dec 03 '15 at 07:57