pub struct Symbol(/* private fields */);Expand description
Wolfram Language symbol.
§PartialOrd sorting order
The comparison behavior of this type is NOT guaranteed to match the behavior of
System`Order for symbols (and does not match it at the moment).
This type implements PartialOrd/Ord primarily for the purposes of allowing
instances of this type to be included in ordered sets (e.g. BTreeMap).
Implementations§
Source§impl Symbol
impl Symbol
Sourcepub fn try_new(input: &str) -> Option<Symbol>
pub fn try_new(input: &str) -> Option<Symbol>
Attempt to parse input as an absolute symbol.
An absolute symbol is a symbol with an explicit context path. "System`Plus" is
an absolute symbol, "Plus" is a relative symbol and/or a SymbolName.
"`Plus" is also a relative symbol.
Sourcepub fn new(input: &str) -> Symbol
pub fn new(input: &str) -> Symbol
Construct a symbol from input — stored verbatim, no validation.
Any string is accepted: a fully-qualified "System`Plus", a
context-less "Plus", or anything else. What goes into a symbol is the
caller’s business — we don’t police WL symbol syntax. A name the kernel
can’t make sense of is the caller’s problem, not ours.
let expr = Expr::normal(Symbol::new("MyPackage`Foo"), vec![]);Use Symbol::try_new if you want to validate the name first.
Examples found in repository?
176fn expr_string_join(link: &mut Link) {
177 let expr = link.get_expr().unwrap();
178
179 let ExprKind::Normal(list) = expr.kind() else {
180 panic!("expected a List, got: {:?}", expr);
181 };
182 assert!(list.has_head(&Symbol::new("System`List")));
183
184 let mut buffer = String::new();
185 for elem in list.elements() {
186 match elem.kind() {
187 ExprKind::String(str) => buffer.push_str(str),
188 _ => panic!("expected String argument, got: {:?}", elem),
189 }
190 }
191
192 link.put_str(buffer.as_str()).unwrap()
193}Sourcepub fn as_symbol_ref(&self) -> SymbolRef<'_>
pub fn as_symbol_ref(&self) -> SymbolRef<'_>
Sourcepub fn context(&self) -> ContextRef<'_>
pub fn context(&self) -> ContextRef<'_>
Get the context path part of a symbol as an ContextRef.
Sourcepub fn symbol_name(&self) -> SymbolNameRef<'_>
pub fn symbol_name(&self) -> SymbolNameRef<'_>
Get the symbol name part of a symbol as a SymbolNameRef.