Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 03:30
    krader1961 commented #1163
  • 03:07
    krader1961 commented #952
  • Oct 20 04:56
    krader1961 commented #1143
  • Oct 20 04:33
    krader1961 edited #1019
  • Oct 20 04:32
    krader1961 edited #1176
  • Oct 20 04:32
    krader1961 commented #680
  • Oct 20 03:36
    krader1961 commented #1170
  • Oct 20 03:29
    krader1961 commented #1170
  • Oct 20 03:22
    krader1961 synchronize #1170
  • Oct 20 03:16
    krader1961 opened #1176
  • Oct 20 02:47
    krader1961 opened #1175
  • Oct 19 04:19
    krader1961 commented #1173
  • Oct 19 04:08
    krader1961 commented #1170
  • Oct 19 03:36
    krader1961 synchronize #1170
  • Oct 18 04:01
    krader1961 opened #1174
  • Oct 18 03:57
    krader1961 commented #857
  • Oct 18 03:02
    krader1961 commented #1145
  • Oct 18 03:01
    krader1961 synchronize #1145
  • Oct 18 02:45
    krader1961 commented #1173
  • Oct 18 02:44
    krader1961 opened #1173
mesajor
@mesajor
[chengxuncc(telegram)] #!/usr/bin/env elvish
fn hello {
echo hello
}
echo running function $args[0]
$args[0]
[chengxuncc(telegram)] I want to run this script by
./make.elv hello
mesajor
@mesajor

[hhanche(telegram)] You can't do it that way, because elvish does not (currently at least) give you first class access to the top level namespace. But here is one possible solution:

!/usr/bin/env elvish

fun = [&]
fn fun [key val]{ fun[$key] = $val }
fun hello {
echo hello
}
echo running function $args[0]
$fun[$args[0]]

[hhanche(telegram)] If you want it to be able to run external commands as well, you would have to check if the named command is in the $fun map, and invoke instead (external $args[0]).
[hhanche(telegram)] … otherwise
(I forgot to add that word at the end of the above)
mesajor
@mesajor
[chengxuncc(telegram)] Where does $fun variable come from
[hhanche(telegram)] I create it at the very beginning.
[hhanche(telegram)] [&] denotes an empty map.
mesajor
@mesajor
mesajor
@mesajor
[donjoe:nanashi0x74.dev(matrix)] yo, should there be a manual entry for elvish or isn't there one yet?
[donjoe:nanashi0x74.dev(matrix)] for me man elvish returns no manual entry
mesajor
@mesajor
[hhanche(telegram)] No, there is no man page for elvish. Run elvish —help for a brief description of the possibilities.
mesajor
@mesajor
[chengxuncc(telegram)] I don't know why my telegram miss a message on desktop, now I see it, I will try it ASAP. (re @hhanche: I create it at the very beginning.)
mesajor
@mesajor

[chengxuncc(telegram)] It work like a magic, thank you very much. (re @hhanche: You can't do it that way, because elvish does not (currently at least) give you first class access to the top level namespace. But here is one possible solution:

!/usr/bin/env elvish

fun = [&]
fn fun [key val]{ fun[$key] = $val }
fun hello {
echo hello
}
echo running function $args[0]
$fun[$args[0]])

mesajor
@mesajor

[donjoe:nanashi0x74.dev(matrix)] > <@mesajor:matrix.org> [hhanche(telegram)] No, there is no man page for elvish. Run elvish —help for a brief description of the possibilities.

Is there any possibility to browse the language documentation locally and not on the website?

Steven E. Harris
@seh

Yes, @xiaq, I have experience with Clojure and a little bit of Haskell (more reading than writing), as well as the Common Lisp SERIES library. The various stream and channel abstractions in Java come to mind too.

When I saw that Elvish has a constantly function, I assumed—wrongly—that it must have lazily evaluated sequences. Reading the documentation again today, though, I realized that it's a function, but not necessarily a stream generator.

By the way, Common Lisp had constantly before Clojure.

mesajor
@mesajor
[hhanche(telegram)] Reading the language docs locally: You could in principle download the html files and then load your local copy into your web browser. There seems to be only one supporting file (a css file) in addition to the html. Or, if you feel adventurous, the source at github also contains the documentation source. But then you need also the requisite tools for building the docs.
[hhanche(telegram)] It ought to be possible to build a streams abstraction in elvish. The thought has crossed my mind once or twice, but I never got around to looking seriously into it. Maybe when I retire next hear. 🤔
Steven E. Harris
@seh
What is the difference between for x $xs { ... } and each [x]{ ... } $xs?
Steven E. Harris
@seh

@krader1961

Earlier you had suggested this might work:

fn x [y @rest]{ put $y $@rest }

When I try calling that as put 1 2 3 | x "foo", the $@rest value is always empty.

mesajor
@mesajor
[SolitudeSF(telegram)] you need to handle piping yourself
Steven E. Harris
@seh
Can you clarify that?
mesajor
@mesajor
[SolitudeSF(telegram)] you need to implement the behavior you want yourself, there is no builtin magic for varargs to consume the pipe.
Steven E. Harris
@seh
We did see an example above last night. Perhaps I'm misinterpreting what it was showing.
That one showed it "working" when the function only accepted one "rest argument."
mesajor
@mesajor
[SolitudeSF(telegram)] each collects the pipe
Steven E. Harris
@seh
Oh, interesting. Passing $@rest to each isn't even necessary:
fn x [@rest]{ each [x]{ put "x: "$x } }
mesajor
@mesajor
[hhanche(telegram)] all to the rescue:
fn x [y @rest]{ put $y (all $@rest) }
Steven E. Harris
@seh

I was trying to write a filter function. Here is my current attempt:

fn filter [pred @rest]{
  each [e]{
    if ($pred $e) {
      put $e
    }
  }
}

However, when I call it like this, it fails:

put 0 1 2 3 | filter [e]{ put ($e > 1) }

The error is:

Exception: bad value: command must be callable or string containing relative path, but is string

That is, drop any supplied integral elements that are less than or equal to one.
Steven E. Harris
@seh
Oh, that's infix notation!
Switching it to put (> $e 1) works as intended—so far.
Steven E. Harris
@seh

I wrote my first "real" program in Elvish, which mostly involves generating a few maps, serializing them as JSON, and feeding that JSON into an external program.

A few things I missed:

  • A command-line flag binding and parsing library
    (I didn't stop to try to build one)
  • Clearer understanding of when parentheses are required around an expression
  • Clearer understanding of when to use piped values versus collecting them into an array and passing that as an argument
2 replies
mesajor
@mesajor
[SolitudeSF(telegram)] > Clearer understanding of when parentheses are required around an expression
always? if you want to capture the result
[SolitudeSF(telegram)] i built a simple cli parsing lib https://github.com/SolitudeSF/argp but its not tested, since im not using it.
[SolitudeSF(telegram)] - Clearer understanding of when to use piped values versus collecting them into an array and passing that as an argument
when you have the data that can be processed continuously, you probably should pipe it
[SolitudeSF(telegram)] also its pretty slow, but its rare case where i wont blame myself for that. (re @SolitudeSF: i built a simple cli parsing lib https://github.com/SolitudeSF/argp but its not tested, since im not using it.)
Steven E. Harris
@seh
Thank you. It's great to find a large file of Elvish code like that to study. I'll spend some time with argp this afternoon.
1 reply
Kurtis Rader
@krader1961
Making a local copy of the Elvish documentation is easy:
> cd website
> make clean
> make
The results are in the _dst directory which you can access using a local file:// URL or copy it to your web server (e.g., cp -pr . ~/www/elvish).
Přemysl Eric Janouch
@pjanx
Elvish could be made to support Midnight Commander, I think, even with this new feature https://midnight-commander.org/ticket/4114
Given the internal "file manager", I'm not sure if it's worth pursuing.
Kurtis Rader
@krader1961
@pjanx Have you tried Elvish’s “navigation” mode (normally bound to Ctrl-N)?
Kurtis Rader
@krader1961
@donjoe:nanashi0x74.dev Regarding a man page see elves/elvish#786
Přemysl Eric Janouch
@pjanx
I have my own "navigator" and managed to integrate it with elvish, that's what makes me think mc should work.
Kurtis Rader
@krader1961
Last time I used Midnight Commander was the 1990’s. So I don’t really know what it means to use it in the context of a shell like Elvish. But Elvish issues that talk about fzf are probably relevant: https://github.com/elves/elvish/issues?q=is%3Aissue+is%3Aopen+fzf
mesajor
@mesajor
[Prashant(telegram)] 16
mesajor
@mesajor
[SolitudeSF(telegram)] if a program requires proper cli, i would use my main language.
1 reply
[SolitudeSF(telegram)] yes, Nim in my case