Update series definition to infer schema
The `series` function no longer requires an explicit schema. The element type is now inferred at compile time from subsequent `push` calls using Hindley-Milner type inference. This simplifies series creation and aligns with the project's goal of making the untyped AST simple while the system handles complexity.
This commit is contained in:
@@ -64,14 +64,14 @@ pub fn register(env: &Environment) {
|
||||
let final_layout = RecordLayout::get_or_create(fields);
|
||||
Value::Series(Rc::new(RecordSeries::new(final_layout, lookback_limit)))
|
||||
}
|
||||
_ => panic!("series expects a lookback_limit and a type keyword (:float, :int...) or a schema record (e.g., {{:price :float}})"),
|
||||
_ => panic!("series: second arg must be a type keyword (:float, :int…) or a schema record ({{:field :type}})"),
|
||||
}
|
||||
},
|
||||
).doc("Creates a new series (ring buffer) with a defined layout and lookback limit.")
|
||||
.description("First arg is the lookback limit (int), second is either a type keyword (:float, :int, :bool, :text, :datetime) or a schema record ({:field :type}).")
|
||||
).doc("Creates a new series (ring buffer) with the given lookback limit.")
|
||||
.description("Takes a single lookback limit (int). The element type is inferred at compile time from subsequent push calls via HM type inference. The compiler injects a second schema argument automatically; the runtime also accepts an explicit schema for cases where inference is not possible.")
|
||||
.examples(&[
|
||||
"(series 100 :float)",
|
||||
"(series 200 {:price :float :volume :int})",
|
||||
"(series 100)",
|
||||
"(do (def s (series 5)) (push s 1.5) (s 0))",
|
||||
]);
|
||||
|
||||
// (push series value) -> Void
|
||||
|
||||
Reference in New Issue
Block a user