[ prog / sol / mona ]

prog


[Challenge] Guile scsh porting

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