trueagi-io / metta-wam

A Hyperon MeTTa Interpreter/Transpilier that targets the Warren Abstract Machine
10 stars 11 forks source link

Unicode Character Misrepresentation #145

Open TeamSPoon opened 1 month ago

TeamSPoon commented 1 month ago

When running a MeTTa script in SWI-Prolog version 9.3.11, Unicode characters such as "ɑ" (Latin small letter alpha) are not handled correctly in the output. The output is expected to show proper handling of the Unicode character, but instead, it displays an incorrect representation (\u0251) in some cases when using mettalog and metta commands.

Steps to Reproduce:

  1. Create a test file with the following contents:

    !(bind! &ex1 (new-space))
    !(add-atom &ex1 (y y (ɑ 0)))
    !(add-atom &ex1 (x z (ɑ 0)))
    !(add-atom &ex1 ((ɑ 0) 1 A))
    
    (= (name $x) (case $x (
      ((ɑ $n) (format-args "ɑ{}" ($n)))
      ($k (format-args "n{}" ($k)))
    )))
    (= (graphviz-triple ($x $p $y))
      (let* (($xn (name $x)) ($pn (name $p)) ($yn (name $y)))
        (format-args "{} -> {} [label=\"{}\"]"
          ($xn $yn $pn)
    )))
    (= (graphviz $space)
      (println! (graphviz-triple (get-atoms $space)))
    )
    !(graphviz &ex1)
  2. Run the script with mettalog command:

    mettalog tests/baseline_compat/anti-regression/issues/metta-wam-issue-145/print_graph.metta

Expected Behavior:

The output should display the Unicode character "ɑ" correctly, as in:

ny -> ɑ0 [label="ny"]
nx -> ɑ0 [label="nz"]
ɑ0 -> nA [label="n1"]

Actual Behavior:

The output is displaying a Unicode escape sequence instead of the actual character:

ny -> \u02510 [label="ny"]
nx -> \u02510 [label="nz"]
\u02510 -> nA [label="n1"]

System Information:

Additional Context:

Running the same script using the metta command works as expected and displays the Unicode character "ɑ" correctly, but when using mettalog, the issue occurs. The mettalog output is mishandling the Unicode characters, while metta works fine. The issue may be related to stream encoding settings in mettalog.

TeamSPoon commented 1 month ago

Also need to buffer the output from the answers

image