zsh-workers
 help / color / mirror / code / Atom feed
From: dana <dana@dana.is>
To: "Clinton Bunch" <cdb_zsh@zentaur.org>
Cc: "Zsh hackers list" <zsh-workers@zsh.org>
Subject: Re: [PATCH] zsh/random module
Date: Fri, 04 Nov 2022 02:27:22 -0500	[thread overview]
Message-ID: <41205a86-8aad-4821-baa4-1d2ac9bf3c5d@app.fastmail.com> (raw)
In-Reply-To: <1e8ea669-7a25-b321-6024-72dbc43ac023@zentaur.org>

On Fri 4 Nov 2022, at 01:22, Clinton Bunch wrote:
> Then why would you use the builtin in preference to the parameter SRANDOM?

I guess the main reason would be for the bounds functionality

On Fri 4 Nov 2022, at 01:22, Clinton Bunch wrote:
> Copied that pattern straight out of Src/Modules/datetime.c

TIL. I also lied about sysread, it does the same. print/printf, zparseopts,
and zstyle don't. Can't think of anything else off the top of my head rn

On Fri 4 Nov 2022, at 01:22, Clinton Bunch wrote:
> Trying to think how to design tests when the output is different every
> time by design.

If nothing else it could just make sure it's in the expected format

On Fri 4 Nov 2022, at 01:22, Clinton Bunch wrote:
> And I can't think what a completion function would
> complete.  It's not like it's using long options or enumerated arguments.

Most of zsh's built-ins have no long options but they still have completion
functions. Some people use completion as a substitute for the documentation.
Attached _getrandom for your consideration (assumes no further changes, tested
very minimally)

btw, in writing that function i realised a few things:

* In the documentation, i think the default upper bound should be 4294967295
  rather than 4294967296

* Why is the maximum length 64? Also, should that value be documented?

* If you put -i after -L/-U it overrides their effect. Maybe the
  `if (integer_out)` in the code should be an `else if` instead?

* It appears that -L is inclusive but -U is exclusive. e.g. if you do
  `getrandom -l1 -L2 -U3` it will only ever return 2. I assume that's not
  intentional?

On Fri 4 Nov 2022, at 01:22, Clinton Bunch wrote:
> It still seems weird that the dev guide specifies mixing the two.

I agree

dana


diff --git a/Completion/Zsh/Command/_getrandom b/Completion/Zsh/Command/_getrandom
new file mode 100644
index 000000000..3513e10b7
--- /dev/null
+++ b/Completion/Zsh/Command/_getrandom
@@ -0,0 +1,12 @@
+#compdef getrandom
+
+local min=0 max=$(( 2 ** 32 - 1 ))
+
+_arguments -s -S : \
+  '(-r -s)-a+[assign result to specified array parameter]:array parameter:_parameters -g "*array*~*readonly*"' \
+  '(-a)-s+[assign result to specified scalar parameter]:scalar parameter:_parameters -g "*(integer|scalar)*~*readonly*"' \
+  '(-r)-i[produce random data as 32-bit unsigned integers]' \
+  '-l+[specify length of data]: :_numbers -d8 -l1 -m64 -u "bytes or integer elements" "data length"' \
+  '(-i -L -U)-r[produce random data as raw bytes]' \
+  '(-r)-L+[specify integer lower bound (implies -i)]: :_numbers -d$min -l$min -m$max "integer lower bound"' \
+  '(-r)-U+[specify integer upper bound (implies -i)]: :_numbers -d$max -l$min -m$max "integer upper bound"'


  reply	other threads:[~2022-11-04  7:29 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02 17:13 Clinton Bunch
2022-11-03 17:50 ` Bart Schaefer
2022-11-04  3:17 ` dana
2022-11-04  6:22   ` Clinton Bunch
2022-11-04  7:27     ` dana [this message]
2022-11-04 12:57       ` Clinton Bunch
2022-11-08  0:18         ` [PATCH] zsh/random module [UPDATED] Clinton Bunch
2022-11-18 14:30           ` Clinton Bunch
2022-11-19  6:42             ` Lawrence Velázquez
2022-11-18 16:23           ` Stephane Chazelas
2022-11-18 17:08             ` Clinton Bunch
2022-11-18 18:12               ` Stephane Chazelas
2022-11-18 18:38                 ` Clinton Bunch
2022-11-23 19:52                   ` Daniel Shahaf
2022-11-24 16:19                     ` Stephane Chazelas
2022-11-24 16:30                       ` Roman Perepelitsa
2022-11-24 22:39                         ` Clinton Bunch
2022-11-25  8:53                           ` Stephane Chazelas
2022-11-25  9:40                             ` Stephane Chazelas
2022-11-28 16:37                               ` further discussion of zsh/random (was [PATCH] zsh/random module [UPDATED]) Clinton Bunch
2022-11-21  1:07           ` [PATCH] zsh/random module [UPDATED] Matthew Martin
2022-11-21  1:59             ` Clinton Bunch
2022-11-21  2:21               ` Matthew Martin
2022-11-21  2:57                 ` Clinton Bunch
2022-11-21  3:14                   ` Lawrence Velázquez
2022-11-21  4:17                     ` Bart Schaefer
2022-11-21  5:05                       ` Clinton Bunch
2022-11-22 13:42                         ` dana
2022-11-23 19:49                         ` Daniel Shahaf
2022-11-22 17:44                       ` Oliver Kiddle
2022-11-22 19:48                         ` Clinton Bunch
2022-11-23  1:23                   ` Matthew Martin
2022-11-23  2:58                     ` Clinton Bunch
2022-11-23  4:14                       ` Matthew Martin
2022-11-23 13:41                         ` Clinton Bunch
2022-11-23 20:33                           ` Daniel Shahaf
2022-11-23 21:42                             ` dana
2022-11-23 23:54                               ` Daniel Shahaf
2022-11-24  0:17                                 ` Daniel Shahaf
2022-11-24  1:05                                 ` dana
2022-11-24 13:52                               ` Clinton Bunch
2022-11-23 19:46           ` Daniel Shahaf
2022-11-24  2:58             ` Clinton Bunch
2022-11-24 10:07               ` nimaje+zml
2022-11-24 13:19                 ` Clinton Bunch
2022-11-24 14:33             ` Clinton Bunch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41205a86-8aad-4821-baa4-1d2ac9bf3c5d@app.fastmail.com \
    --to=dana@dana.is \
    --cc=cdb_zsh@zentaur.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).