From f3944ce73d35f18b0d3cea06d73685823d605dd3 Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Wed, 14 Jul 2021 08:14:07 +0200 Subject: [PATCH] feat: add Dynamic.Debug.trace (#1279) --- core/Dynamic.carp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/Dynamic.carp b/core/Dynamic.carp index b9dee77e..e62b214a 100644 --- a/core/Dynamic.carp +++ b/core/Dynamic.carp @@ -73,6 +73,22 @@ integers [`imod`](#imod).") (defndynamic tail [s] (String.suffix s 1)) ) + + (defmodule Debug + (doc trace "prints the value of an expression to `stdout`, then returns its value.") + (defmacro trace [x] + (let [sym (gensym)] + `(let-do [%sym %x] + ; we use eval here to ensure we resolve the symbol before putting it + ; into file, line, and column + (macro-log + %(eval `(file %x)) ":" + %(eval `(line %x)) ":" + %(eval `(column %x)) ": " + %sym) + %sym)) + ) + ) )