Mangled String?

5 views
Skip to first unread message

Grégory Vanuxem

unread,
Apr 23, 2026, 2:16:30 PM (2 days ago) Apr 23
to fricas...@googlegroups.com
Hello,

I am stuck with a String issue that I do not understand, maybe you can understand it. Basically, I have a small interface (package) to BrowserInformation and the String returned by the following function is apparently mangled. That does not happen for every operations. I attached the Spad file for testing purpose.

    getOperationDocumentation(op) ==
      ops := search_operations(string op)$BrowserInformation
      docs := coerce(ops)@List(Record(name: Symbol,
        sdl: List(Record(signature: SExpression,
          condition: SExpression, origin: SExpression,
            documentation: String))))
      res_str : String := ""
      for ops_rec in docs repeat
        for item in elt(ops_rec, sdl) repeat
          cleaned := clean_tex(elt(item, documentation))
          sl := cons(convert('Mapping)$SExpression,
            destruct(elt(item, signature)))
          sig_str : String := concat [" Signature: ",
            form2LispString(sl)$Lisp pretend String]
          ori_str : String := concat [" From: ",
            form2LispString(elt(item, origin))$Lisp pretend String]
          -- Debug purpose
          PRINT(concat [cleaned, coerce(newline()),
            sig_str, coerce(newline()), ori_str, coerce(newline()), coerce(newline())])$Lisp
          res_str := concat [res_str, cleaned, coerce(newline()),
            sig_str, coerce(newline()), ori_str, coerce(newline()), coerce(newline())]
      res_str

The PRINT$Lisp is here for debug. As an example, here is the output when I apply it to the debug function:

===========================================================================
(3) -> getOperationDocumentation(debug)

"debug(d) specifies whether we want additional output on the progress. This option is expressed in the form debug == d.
 Signature: (Boolean)->%
 From: GuessOption

"
"debug(true) turns debug mode on debug(false) turns debug mode off
 Signature: (Boolean)->Boolean
 From: Plot

"
"debug returns whether we want additional output on the progress, default being false
 Signature: (List(GuessOption))->Boolean
 From: GuessOptionFunctions0

"
   (3)
  "debug(d) specifies whether we want additional output on the progress. This o
  ption is expressed in the form debug == d.
 Signature: (Boolean)->%
 From: Gu
  essOption

debug(true) turns debug mode on debug(false) turns debug mode off

   Signature: (Boolean)->Boolean
 From: Plot

debug returns whether we want add
  itional output on the progress, default being false
 Signature: (List(GuessOp
  tion))->Boolean
 From: GuessOptionFunctions0

"
                                                                 Type: String
==================================================================

The first part is the PRINT debug information, but after the (3), in the string returned I obtain some _apparently_ random space characters or carriage return.
For example, see the first "From:", the GuessOption is mangled. In the third part this is in the "Signature:". In fact, that can happen in the docstring also. Any idea why? And eventually a hack to circumvent this?

Hoping I am clear.

Greg

sdoc.spad

Qian Yun

unread,
Apr 23, 2026, 10:21:00 PM (2 days ago) Apr 23
to fricas...@googlegroups.com
OK, this is a side effect of

)set output length


Even if your string contains "\n", fricas considers it as
one long string, and cuts it up when exceeding the above limit.

- Qian
> --
> You received this message because you are subscribed to the Google
> Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to fricas-devel...@googlegroups.com <mailto:fricas-
> devel+un...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/fricas-
> devel/
> CAHnU2dZX8uJT6rDVtPy6PmiAUDBYFfm5tjiNOB1TzPDiU_FC7w%40mail.gmail.com
> <https://groups.google.com/d/msgid/fricas-devel/
> CAHnU2dZX8uJT6rDVtPy6PmiAUDBYFfm5tjiNOB1TzPDiU_FC7w%40mail.gmail.com?
> utm_medium=email&utm_source=footer>.

Grégory Vanuxem

unread,
Apr 24, 2026, 12:29:50 AM (yesterday) Apr 24
to fricas...@googlegroups.com
Oh thanks Qian!

In fact I usually use a line length of 110, I reverted it to 77 to see the change, I did not notice this.

Since this interface is not only designated to be used in the interpreter, but also for use by the MCP server I am coding, I suppose I will have to play with $LINELENGTH related code and 'pile' also a List of OutputForm in another routine.

Good!

BTW, I am pretty sure the Waldek's code for HyperDoc can do better than some part I did but I must admit, its code is beyond my actual knowledge.

Greg


To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/fricas-devel/b5764b5d-ceaf-4cc8-8256-e4b0af38833c%40gmail.com.
Reply all
Reply to author
Forward
0 new messages