WolframResearch / wstp-rs

Rust bindings to the Wolfram Symbolic Transport Protocol (WSTP)
Apache License 2.0
21 stars 3 forks source link

feature: Add Expr::get_expr_with_resolver() #26

Closed ConnorGray closed 2 years ago

ConnorGray commented 2 years ago

This is an experimental feature intended to provide a workaround for the problem that the Wolfram Kernel does not always write symbol expressions with their complete context.

For example, the symbol SystemList may be written as the string "List" and not "SystemList". That means that the context of "List" is ambiguous when being read off of the link by Link::get_expr().

Link::get_expr_with_resolver() works around this problem by using a user-provided callback function to handle any ambiguous symbols. The user function can choose how to handle them. Doing this in a naive way (e.g. assuming every ambiguous symbol is in the System` context) is a hacky workaround, but sufficient for simple use-cases.

A more robust method would be to ask the Kernel explicitly for the context, e.g. by evaluating Context["List"]. But that has performance considerations, and is not easy to do in the middle of get_expr().