diff options
author | Freya Murphy <freya@freyacat.org> | 2024-02-29 17:04:28 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-02-29 17:04:28 -0500 |
commit | 5d2747e26f51cc2344a6bd95f93457248fdfebd8 (patch) | |
tree | 8755b4068166c3854d26817683ce438a771ab319 /matrix-std/src/core.rs | |
parent | more mat, sys, and os stdlib functions, better matrix printing, other fixes (diff) | |
download | matrix-5d2747e26f51cc2344a6bd95f93457248fdfebd8.tar.gz matrix-5d2747e26f51cc2344a6bd95f93457248fdfebd8.tar.bz2 matrix-5d2747e26f51cc2344a6bd95f93457248fdfebd8.zip |
fin prob
Diffstat (limited to '')
-rw-r--r-- | matrix-std/src/core.rs (renamed from matrix-stdlib/src/core.rs) | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/matrix-stdlib/src/core.rs b/matrix-std/src/core.rs index 2c76497..69b6d97 100644 --- a/matrix-stdlib/src/core.rs +++ b/matrix-std/src/core.rs @@ -1,10 +1,8 @@ -use std::hash::{DefaultHasher, Hash, Hasher}; - -use matrix::{vm::Vm, value::Value, unpack_args, Result, unpack_varargs}; -use matrix_macros::native_func; +use std::hash::{DefaultHasher, Hasher}; use rand::Rng; -use crate::{VmArgs, next, error}; - +use matrix_lang::prelude::*; +use matrix_macros::native_func; +use crate::{VmArgs, next, error, unpack_args, unpack_varargs}; fn to_radix(r: i64, mut n: i64) -> String { let mut result = String::new(); @@ -123,11 +121,8 @@ fn remove(_: VmArgs, args: Vec<Value>) -> Result<Value> { #[native_func(1)] fn hash(_: VmArgs, args: Vec<Value>) -> Result<Value> { let [value] = unpack_args!(args); - if let Err(e) = value.can_hash() { - return Err(e) - }; let mut hasher = DefaultHasher::new(); - value.hash(&mut hasher); + value.try_hash(&mut hasher)?; let fin = hasher.finish(); Ok(Value::Int(fin as u32 as i64)) } @@ -201,8 +196,10 @@ fn sort(_: VmArgs, args: Vec<Value>) -> Result<Value> { let Value::List(mut list) = value else { return error!("sort requires a list") }; - let hi = list.len() - 1; - quicksort(list.as_mut(), 0, hi); + if list.len() > 1 { + let hi = list.len() - 1; + quicksort(list.as_mut(), 0, hi); + } Ok(Value::List(list)) } |