]> gitweb.factorcode.org Git - factor.git/commitdiff
reservoir-sampling: cleanup example in docs
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 25 Aug 2023 00:47:47 +0000 (17:47 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 25 Aug 2023 00:48:15 +0000 (17:48 -0700)
basis/reservoir-sampling/reservoir-sampling-docs.factor

index badbaf057376b8985c006f7d9cfce94af3f3da8e..abc77ad0c948d269a5160698469a4e207ff1699f 100644 (file)
@@ -9,18 +9,25 @@ HELP: <reservoir-sampler>
 
 HELP: reservoir-sample
 { $values obj: object sampler: object }
-{ $description Feeds a sample to a \ reservoir-sampler which will maintain a vector of samples with equal probability. This word is especially useful when you do not know how many objects will appear but wish to sample them with equal probability, such as in a stream with unknown length. }
-{ $unchecked-example
-    [=[ 
-        USING: prettyprint io strings math reservoir-sampling
-        kernel accessors io.streams.string ;
-        
-        "Nothing will fundamentally change." [
-            10 <reservoir-sampler>
-            [ [ read1 dup ] swap '[ dup 1string . _ reservoir-sample ] while ] keep nip sampled>> >string .
-        ] with-string-reader
-        ""
-    ]=]
+{ $description
+    Feeds a sample to a \ reservoir-sampler which will maintain a vector of samples
+    with equal probability. This word is especially useful when you do not know how
+    many objects will appear but wish to sample them with equal probability, such
+    as in a stream with unknown length.
+
+    An example where characters from a string are sampled:
+    { $code
+        [=[
+            USING: prettyprint io strings math reservoir-sampling
+            kernel accessors io.streams.string ;
+
+            "Nothing will fundamentally change." [
+                10 <reservoir-sampler> [
+                    [ read1 ] swap '[ dup 1string . _ reservoir-sample ] while*
+                ] keep sampled>> >string .
+            ] with-string-reader
+        ]=]
+    }
 } ;
 
 HELP: reservoir-sample-iteration