underscore at end of identifier

6 views
Skip to first unread message

Ralf Hemmecke

unread,
Jul 27, 2026, 12:38:54 PM (9 days ago) Jul 27
to fricas-devel
I just want to share a little experience ...

I introduced a variable

__foo__ := "blah"

and then typed

__foo__

on the next line and pressed ENTER. The cursor jumps to the next line,
but no output appeared. I wondered why for such a simple thing the
evaluation takes so long and pressed ENTER again and the result was
printed immediately.

Well, after a little thought, it is clear what happened. The last
twounderscores are not interpreted as an escaped underscore but rather
the last underscore is taken to escape the following newline, so the
fricas session is actually waiting for more input.

So although one could think that a double underscore just counts as a
single underscore that belongs to an identifier, obviously line
concatenation comes first.

Well, I don't think it is worth changing that, because letting
identifiers end in an underscore is not common in FriCAS, but I realized
something else.

Isn't the output below a bit weird. In particular why are there two
underscores in (12)? I thought the third underscrore just escapes the
newline and the previous two contract to just one underscore.
It is completely unclear why (12) does not give foo_bar as output.

Ralf

PS: There is probably no need to change anything. I just wanted to share
this experience.


%%% (11) -> foo_
bar

(11) foo_bar

%%% (12) -> foo__
bar
There are no library operations named foo_
Use HyperDoc Browse or issue
)what op foo_
to learn if there is any operation containing " foo_ " in its
name.

Cannot find a definition or applicable library operation named foo_
with argument type(s)
Variable(bar)

Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need.

%%% (12) -> foo___
bar

(12) foo__bar

Ralf Hemmecke

unread,
Jul 27, 2026, 12:52:59 PM (9 days ago) Jul 27
to fricas...@googlegroups.com
As I understand, an underscore at the beginning of an identifier must be
doubled in the input to mean that there is just one underscore in the
identifier.

%%% (15) -> __foo := "bar"

(15) "bar"

This actually defines the identifier _foo internally.

%%% (16) -> __foo

(16) "bar"

%%% (17) -> )clear prop __foo

%%% (17) -> __foo

(17) "bar"

Why does this variable keep its value? There is obviously a difference
in handling underscores in SPAD and on a )clear line.
Isn't that a bit confusing for a user?

%%% (18) -> _foo

(18) foo

That is clear, since just one underscore escapes the initial f and that
gives f.

%%% (19) -> )clear prop _foo

%%% (19) -> __foo

(19) _foo

%%% (20) -> _foo

(20) foo

Ralf

Waldek Hebisch

unread,
Jul 28, 2026, 4:09:03 PM (8 days ago) Jul 28
to 'Ralf Hemmecke' via FriCAS - computer algebra system
On Mon, Jul 27, 2026 at 06:52:55PM +0200, 'Ralf Hemmecke' via FriCAS - computer algebra system wrote:
> As I understand, an underscore at the beginning of an identifier must be
> doubled in the input to mean that there is just one underscore in the
> identifier.
>
> %%% (15) -> __foo := "bar"
>
> (15) "bar"
>
> This actually defines the identifier _foo internally.
>
> %%% (16) -> __foo
>
> (16) "bar"
>
> %%% (17) -> )clear prop __foo
>
> %%% (17) -> __foo
>
> (17) "bar"
>
> Why does this variable keep its value? There is obviously a difference in
> handling underscores in SPAD and on a )clear line.
> Isn't that a bit confusing for a user?

Yes, it is. Unfortunatly several function do not use scanner to get
symbols, but simply take space-delimited sequence of characters
and treats it as symbol name. Sometimes functions use some
ad-hoc handling of underscores (that used to be the case with
older HyperDoc search). We should fix this.

> %%% (18) -> _foo
>
> (18) foo
>
> That is clear, since just one underscore escapes the initial f and that
> gives f.
>
> %%% (19) -> )clear prop _foo
>
> %%% (19) -> __foo
>
> (19) _foo
>
> %%% (20) -> _foo
>
> (20) foo
>

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