Skip to content

Handling multiple effects without with? #618

Answered by TimWhiting
osa1 asked this question in Q&A
Discussion options

You must be logged in to vote

If you are just avoiding with due to the scoping issue, I would just create a local variable for the result, and use an indented block
This is how I usually limit the scope of with

  val result = // A local value can be defined in an indented block (since every block is also an expression)
    with handler
      fun random-int32()
        num
    // game will be run under this handler, and the handler will not be in scope after.
    game()
  with handler
    ctl readline1()
      match inputs
        Cons(line, nextLines) ->
          inputs := nextLines
          resume(line)
        Nil ->
          throw-exn(Exception(message = "blah", info = ExnAssert))

    ctl println1(s: string)
  …

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@osa1
Comment options

@chtenb
Comment options

Comment options

You must be logged in to vote
1 reply
@osa1
Comment options

Answer selected by osa1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants