From c140bac5b058935e550b0d19fadd7dd822ce9f7a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 21 Mar 2023 21:48:05 -0700 Subject: New function: ignore, synonym of nilf. This will be an official mechanism for indicating deliberately unused variables. * eval.c (eval_init): Register ignore intrinsic, binding to the same function object as nilf. * stdlib/compiler.tl (%const-foldable-funs%): Mention ignore function, next to its nilf synonym. * txr.1: Documented. * stdlib/doc-syms.tl: Updated. --- eval.c | 7 ++++++- stdlib/constfun.tl | 2 +- stdlib/doc-syms.tl | 5 +++-- txr.1 | 23 ++++++++++++++++++++++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/eval.c b/eval.c index e09db92a..343ea49f 100644 --- a/eval.c +++ b/eval.c @@ -7160,7 +7160,12 @@ void eval_init(void) reg_fun(intern(lit("callf"), user_package), func_n1v(callf)); reg_fun(intern(lit("mapf"), user_package), func_n1v(mapf)); reg_fun(intern(lit("tf"), user_package), func_n0v(tf)); - reg_fun(intern(lit("nilf"), user_package), func_n0v(nilf)); + + { + val nilf_f = func_n0v(nilf); + reg_fun(intern(lit("nilf"), user_package), nilf_f); + reg_fun(intern(lit("ignore"), user_package), nilf_f); + } reg_fun(intern(lit("print"), user_package), func_n3o(print, 1)); reg_fun(intern(lit("pprint"), user_package), func_n2o(pprint, 1)); diff --git a/stdlib/constfun.tl b/stdlib/constfun.tl index bef32cc5..0f66ac41 100644 --- a/stdlib/constfun.tl +++ b/stdlib/constfun.tl @@ -47,7 +47,7 @@ memq memql memqual rmemq rmemql rmemqual countq countql countqual posq posql posqual rposq rposql rposqual eq eql equal meq meql mequal neq neql nequal max min clamp bracket take drop if or and progn - prog1 prog2 nilf tf display-width sys:fmt-simple + prog1 prog2 nilf ignore tf display-width sys:fmt-simple sys:fmt-flex sys:fmt-join packagep symbolp keywordp bindable stringp length-str coded-length cmp-str string-lt str= str< str> str<= str>= int-str diff --git a/stdlib/doc-syms.tl b/stdlib/doc-syms.tl index 067d3701..4046ea49 100644 --- a/stdlib/doc-syms.tl +++ b/stdlib/doc-syms.tl @@ -985,6 +985,7 @@ ("ignbrk" "N-02391683") ("igncr" "N-02391683") ("ignerr" "N-007287AC") + ("ignore" "N-007E0508") ("ignpar" "N-02391683") ("ignwarn" "N-02552A58") ("imaxbel" "N-02391683") @@ -1324,7 +1325,7 @@ ("next-file" "N-00839D2F") ("nf" "N-0267AE6D") ("nil" "N-015134D8") - ("nilf" "N-032070EB") + ("nilf" "N-007E0508") ("ninth" "N-01B0FA33") ("nl0" "N-03BD477F") ("nl1" "N-03BD477F") @@ -1994,7 +1995,7 @@ ("test-neq-set-indent-mode" "N-01A1F89C") ("test-set" "N-036C7E9E") ("test-set-indent-mode" "N-01A1F89C") - ("tf" "N-032070EB") + ("tf" "N-007E0508") ("third" "N-01B0FA33") ("throw" "D-0053") ("throwf" "N-015466AD") diff --git a/txr.1 b/txr.1 index 7be5a547..159c958d 100644 --- a/txr.1 +++ b/txr.1 @@ -58769,10 +58769,11 @@ with both optional arguments omitted: [iff a] <---> [iff a identity nilf] <---> a .brev -.coNP Functions @ tf and @ nilf +.coNP Functions @, tf @ nilf and @ ignore .synb .mets (tf << arg *) .mets (nilf << arg *) +.mets (ignore << arg *) .syne .desc The @@ -58789,6 +58790,11 @@ and the function returns .codn nil . +The +.code ignore +function is a synonym of +.codn nilf . + Note: the following equivalences hold between these functions and the .code ret operator, and @@ -58813,6 +58819,11 @@ and [mapcar (ret nil) list] <--> [mapcar nilf list] .brev +Note: the +.code ignore +function can be used for suppressing unused variable +warnings. + .TP* Example: .verb @@ -58851,6 +58862,16 @@ is even, then iff passes it into the function, which ignores the value and returns .codn nil . +The following example shows how +.code ignore +may be used to suppress compiler warnings about unused parameters +or other variables: + +.verb + (defun (x y) + (ignore x y)) +.brev + .coNP Function @ retf .synb .mets (retf << value ) -- cgit v1.2.3