Skip to content

Channels and printing in runtime evaluation #1531

@pyrmont

Description

@pyrmont

Description
Using a channel for print operations in runtime evaluation results in strange behaviour.

Steps to Reproduce

  1. Run this code.
    (def c (ev/chan))
    
    (ev/spawn
      (while (def v (ev/take c))))
    
    (defn print-to-chan [x]
      (ev/give c x))
    
    (setdyn :out print-to-chan)
    (def res
      (eval-string
        "(defn x []
           (pp :foo)
           (pp :bar)
           :qux)
         (x)"))
    (ev/chan-close c)
    (setdyn :out nil)
    (print "Result is " res)

Expected Result
The code outputsResult is qux.

Actual Result
The actual output on my Mac is for the string Result is to appear.

Notes
This is an intentionally contrived example that tries to simplify the problem to its maximum extent. The context in which I came across this is in developing my own evaluation environment for a REPL project I’m working on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions