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

Unclear output of IF "FALSE #182

Open
jasonsikes opened this issue May 2, 2024 · 2 comments
Open

Unclear output of IF "FALSE #182

jasonsikes opened this issue May 2, 2024 · 2 comments

Comments

@jasonsikes
Copy link

The IF command outputs the result of the instruction list if the condition is TRUE.

That enables the user to, for example:

MAKE "MESSAGE IF :USERNAME = "jsmith ["Welcome!]
PRINT :MESSAGE

What is the output if the condition is FALSE?

Of course, my example IS bad programming practice and probably should result in an error. It's just that the error message is unclear; an empty list is a list.

? show if "false ["hello]
Macro returned [] instead of a list
@brianharvey
Copy link
Collaborator

Oh gosh it's a terrible error message, because a user of IF shouldn't have to know what a macro is! Really the message should be IF DIDN'T OUTPUT TO SHOW. Sorry!

The case of an IF with no else clause, when a value is expected, could be caught in advance with IF (VAL_STATUS == VALUE_OK) at coms.c line 236. That would be the usual thing, although Logo's general practice is to report errors as late as possible so that side effects happen. But this could be viewed as a syntax error I guess.

@jasonsikes
Copy link
Author

I suppose it could be a syntax error, but I agree that the most sensible error should be IF didn't output to SHOW.

It seems that after IF checks the condition, it outputs a list to be run as a macro. If the condition is FALSE the list will be empty. So UCBLogo treats:

IF tf instructionlist

as if the user wrote:

IFELSE tf instructionlist []

After some poking around, I found similar issues in a few other places. This is probably the simplest example:

SHOW RUN []
Macro returned [] instead of a list

It also happens when using IFT and IFF.

Oh, and don't feel sorry. UCBLogo is an excellent interpreter and language. As you guys probably know, I'm building my own interpreter, and I'm poking around UCBLogo testing edge cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants