Skip to content

Conversation

@kmr-srbh
Copy link
Contributor

fixes#2669

print("a", "b", "c", "d") fruits: list[str] = ["apple", "guava", "mango"] mango: str=fruits.pop() print("I have got a", mango, "to eat!")
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.pya b c dI have got a mango to eat!

@kmr-srbh
Copy link
ContributorAuthor

@Shaikh-Ubaid could you please rerun the CI? The failing check is unrelated to the PR.

@ubaidsk
Copy link
Collaborator

The approach in this PR might break lfortran. lfortran needs to not print spaces when two consecutive print arguments are strings.

% cat examples/expr2.f90 program expr2implicit noneprint *, "hi", "bye"print *, 12, 23end program % gfortran examples/expr2.f90  % ./a.out  hibye 12 23 % lfortran examples/expr2.f90hibye12 23

if (global_sep_space &&
!(ASRUtils::is_character(*ASRUtils::expr_type(x.m_values[i]))
&& ASRUtils::is_character(*ASRUtils::expr_type(x.m_values[i - 1])))){
if (global_sep_space){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way to fix this such that we print spaces when two consecutive arguments are strings in LPython and not print spaces for the same in LFortran, is to support this in AST->ASR Translation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to figure out how to update the middle-ends of both lfortran and lpython such that both of them work as expected when two consecutive arguments are strings.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shaikh-Ubaid thanks for this! I will try to create a solution that works for both. 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if your solution works for both lpython and lfortran (test it locally on your system or send a PR to lfortran so it gets tested at the CI). If no run reference tests change for lfortran, then it works.

You can also test your current approach with lfortran. If it works currently, then I think its good.

@ubaidskubaidsk marked this pull request as draft April 26, 2024 18:36
@kmr-srbhkmr-srbhforce-pushed the add-space-between-strings-in-print branch from c52e653 to 6fc0b6aCompareApril 27, 2024 05:06
@kmr-srbhkmr-srbh changed the title Add space between multiple strings in printAdd space between multiple strings while printingApr 29, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Printing multiple strings together does not add a space between them

2 participants

@kmr-srbh@ubaidsk