• Clojure threading in scheme.

    From Alain De Vos@21:1/5 to All on Sat Nov 13 09:20:28 2021
    Clojure has a syntax for left to right evaluation and pipeline. https://clojure.org/guides/threading_macros
    Does there exist a similar function in scheme ?
    Or a similar function in scheme with a name be coded in a few lines of code.
    I think you apply on the expression left and that output is then the input of the expression on the right etc...
    It allows to read nested expressions from left to right which is more like the natural language.

    I have found rackjure but this is only an implementation of racket.
    It would be nice to do something similar in chez-scheme

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Vine@21:1/5 to Alain De Vos on Sat Nov 13 17:56:50 2021
    On Sat, 13 Nov 2021 09:20:28 -0800 (PST)
    Alain De Vos <devosalain71@gmail.com> wrote:
    Clojure has a syntax for left to right evaluation and pipeline. https://clojure.org/guides/threading_macros
    Does there exist a similar function in scheme ?
    Or a similar function in scheme with a name be coded in a few lines of code. I think you apply on the expression left and that output is then the input of the expression on the right etc...
    It allows to read nested expressions from left to right which is more like the natural language.

    I have found rackjure but this is only an implementation of racket.
    It would be nice to do something similar in chez-scheme

    I don't know clojure but it is relatively simple to make your own
    pipeline macro, if that is what you are after. Here's one approach:

    (define-syntax ->
    (lambda (x)
    (syntax-case x ()
    [(_ exp0 exp1 ...)
    (let ([reversed (reverse #'(exp0 exp1 ...))])
    (with-syntax
    ([out
    (let loop ([first (car reversed)]
    [rest (cdr reversed)])
    (if (null? rest)
    first
    (syntax-case first ()
    [(func arg0 ...)
    (append #'(func arg0 ...)
    (list (loop (car rest) (cdr rest))))])))])
    #'out))])))

    You can also do it with syntax-rules:

    (define-syntax ->
    (syntax-rules ()
    [(-> exp)
    exp]
    [(-> exp ... (op args ...))
    (op args ... (-> exp ...))]))

    Expressions are evaluated left to right, rather like ML's |>
    operator. So usage of these is thus:

    "hello"
    (format #t "~A~%"))

    In that example the pipeline expression itself evaluated to
    undefined (the return value of format), but it could evaluate to
    anything.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)