gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-scheme] 01/05: data-string: Eliminate mutation of variables.


From: gnunet
Subject: [gnunet-scheme] 01/05: data-string: Eliminate mutation of variables.
Date: Wed, 31 Aug 2022 13:30:17 +0200

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a commit to branch master
in repository gnunet-scheme.

commit dbbb55f03dbbe3c4db76fa0aabc5c66a28b6af31
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Wed Aug 31 12:08:20 2022 +0200

    data-string: Eliminate mutation of variables.
    
    This should make the code more understandable.
    
    * gnu/gnunet/data-string.scm (data->string): Eliminate set!.
---
 gnu/gnunet/data-string.scm | 44 ++++++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/gnu/gnunet/data-string.scm b/gnu/gnunet/data-string.scm
index 041d382..54150d0 100644
--- a/gnu/gnunet/data-string.scm
+++ b/gnu/gnunet/data-string.scm
@@ -53,26 +53,30 @@ of the C implementation.
 @var{size}: length of data to encode, in octets"
       ((bv) (data->string bv 0 (bytevector-length bv)))
       ((bv offset size)
-       (let loop ((vbit 0) (rpos offset) (bits 0) (accumulated '()))
-         (if (or (< (- rpos offset) size) (> vbit 0))
-             (begin
-               (when (and (< (- rpos offset) size) (< vbit 5))
-                (set! bits (bitwise-ior (bitwise-arithmetic-shift-left bits 8)
-                                        (bytevector-u8-ref bv rpos)))
-                (set! rpos (+ 1 rpos))
-                (set! vbit (+ vbit 8)))
-               (when (< vbit 5)
-                (set! bits (bitwise-arithmetic-shift-left bits (- 5 vbit)))
-                (assert (= vbit (mod (* 8 size) 5)))
-                (set! vbit 5))
-               (loop (- vbit 5) rpos bits
-                    (cons (string-ref charset
-                                      (bitwise-and
-                                       (bitwise-arithmetic-shift-right
-                                        bits (- vbit 5)) 31))
-                          accumulated)))
-             (begin (assert (= 0 vbit))
-                    (apply string (reverse accumulated))))))))
+       (let^ ((/o/ loop (vbit 0) (rpos offset) (bits 0) (accumulated '()))
+             (? (not (or (< (- rpos offset) size) (> vbit 0)))
+                (assert (= 0 vbit))
+                (apply string (reverse accumulated)))
+             (<-- (bits rpos vbit)
+                  (if (and (< (- rpos offset) size) (< vbit 5))
+                      (let^ ((! bits (bitwise-ior 
(bitwise-arithmetic-shift-left bits 8)
+                                                  (bytevector-u8-ref bv rpos)))
+                             (! rpos (+ 1 rpos))
+                             (! vbit (+ vbit 8)))
+                            (values bits rpos vbit))
+                      (values bits rpos vbit)))
+             (<-- (bits vbit)
+                  (if (< vbit 5)
+                      (begin
+                        (assert (= vbit (mod (* 8 size) 5)))
+                        (values (bitwise-arithmetic-shift-left bits (- 5 
vbit)) 5))
+                      (values bits vbit))))
+             (loop (- vbit 5) rpos bits
+                  (cons (string-ref charset
+                                    (bitwise-and
+                                     (bitwise-arithmetic-shift-right
+                                      bits (- vbit 5)) 31))
+                        accumulated))))))
 
   ;; TODO: appropriate supertype
   ;; TODO: fields!

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]