/
choose-curly-bracket.fs
63 lines (48 loc) · 1.29 KB
/
choose-curly-bracket.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
\ galope/choose-curly-bracket.fs
\ `choose{`
\ Random selection for a compiled set of double cells.
\ This file is part of Galope
\ http://programandala.net/en.program.galope.html
\ Author: Marcos Cruz (programandala.net), 2011, 2012, 2013, 2014,
\ 2016, 2017.
\ Description: Tools to compile several strings and return one of them
\ by chance at run-time.
\ ==============================================================
require random.fs \ Gforth's `random`
require ./choose-stack.fs
require ./choose.fs
\ ==============================================================
\ Operators
: choose{ ( -- ) depth >choose-stack ;
\ doc{
\
\
\ choose{ ( -- )
\
\ Start a set of single-cell numbers to choose from.
\
\ Usage example:
\ ----
\ choose{ my-variable @ 1 8 16 }choose .
\ ----
\
\ See: `}choose`, `2choose{`.
\
\ }doc
: }choose ( x1 .. xn -- x' ) depth <choose-stack - choose ;
\ doc{
\
\ }choose ( x1 .. xn -- x' )
\
\ Chose a random _x'_ from the set _x1 .. xn_
\ stacked since the last unresolved `choose{`.
\
\ See: `}2choose`.
\
\ }doc
\ ==============================================================
\ Change log
\ 2016-07-22: Copy, modify and rename `s{ }s` from the old module
\ <random_strings.fs>
\
\ 2017-10-26: Improve documentation.