Skip to content

Capturing things outside the env #8

Description

@keynmol

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions