Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 00:49

    xiaq on master

    Document performance improvemen… (compare)

  • 00:41

    xiaq on master

    pkg/eval: Reorganize benchmarks… pkg/eval: Execute the last form… (compare)

  • Dec 01 17:13
    mqudsi commented #1351
  • Dec 01 17:13
    mqudsi commented #1351
  • Dec 01 02:19
    krader1961 commented #1373
  • Nov 30 19:23
    zzamboni commented #1427
  • Nov 30 19:06
    crinklywrappr commented #1427
  • Nov 30 18:52
    zzamboni commented #1427
  • Nov 30 09:33
    fennewald commented #1372
  • Nov 30 09:33
    fennewald commented #1372
  • Nov 30 09:28
    fennewald commented #1372
  • Nov 30 02:48
    krader1961 commented #1427
  • Nov 30 02:08
    krader1961 commented #1426
  • Nov 30 02:01
    krader1961 commented #1430
  • Nov 30 01:47

    xiaq on master

    Use onclick="" to make :hover w… (compare)

  • Nov 30 01:37

    xiaq on master

    Tweak styling of header anchors… (compare)

  • Nov 30 01:14
    xiaq closed #1426
  • Nov 30 01:14

    xiaq on master

    website: Add anchor link for ea… (compare)

  • Nov 30 00:20
    xiaq commented #1426
  • Nov 29 23:53
    xiaq commented #1426
iandol
@iandol:matrix.org
[m]
printf %X requires an integer input, but the output from rand is a floating point number, how to convert number types?
iandol
@iandol:matrix.org
[m]
printf "%X" (num (to-string (math:floor (* (rand) 16))))
I tried converting to string and back to num but it keeps the original type
iandol
@iandol:matrix.org
[m]
OK if I remove the decimal part of the string with a re I can get a value out:
printf '%X' (num (re:replace '\..+' '' (to-string (math:floor (* (rand) 16)))))
C
xiaqqaix (Telegram)
@telegram_84517825:elv.sh
[m]
You can use randint
To coerce a float to an integer, use exact-num (https://elv.sh/ref/builtin.html#exact-num), but this won't be necessary if you just use randint
iandol
@iandol:matrix.org
[m]
zQueal (Telegram):
⟨~⟩❯ time { openssl rand -hex 32 }
1a842fd564b717c03ff26c548969fb7a464ce5433b493ca0138ddda0cb5f79fd
3.40442ms
⟨~⟩❯ time { xxd -p -l 32 < /dev/random }
5f50370c64f8dd92ed62f7094db69ac1b6f68d338ccb093aa1dbb15a36d10af6
2.714123ms
⟨~⟩❯ time { echo (for i [(range 0 64)] { printf '%X' (randint 0 15) }) }
B584A4D97B106D76DA3253329CAA4C550880C8B73CD4D1C5DE8DEDBB98E28C16
4.562052ms
iandol
@iandol:matrix.org
[m]
fn repeat-each {|n f|
    for i [(range 0 $n)] { $f }
}
fn hexstring {|n|
    put (repeat-each $n { printf '%X' (randint 0 15) })
}
hexstring 64
▶ DC2E53D059495689B6ABED1E5A11EC04A17CA79E9484D6EA7460C857B4244ADE
xiaqqaix (Telegram)
@telegram_84517825:elv.sh
[m]
You should use (randint 0 16), otherwise you'll never get F
iandol
@iandol:matrix.org
[m]
printf '%X' 15
F
ah you mean randint is not inclusive?
ok you're right randint 14 15 never returns 15
iandol
@iandol:matrix.org
[m]
$low is inclusive and $high is exclusive...
Both ruby and python are inclusive for both $low and $high, e.g. ruby -e "puts rand(0..2)"
xiaqqaix (Telegram)
@telegram_84517825:elv.sh
[m]
Python's range and random.randrange both use [low, high). So does slicing in Python and Go
iandol
@iandol:matrix.org
[m]
python3 -c 'import random; print(random.randint(0, 2))' returns 0 1 and 2
xiaqqaix (Telegram)
@telegram_84517825:elv.sh
[m]
That's randint
iandol
@iandol:matrix.org
[m]
yes, but it has the same name as the elvish command
anyway, should I can create a pull request to add the detail of the inclusivity to the randint documentation?
xiaqqaix (Telegram)
@telegram_84517825:elv.sh
[m]
iandol
@iandol:matrix.org
[m]
I didn't know [ and ) had these meanings, I thought it was a typo 😂
xiaqqaix (Telegram)
@telegram_84517825:elv.sh
[m]
Right, I suppose not every Elvish user is familiar with the notation
iandol
@iandol:matrix.org
[m]
I'm sure I'm not the only casual user who doesn't know this terminology
so a clarification may still be helpful?
xiaqqaix (Telegram)
@telegram_84517825:elv.sh
[m]
added a link to the wikipedia article on interval terminology in https://elv.sh/ref/builtin.html#randint
iandol
@iandol:matrix.org
[m]

how about adding an explicit sample in the doc, e.g.

Output a pseudo-random integer N in the half-open interval [$low, $high) such that $low <= N < $high.

Then no need to go to read the article in wikipedia (thanks for the link however!)
wording is similar to the python doc: https://docs.python.org/3/library/random.html#random.randint
1 reply
iandol
@iandol:matrix.org
[m]
xiaqqaix (Telegram): did you ever think about adding a builtin help command, it would be great to be able to do help randint and get the function comment from the source echoed in the terminal...
2 replies
iandol
@iandol:matrix.org
[m]

:point_up: Edit: how about also adding an explicit sample in the doc, e.g.

Output a pseudo-random integer N in the half-open interval [$low, $high) such that $low <= N < $high.

zQueal (Telegram)
@telegram_56630627:elv.sh
[m]
Built in help, like with Vim would be chef's kiss
meng zhao
@shizhaojingszj
图像 183.png
图像 183.png
any ideas?
I'm using elvish in WSL
xiaqqaix (Telegram)
@telegram_84517825:elv.sh
[m]
Can't see your question
meng zhao
@shizhaojingszj
this is powerline theme from github.com/muesli/elvish-libs/theme/powerline
I mean the powerline has wield chars
OMG, maybe due to the windows terminal I'm using, this is not a elvish issue. Sorry.
zQueal (Telegram)
@telegram_56630627:elv.sh
[m]
Probably need a patched nerd font.
meng zhao
@shizhaojingszj
Yes, I will try that.
iandol
@iandol:matrix.org
[m]
Nice that $low is now optional 👍️
Kurtis Rader
@krader1961:matrix.org
[m]

What do people think about supporting this syntax for executing a loop N times:

range 10 {|i|
    f(i)
}

See elves/elvish#1433

5 replies
meng zhao
@shizhaojingszj
Is there any way to mimic bash/zsh 's 'Ctrl+X Ctrl+E' to open editor in elvish shell?
Kurtis Rader
@krader1961:matrix.org
[m]

Yes. I have this in my ~/.config/elvish/rc.elv:

# Arrange for [alt-e] and [alt-v] to edit the current command buffer using my
# prefered external editor.
set edit:insert:binding[Alt-e] = $interactive:external-edit-command~
set edit:insert:binding[Alt-v] = $interactive:external-edit-command~

You can obviously change that basic idea to match your preferred invocation sequence.

meng zhao
@shizhaojingszj
Great! Thanks a lot!
Kurtis Rader
@krader1961:matrix.org
[m]
@shizhaojingszj: My interactive: module is not part of the standard Elvish config. It is part of my personal Elvish config which looks like this:
fn external-edit-command {
  var temp-file = (path:temp-file)
  print $edit:current-command > $temp-file
  try {
    # This assumes $E:EDITOR is an absolute path. If you prefer to use
    # just the bare command and have it resolved when this is run use
    # (external $E:EDITOR)
    $E:EDITOR $temp-file[name] </dev/tty >/dev/tty 2>&1
    set edit:current-command = (slurp < $temp-file[name])[..-1]
  } finally {
    file:close $temp-file
    rm $temp-file[name]
  }
}
meng zhao
@shizhaojingszj
OK, thanks for sharing. It works like a charm. @krader1961:matrix.org
# binding:
# @krader1961:matrix.org 
use path
use file
E:EDITOR = (which vim)
fn external-edit-command {
  var temp-file = (path:temp-file)
  print $edit:current-command > $temp-file
  try {
    # This assumes $E:EDITOR is an absolute path. If you prefer to use
    # just the bare command and have it resolved when this is run use
    # (external $E:EDITOR)
    $E:EDITOR $temp-file[name] </dev/tty >/dev/tty 2>&1
    set edit:current-command = (slurp < $temp-file[name])[..-1]
  } finally {
    file:close $temp-file
    rm $temp-file[name]
  }
}
# Arrange for [alt-e] and [alt-v] to edit the current command buffer using my
# prefered external editor.
set edit:insert:binding[Alt-e] = $external-edit-command~
set edit:insert:binding[Alt-v] = $external-edit-command~
meng zhao
@shizhaojingszj
Any good support of sth. like eval $(ssh-agent) in bash?
hhanche (Telegram)
@telegram_558831502:elv.sh
[m]

It's a bit tricky, since there are several ways a program like ssh-agent could choose to print the relevant commands. Assuming the output has the form export FOO=bar …, I would go for parsing the output in elvish:

ssh-agent -s |
eawk [_ @args]{ if (eq $args[0] export) {
for arg $args[1..] {
var @p = (str:split '=' $arg &max=2)
if (== (count $p) 2) { set-env $@p } } } }

meng zhao
@shizhaojingszj
Oh, I searched in this thread and find sth. like:
alias:new sshagent bash -c "eval $(ssh-agent);"(which elvish)
Not ideal, but looks easier to me.