News for hackers. Stuff that matters.
Re:Show HN: A dbg(...) macro for C++ by 97b683f8 on Saturday September 21, 2019 @12:24PM (#21036230)
in lisp this would be

    (defmacro dbg [expr]
      (println '~expr ~expr))
Re:Show HN: A dbg(...) macro for C++ by Ives on Saturday September 21, 2019 @12:45PM (#21036346)
Not really, the C++ macro provides information about which source file the statement was generated from, as well as color coding.
Re:Show HN: A dbg(...) macro for C++ by kazinator on Sunday September 22, 2019 @01:58PM (#21042802)

  1> (defmacro dbg (expr)
       (with-gensyms (val)
         ^(let ((,val ,expr))
            (format t "~a: ~s -> ~s\n" (source-loc-str ',expr) ',expr ,val)
            ,val)))
  dbg
  2> (dbg (cons 1 2))
  expr-2:1: (cons 1 2) -> (1 . 2)
  (1 . 2)
  3> (dbg (+ 2 2))
  expr-3:1: (+ 2 2) -> 4
  4
  4> (progn
       (dbg (list 1 2))
       (dbg (cons 1 2))
       (dbg (+ 1 2)))
  expr-4:2: (list 1 2) -> (1 2)
  expr-4:3: (cons 1 2) -> (1 . 2)
  expr-4:4: (+ 1 2) -> 3
  3
Colorization is just inserting some trivial ANSI codes. Arguably, this just slows down the program even more and increases the size of the log files. It can be done as a post-processing filter.