synonym not working

20 views
Skip to first unread message

Fabian Hassler

unread,
Jan 21, 2024, 3:24:39 AM1/21/24
to FriCAS - computer algebra system
I have problems getting the command )synonym working. Most likely, I am just interpreting the documentation wrong.

As an example: if I execute `)synonym pwd system pwd` then )pwd appears in the list of synonyms whoever the body is empty. Also executing )pwd gives the error `Your argument list is not valid.` 

Qian Yun

unread,
Jan 21, 2024, 4:29:37 AM1/21/24
to fricas...@googlegroups.com
Yes, this is a bug.

After some glancing, this is a quick fix:

diff --git a/src/interp/i-syscmd.boot b/src/interp/i-syscmd.boot
index eca9f345..22bf47b0 100644
--- a/src/interp/i-syscmd.boot
+++ b/src/interp/i-syscmd.boot
@@ -2461,9 +2461,9 @@ processSynonymLine line ==
line := dropLeadingBlanks line
mx := MAXINDEX line
for i in 0..mx repeat
- line.i = " " =>
+ line.i = char '" " =>
return (for j in (i+1)..mx repeat
- line.j ~= " " => return (SUBSTRING (line, j, nil)))
+ line.j ~= char '" " => return (SUBSTRING (line, j, nil)))
[key, :value]



I need a deeper look into this. Seems that "synonymSpad2Cmd" is dead
code compared with "npProcessSynonym".

- Qian

Qian Yun

unread,
Jan 22, 2024, 6:38:15 AM1/22/24
to fricas...@googlegroups.com
I think this patch is much better.

Remove "dropLeadingBlanks", it is only used once.

Also removes manual loops, uses function instead.

- Qian

diff --git a/src/interp/g-util.boot b/src/interp/g-util.boot
index bba51e02..42cf4171 100644
--- a/src/interp/g-util.boot
+++ b/src/interp/g-util.boot
@@ -170,18 +170,6 @@ stringPrefix?(pref,str) ==
i := i + 1
ok

-dropLeadingBlanks str ==
- str := object2String str
- l := QCSIZE str
- nb := NIL
- i := 0
- while (i < l) and not nb repeat
- if SCHAR(str,i) ~= SCHAR('" ",0) then nb := i
- else i := i + 1
- nb = 0 => str
- nb => SUBSTRING(str,nb,NIL)
- '""
-
concat(:l) == concatList l

concatList [x,:y] ==
diff --git a/src/interp/i-syscmd.boot b/src/interp/i-syscmd.boot
index eca9f345..3337fd8c 100644
--- a/src/interp/i-syscmd.boot
+++ b/src/interp/i-syscmd.boot
@@ -2455,15 +2455,10 @@ synonymSpad2Cmd() ==
terminateSystemCommand()

processSynonymLine line ==
+ line := STRING_-LEFT_-TRIM('" ", line)
key := STRING2ID_N (line, 1)
- value := removeKeyFromLine line where
- removeKeyFromLine line ==
- line := dropLeadingBlanks line
- mx := MAXINDEX line
- for i in 0..mx repeat
- line.i = " " =>
- return (for j in (i+1)..mx repeat
- line.j ~= " " => return (SUBSTRING (line, j, nil)))
+ value := SUBSTRING(line, # STRINGIMAGE key, nil)
+ value := STRING_-LEFT_-TRIM('" ", value)
[key, :value]

Waldek Hebisch

unread,
Jan 22, 2024, 1:14:36 PM1/22/24
to fricas...@googlegroups.com
On Mon, Jan 22, 2024 at 07:38:10PM +0800, Qian Yun wrote:
> I think this patch is much better.
>
> Remove "dropLeadingBlanks", it is only used once.
>
> Also removes manual loops, uses function instead.

Looks OK.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages