From c656cf912e32f394a525d970bce7b08e47f06333 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Sun, 4 Jul 2021 23:38:07 -0400 Subject: genman, lib, tests: use defvarl where possible. * genman.txr (dupes, tagnum): Replace defvar with defvarl. * stdlib/doc-lookup.tl (os-symbol): Same. * tests/011/macros-3.tl (x): Same. * tests/011/mandel.txr (x-centre, y-centre, width, i-max, j-max, n) (r-max, pixel-size, x-offset, y-offset): Same. (file, colour-max): Delete (unused) variables. * tests/012/circ.tl (x): Replace defvar with defvarl. * tests/012/stack.tl (stack-limited): Same. * tests/012/struct.tl (s): Same. * tests/013/maze.tl (vi, pa, sc): Delete variables. Use function arguments instead. (usage): Fix typo. * tests/014/dgram-stream.tl (family): Rename to... (*family*): ...this. * tests/014/socket-basic.tl (socktype): Rename to... (*socktype*): ...this. (%iters%): Replace defvar with defvarl. --- genman.txr | 4 ++-- stdlib/doc-lookup.tl | 2 +- tests/011/macros-3.tl | 2 +- tests/011/mandel.txr | 22 ++++++++++------------ tests/012/circ.tl | 6 +++--- tests/012/stack.tl | 2 +- tests/012/struct.tl | 2 +- tests/013/maze.tl | 16 ++++++---------- tests/014/dgram-stream.tl | 8 ++++---- tests/014/socket-basic.tl | 10 +++++----- 10 files changed, 34 insertions(+), 40 deletions(-) diff --git a/genman.txr b/genman.txr index 392b8524..879f5413 100644 --- a/genman.txr +++ b/genman.txr @@ -9,8 +9,8 @@ @(bind clpsall "[collapse all]") @(bind closed t) @(do - (defvar dupes (hash)) - (defvar tagnum (hash :equal-based)) + (defvarl dupes (hash)) + (defvarl tagnum (hash :equal-based)) (defvarl disamb (hash :equal-based)) (defvarl dist-counter 0) diff --git a/stdlib/doc-lookup.tl b/stdlib/doc-lookup.tl index 110d37d4..ea2ede3c 100644 --- a/stdlib/doc-lookup.tl +++ b/stdlib/doc-lookup.tl @@ -2,7 +2,7 @@ (defvar usr:*doc-url* "https://www.nongnu.org/txr/txr-manpage.html") -(defvar os-symbol +(defvarl os-symbol (if (ignerr (dlsym (dlopen "libandroid.so") "AAsset_close")) :android (let ((u (uname))) diff --git a/tests/011/macros-3.tl b/tests/011/macros-3.tl index e08e5da7..9a595021 100644 --- a/tests/011/macros-3.tl +++ b/tests/011/macros-3.tl @@ -11,7 +11,7 @@ (m)))))) 42) -(defvar x 0) +(defvarl x 0) (defmacro mac-time-counter () (inc x)) (defsymacro s (mac-time-counter)) diff --git a/tests/011/mandel.txr b/tests/011/mandel.txr index 8a701526..cfa24857 100644 --- a/tests/011/mandel.txr +++ b/tests/011/mandel.txr @@ -1,16 +1,14 @@ @(do - (defvar x-centre -0.5) - (defvar y-centre 0.0) - (defvar width 4.0) - (defvar i-max 80) - (defvar j-max 60) - (defvar n 100) - (defvar r-max 2.0) - (defvar file "mandelbrot.pgm") - (defvar colour-max 255) - (defvar pixel-size (/ width i-max)) - (defvar x-offset (- x-centre (* 0.5 pixel-size (+ i-max 1)))) - (defvar y-offset (+ y-centre (* 0.5 pixel-size (+ j-max 1)))) + (defvarl x-centre -0.5) + (defvarl y-centre 0.0) + (defvarl width 4.0) + (defvarl i-max 80) + (defvarl j-max 60) + (defvarl n 100) + (defvarl r-max 2.0) + (defvarl pixel-size (/ width i-max)) + (defvarl x-offset (- x-centre (* 0.5 pixel-size (+ i-max 1)))) + (defvarl y-offset (+ y-centre (* 0.5 pixel-size (+ j-max 1)))) ;; complex number library (macro-time diff --git a/tests/012/circ.tl b/tests/012/circ.tl index 4b6e9990..82abe745 100644 --- a/tests/012/circ.tl +++ b/tests/012/circ.tl @@ -5,9 +5,9 @@ (print me.a stream pretty-p) (put-string "]]" stream))) -(defvar x (let* ((l (list "a")) - (c (new circ-print a l))) - (list l c))) +(defvarl x (let* ((l (list "a")) + (c (new circ-print a l))) + (list l c))) (let ((*print-circle* t)) (prinl (new circ-print a "a")) diff --git a/tests/012/stack.tl b/tests/012/stack.tl index 9a7534bb..62df252b 100644 --- a/tests/012/stack.tl +++ b/tests/012/stack.tl @@ -1,6 +1,6 @@ (load "../common") -(defvar stack-limited (set-stack-limit 32768)) +(defvarl stack-limited (set-stack-limit 32768)) (defun recur () (recur)) diff --git a/tests/012/struct.tl b/tests/012/struct.tl index 3f03552d..bdff6311 100644 --- a/tests/012/struct.tl +++ b/tests/012/struct.tl @@ -16,7 +16,7 @@ (test (expand '^#S(bar b ,(+ 2 2))) (sys:make-struct-lit 'bar (list 'b (+ 2 2)))) -(defvar s (eval ^#S(bar b ,(+ 2 2)))) +(defvarl s (eval ^#S(bar b ,(+ 2 2)))) (test (set (slot s 'a) 100) 100) diff --git a/tests/013/maze.tl b/tests/013/maze.tl index 5cb989d6..38dca3e3 100644 --- a/tests/013/maze.tl +++ b/tests/013/maze.tl @@ -1,7 +1,3 @@ -(defvar vi) ;; visited hash -(defvar pa) ;; path connectivity hash -(defvar sc) ;; count, derived from straightness fator - (defun scramble (list) (let ((out ())) (each ((item list)) @@ -18,7 +14,7 @@ (list (- x 1)..y (+ x 1)..y x..(- y 1) x..(+ y 1)))) -(defun make-maze-impl (cu) +(defun make-maze-impl (vi pa sc cu) (let ((fr (hash :equal-based)) (q (list cu)) (c sc)) @@ -38,16 +34,16 @@ (pop q))))))) (defun make-maze (w h sf) - (let ((vi (hash :equal-based)) - (pa (hash :equal-based)) - (sc (max 1 (int-flo (trunc (* sf w h) 100.0))))) + (let ((vi (hash :equal-based)) ;; visited hash + (pa (hash :equal-based)) ;; path connectivity hash + (sc (max 1 (int-flo (trunc (* sf w h) 100.0))))) ;; go straight count (each ((x (range -1 w))) (set [vi x..-1] t) (set [vi x..h] t)) (each ((y (range* 0 h))) (set [vi -1..y] t) (set [vi w..y] t)) - (make-maze-impl 0..0) + (make-maze-impl vi pa sc 0..0) ;; Open start and end (push 0..-1 [pa 0..0]) (push (- w 1)..(- h 1) [pa (- w 1)..h]) @@ -78,7 +74,7 @@ (let ((invocation (ldiff *full-args* *args*))) (put-line "usage: ") (put-line `@invocation []`) - (put-line "straightness-factor is a percentage, defaulting to 15") + (put-line "straightness is a percentage, defaulting to 15") (exit 1))) (let ((args [mapcar num-str *args*])) diff --git a/tests/014/dgram-stream.tl b/tests/014/dgram-stream.tl index 5902a84d..6890e300 100644 --- a/tests/014/dgram-stream.tl +++ b/tests/014/dgram-stream.tl @@ -1,7 +1,7 @@ (load "../common.tl") (load "../sock-common.tl") -(defvar family) +(defvar *family*) (defun server (svc-sock) (whilet ((acc-sock (sock-accept svc-sock)) @@ -10,7 +10,7 @@ (close-stream acc-sock))) (defun client (addr) - (with-stream (cli-sock (open-socket family sock-dgram)) + (with-stream (cli-sock (open-socket *family* sock-dgram)) (sock-connect cli-sock addr) (dotimes (i 1000) (print i cli-sock) @@ -22,7 +22,7 @@ (flush-stream cli-sock))) (defun dgram-test () - (let* ((svc-sock (open-socket family sock-dgram)) + (let* ((svc-sock (open-socket *family* sock-dgram)) (svc-addr (bindfree svc-sock 1025 65535)) (server-pid (fork))) (cond @@ -37,6 +37,6 @@ (fboundp 'fork)) (let ((maybe-ipv6 (if (memq (os-symbol) '(:linux :macos :cygwin :cygnal)) (list af-inet6)))) - (each ((family ^(,af-inet ,*maybe-ipv6))) + (each ((*family* ^(,af-inet ,*maybe-ipv6))) (unless (dgram-test) (error "test failed"))))) diff --git a/tests/014/socket-basic.tl b/tests/014/socket-basic.tl index 1b4464fb..ae591c9b 100644 --- a/tests/014/socket-basic.tl +++ b/tests/014/socket-basic.tl @@ -1,12 +1,12 @@ (load "../sock-common.tl") (load "../common.tl") -(defvar socktype) +(defvar *socktype*) -(defvar %iters% (if (meql (os-symbol) :macos :openbsd) 2000 5000)) +(defvarl %iters% (if (meql (os-symbol) :macos :openbsd) 2000 5000)) (defun client (addr) - (with-stream (cli-sock (open-socket af-inet socktype)) + (with-stream (cli-sock (open-socket af-inet *socktype*)) (sock-connect cli-sock addr) (put-string "5000" cli-sock) (sock-shutdown cli-sock) @@ -19,7 +19,7 @@ (close-stream acc-sock))) (defun sock-test () - (let* ((svc-sock (open-socket af-inet socktype)) + (let* ((svc-sock (open-socket af-inet *socktype*)) (svc-addr (bindfree svc-sock 1025 65535)) (child-pid (fork))) (cond @@ -29,6 +29,6 @@ (if (and (fboundp 'open-socket) (fboundp 'fork)) - (each ((socktype (list sock-dgram sock-stream))) + (each ((*socktype* (list sock-dgram sock-stream))) (unless (sock-test) (error "test failed")))) -- cgit v1.2.3