PtcRunner.Lisp.Runtime.FlexAccess (PtcRunner v0.10.1)

Copy Markdown View Source

Flexible key access helpers for PTC-Lisp runtime.

These helpers allow accessing map keys using either atom or string versions, with hyphen/underscore normalization for seamless interoperability between Clojure-style keywords (:turn-summaries) and Elixir-style keys (:turn_summaries).

Lookup order

  1. Exact match (atom or string as given)
  2. Atom↔string variant (:foo"foo" or vice versa)
  3. Hyphen↔underscore normalized variant (:turn-summaries:turn_summaries, "turn_summaries")

Summary

Functions

Flexible key fetch: try both atom and string versions of the key. Returns {:ok, value} if found, :error if missing. Use this when you need to distinguish between nil values and missing keys.

Flexible nested key fetch: try both atom and string versions at each level. Returns {:ok, value} if found, :error if missing.

Flexible key access: try atom/string and hyphen/underscore variants of the key. Returns the value if found, nil if missing. Use this for simple lookups where you don't need to distinguish between nil values and missing keys.

Flexible nested key access: try both atom and string versions at each level.

Flexible nested key insertion: creates intermediate maps as needed at each level. Aligns with Clojure's assoc-in behavior.

Flexible nested key update: creates intermediate maps as needed at each level. Aligns with Clojure's update-in behavior.

Functions

flex_fetch(map, key)

Flexible key fetch: try both atom and string versions of the key. Returns {:ok, value} if found, :error if missing. Use this when you need to distinguish between nil values and missing keys.

flex_fetch_in(data, arg2)

Flexible nested key fetch: try both atom and string versions at each level. Returns {:ok, value} if found, :error if missing.

flex_get(map, key)

Flexible key access: try atom/string and hyphen/underscore variants of the key. Returns the value if found, nil if missing. Use this for simple lookups where you don't need to distinguish between nil values and missing keys.

flex_get_in(data, arg2)

Flexible nested key access: try both atom and string versions at each level.

flex_put_in(data, path, v)

Flexible nested key insertion: creates intermediate maps as needed at each level. Aligns with Clojure's assoc-in behavior.

flex_update_in(data, path, f)

Flexible nested key update: creates intermediate maps as needed at each level. Aligns with Clojure's update-in behavior.