From: bakaq Date: Fri, 16 Aug 2024 03:34:46 +0000 (-0300) Subject: Fix lists of chars as strings X-Git-Tag: v0.10.0~117^2~2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=8736526b355e6756b1047a9615610e40171cac52;p=scryer-prolog.git Fix lists of chars as strings --- diff --git a/src/machine/parsed_results.rs b/src/machine/parsed_results.rs index 305e6a4d..cedbc9f0 100644 --- a/src/machine/parsed_results.rs +++ b/src/machine/parsed_results.rs @@ -194,6 +194,20 @@ impl Value { let head = term_stack.pop().unwrap(); let list = match tail { + Value::Atom(atom) if atom == "[]" => match head { + Value::Atom(ref a) if a.chars().collect::>().len() == 1 => { + // Handle lists of char as strings + Value::String(a.to_string()) + } + _ => Value::List(vec![head]), + }, + Value::List(elems) if elems.is_empty() => match head { + Value::Atom(ref a) if a.chars().collect::>().len() == 1 => { + // Handle lists of char as strings + Value::String(a.to_string()) + }, + _ => Value::List(vec![head]), + }, Value::List(mut elems) => { elems.insert(0, head); Value::List(elems) @@ -213,13 +227,6 @@ impl Value { Value::List(elems) } }, - Value::Atom(atom) if atom == "[]" => match head { - Value::Atom(ref a) if a.chars().collect::>().len() == 1 => { - // Handle lists of char as strings - Value::String(a.to_string()) - } - _ => Value::List(vec![head]), - }, _ => Value::Structure(".".into(), vec![head, tail]), }; term_stack.push(list);