Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input format, ";", ":", ";\" #274

Open
slazav opened this issue Mar 12, 2023 · 4 comments
Open

input format, ";", ":", ";\" #274

slazav opened this issue Mar 12, 2023 · 4 comments
Labels
bug An actual bug enhancement Not strictly a bug but more of a feature enhancement request

Comments

@slazav
Copy link

slazav commented Mar 12, 2023

The cadabra book says Lines always have to be terminated with either a “;” or a “:”.

In cadabra2-cli 2.4.2 this works with expressions "a:=something", but not with algorithms.
Algorithm with ":" produces an "invalid syntax" error.
Algorithm with ";" works as expected, with output.
Algorithm without ";" or ":" works without output, but does not modify "_" expression:

#!/usr/bin/cadabra2-cli

a:= a = a1:
substitute($b=b1$, $b1=b2$);
substitute(a, $a1=a2$)

print("print(_):", _)
print("print(a):", a)

Output ('_' contains result of first substitute, not last one):

b = b2
print(_): b = b2
print(a): a = a2

Adding '\' after substitute($b=b1$, $b1=b2$); suppresses output of this line and makes the next line to set "_". This is the only way I found to stack multiple algorithms with using "_" and without producing output.

It would be good to have better documentation to understand this behaviour...

@kpeeters kpeeters added bug An actual bug enhancement Not strictly a bug but more of a feature enhancement request labels Mar 12, 2023
@kpeeters
Copy link
Owner

Yeah, this is a bit of a weird left-over from the days that Cadabra did not use Python for its programming language. If I ever find a few hours of spare time just sitting in a corner, I'll clean this up :-(

@slazav
Copy link
Author

slazav commented Mar 12, 2023

Another related thing: ";" in the beginning of a line produces strange results.

ex :=
  a + b
;

does not work as expected, replacing ";" with ":" or adding space before ";" changes things.

@matiasdahl
Copy link

matiasdahl commented Jul 26, 2023

Potentially related.

Running the below script

A := u -> 1.
_;
A;
B := u -> 2.
_;
A;
B;

outputs

u → 1
u → 1
u → 2
u → 2   (<-- expected output from A; would be u->1)
u → 2

So the command "A;" prints two different outputs

Ubuntu, Cadabra 2.3.6 (build private dated 2022-01-31)

(edit: clearer variable names)

@kpeeters
Copy link
Owner

The first issue is, on second thought, actually intended. The logic is that if you use ; to display the last expression, then _ gets assigned a reference to the last expression. If you don't do that (if you do not terminate that substitute(...) with a ;) then _ remains unchanged. A simple workaround is

a:= a = a1:
substitute($b=b1$, $b1=b2$);
_ = substitute(a, $a1=a2$)

That is: set the 'last expression' variable '_' manually.

The other issues are now solved in 2248d92 (on the microtex branch, will become master soon).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An actual bug enhancement Not strictly a bug but more of a feature enhancement request
Projects
None yet
Development

No branches or pull requests

3 participants