[ prog / sol / mona ]

prog


[Challenge] Guile scsh porting

1 2020-06-21 18:00

Every time someone complains about Guile's scsh port, you are obliged to post a patch here to improve it.

Use this as the base: https://gitlab.com/guile-scsh/guile-scsh

Happy hacking!

2 2020-06-21 18:01

This fixes the issues that make it unable to run on Guile 3.0.2: https://paste.textboard.org/37618cbc

3 2020-06-21 19:22

Meta: What does Guile scsh offer over bash (besides being probably more hackable)? Is it kind of like Eshell?

4 2020-06-22 01:21

>>1
Good one.

5 2020-06-22 08:05

Who wants to adopt the repo?

6 2020-06-24 23:35

Help me out, why work on guile-scsh instead of gash?

7 2020-06-25 06:38

>>3,6
I don't exactly get what the hype around scsh is, but I think the idea is the following:

Unix shells provide a single language for two purposes: 1) interactively executing commands, and 2) writing scripts. It is clear that they were designed for the first case, the second being only an afterthought. I think Eshell is only capable of the first one. Meanwhile, scsh was designed for scripting and programming, with proper lexical scoping, data-structures, everything a programmer could want (coming from Scheme), but with a convenient interface to the system that resembles the ease-of-use provided by the shell.

Meanwhile Gash is an implementation of the POSIX sh.

8 2020-06-25 10:21

>>7
So how does it differ from a Scheme implementation with a POSIX library?

9 2020-06-25 16:20

>>8
Flip through the manual: https://scsh.net/docu/html/man.html

I think the most important is the process notation. Here's an example from the manual:

(run (| (delatex)
        (begin ((char-filter char-downcase))) ; tr A-Z a-z
        (spell)
        (sort)
        (uniq))
     (< scsh.tex)
     (> spell-errors.txt))

The begin is Scheme, the rest are shell commands.

10 2020-06-25 20:11

(begin ((char-filter char-downcase))) ; tr A-Z a-z
The begin is Scheme

Since it is given one argument, it is much more likely to be a custom, redefined begin, not the standard one.

11 2020-06-25 20:46

>>10
It is the `escape-to-scheme' case of the process forms, it behaves like `begin' but is run in a fork. For example:

(run (pipe
      (begin
        (display "Hello SchemeBBS!")
        (newline)
        (display "How are you doing?")
        (newline))
      (wc -l)))

This will output 2.

It is a somewhat common mistake in bash to try to modify the environment of the parent shell from a child shell in a pipeline. Here it is in scsh:

(let ((maximum 0))
  (run (pipe
        (seq 100)
        (begin
          (let loop ((l (read-line)))
            (when (not (eof-object? l))
              (when (> (string->number l) maximum)
                (set! maximum (string->number l)))
              (display l)
              (newline)
              (loop (read-line)))))
        (wc -l)))
  (display (list 'maximum maximum)))
12


VIP:

do not edit these