diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 5ec3be6e..86755ca9 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1850,9 +1850,9 @@ (res) (error (res :error)))) -(def unquote - "(unquote x)\n\nEscapes one level inside of a quasiquote. When used outside of a quasiquote, evaluates - its argument at compile-time." +(def comptime + "(comptime x)\n\n + Evals x at compile time and returns the result. Similar to a top level unquote." :macro eval) (defn make-image diff --git a/src/core/specials.c b/src/core/specials.c index 210f8004..83c686b1 100644 --- a/src/core/specials.c +++ b/src/core/specials.c @@ -120,6 +120,13 @@ static JanetSlot janetc_quasiquote(JanetFopts opts, int32_t argn, const Janet *a return quasiquote(opts, argv[0], JANET_RECURSION_GUARD, 0); } +static JanetSlot janetc_unquote(JanetFopts opts, int32_t argn, const Janet *argv) { + (void) argn; + (void) argv; + janetc_cerror(opts.compiler, "cannot use unquote here"); + return janetc_cslot(janet_wrap_nil()); +} + /* Perform destructuring. Be careful to * keep the order registers are freed. * Returns if the slot 'right' can be freed. */ @@ -812,6 +819,7 @@ static const JanetSpecial janetc_specials[] = { {"quote", janetc_quote}, {"set", janetc_varset}, {"splice", janetc_splice}, + {"unquote", janetc_unquote}, {"var", janetc_var}, {"while", janetc_while} }; diff --git a/test/suite7.janet b/test/suite7.janet index ed9f3820..f7efb9a7 100644 --- a/test/suite7.janet +++ b/test/suite7.janet @@ -273,8 +273,8 @@ # Top level unquote (defn constantly [] - ,(math/random)) + (comptime (math/random))) -(assert (= (constantly) (constantly)) "top level unquote") +(assert (= (constantly) (constantly)) "comptime 1") (end-suite)