Created
December 27, 2022 11:55
-
-
Save Oldes/61b9e49a6c19502f0834973df2bc5e26 to your computer and use it in GitHub Desktop.
Random names generator scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REBOL [ | |
Title: "Random names" | |
type: module | |
name: random-names | |
version: 0.0.1 | |
author: @oldes | |
exports: [random-names] | |
] | |
;; https://britishsurnames.co.uk/random | |
;; num: 50 | |
;; sex: ["a" "m" "f"] | |
;; type: ["current" "1881"] | |
;; submit: "go" | |
buffer: make block! 100 | |
random-names: function/with/extern [ | |
/into out [block!] | |
][ | |
txt: read https://britishsurnames.co.uk/random | |
;write %names.html txt | |
out: any [out make block! 100] | |
parse txt [ | |
thru "<h3>Random Names</h3>" | |
any [ | |
any whitespace | |
copy name: to whitespace | |
any whitespace | |
"<a" thru #">" | |
copy surname: to #"<" | |
thru "<br />" | |
( | |
append out ajoin [name #" " surname] | |
) | |
] | |
] | |
new-line/all out true | |
out | |
] :system/catalog/bitsets [buffer] | |
open-names: func [port [port!] /local spec conn][ | |
unless empty? buffer [return port] | |
random-names/into buffer | |
] | |
read-names: func [ | |
port [port!] | |
/part length [number!] | |
/local n | |
][ | |
length: any [length 1] | |
while [length > length? buffer][ | |
random-names/into buffer | |
] | |
n: random length? buffer | |
either part [ | |
take/part at buffer n length | |
][ take at buffer n ] | |
] | |
sys/make-scheme [ | |
name: 'names | |
title: "Random names generator" | |
spec: make system/standard/port-spec-head [ | |
host: %britishsurnames | |
] | |
actor: compose [ | |
open: (:open-names) | |
read: (:read-names) | |
] | |
] | |
;@@ Usage examples | |
;-- Single name: | |
;; probe read names:// | |
;-- Block of names: | |
;; probe read/part names:// | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment