Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capturing things outside the env #8

Open
keynmol opened this issue Oct 5, 2022 · 0 comments
Open

Capturing things outside the env #8

keynmol opened this issue Oct 5, 2022 · 0 comments

Comments

@keynmol
Copy link

keynmol commented Oct 5, 2022

Just listened to your talk :)

I asked about the captured bound identifiers which are not part of the env because I cannot make this snippet (scala-cli) fail at compile time:

//> using lib "com.phaller::spores3::0.1.0"

import com.phaller.spores.Spore
import com.phaller.spores.{Spore, SporeData, PackedSporeData}
import com.phaller.spores.upickle.given

val str = "anonymous function"
val BLA = "hello"
val s = Spore(str) { // `str` is the environment of the spore
  env => (x: Int) => x + env.length + BLA.length
}

val z = 25
object MySpore
    extends Spore.Builder[Int, Int, Int](env => (x: Int) => env + x + 1 + z)

import upickle.default._

@main def hello =
  val x = 12
  val data =
    SporeData(MySpore, Some(x)) // `x` is the environment, as before
  val pickledData = write(data)
  val unpickledData = read[PackedSporeData](pickledData)
  val unpickledSpore = unpickledData.toSpore[Int, Int]
  assert(unpickledSpore(3) == 16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant