Skip to content

Instantly share code, notes, and snippets.

@rebolek
Created September 1, 2019 07:46
Show Gist options
  • Save rebolek/7f7625a947bc56215cade200cef9b040 to your computer and use it in GitHub Desktop.
Save rebolek/7f7625a947bc56215cade200cef9b040 to your computer and use it in GitHub Desktop.
Make CSV from simple dialect
Red[
Dialect: {
pair! (req) - block size: record size x number of records
[MAX] integer! (opt) - value size: string length for values in records. MAX
switches to variable size
}
]
make-string: func [
"Return random string!"
length [integer!] "String size"
][
collect/into [
loop length [keep random/only "abcdefghijklmnopqrstuvwxyz"]
] make string! length
]
make-block: function [
"Make block of records from simple dialect"
desc [block!]
][
value-size: 8 ; default value size
variable-value-size?: false
record-size: 0
length: 0
parse desc [
set value pair! (
record-size: value/x
length: value/y
)
opt ['max (variable-value-size?: true)]
opt [set value-size integer!]
]
collect/into [
loop length [
keep/only collect/into [
loop record-size [
keep make-string either variable-value-size? [
random value-size
][
value-size
]
]
] make block! record-size
]
] make block! length
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment