Skip to content

07: Side Effect Free Passing of Parameters #169

@dschwartznyc

Description

@dschwartznyc

Feature Request

There is a semantic mismatch between Rune and Python regarding parameter handling. Rune expects functions to be side-effect free, effectively treating parameters as immutable or passed-by-value.

In contrast, Python uses pass-by-assignment. When mutable objects (like lists or classes) are passed into a generated Python function, any modification to those objects reflects in the caller's scope, violating Rune’s functional integrity.

The Java implementation solves this by:

  1. Using "Holders" and "Builders."
  2. Performing a .toBuilder() call on assignment (effectively cloning).
  3. Returning a .build() result.

Current Failure Case:

In the following Rune snippet, the holder should remain unchanged in the calling scope. In the current Python generator, updated would simply be a reference to holder, and add would mutate the original object.

type IntHolder:
    items int (0..*)

func AddItemToHolder:
    inputs:
        holder IntHolder (1..1)
        value int (1..1)
    output:
        updated IntHolder (1..1)

    set updated: holder
    add updated -> items: value

Potential Solutions:

The Python Runtime and Generator must replicate "pass-by-value" behavior. There are two primary alternatives:

  1. Eager Copying: Deep-copy all mutable inputs upon function entry.
  2. Copy-on-Write (CoW): Use a wrapper that only clones the underlying data if a mutation (like add or set) is attempted.

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