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

Using special argv vector in IF control flow statement returns error #8

Closed
carbontwelve opened this issue Mar 5, 2019 · 4 comments
Closed

Comments

@carbontwelve
Copy link

carbontwelve commented Mar 5, 2019

Given the following code:

DATA:
i IS NUMBER
local.min IS NUMBER
local.max IS NUMBER

PROCEDURE:
STORE 0 IN i
WHILE i IS LESS THAN argc DO
    IF i IS EQUAL TO 0 THEN
        STORE argv:i IN local.min
        STORE argv:i IN local.max
    END IF

    IF argv:i IS LESS THAN local.min THEN
        STORE argv:i IN local.min
    END IF

    IF argv:i IS GREATER THAN local.max THEN
        STORE argv:i IN local.max
    END IF

    ADD i AND 1 IN i
REPEAT
DISPLAY "Min (" local.min ") Max (" local.max ")" CRLF

I get the Error: Malformed statement error for line 14 being IF argv:i IS LESS THAN local.min THEN.

If I assign argv:i to a variable it works:

STORE argv:i IN n
IF n IS LESS THAN local.min THEN

Is this a bug or a feature?

@Lartu
Copy link
Owner

Lartu commented Mar 5, 2019

Hi there! That's the intended behavior. Argv is a TEXT vector, so you should first store the value in a NUMBER variable, thus converting it to a NUMBER, and then use it in the IF.

@carbontwelve
Copy link
Author

Hi, thank you for your reply. I don't think that the documentation makes that clear - it may be worth amending the documentation with a note on correct usage of Argv.

@Lartu
Copy link
Owner

Lartu commented Mar 6, 2019

Hi, thank you! It's noted here: http:https://ldpl.lartu.net/reference/#cliargs. Argv is just like any other TEXT VECTOR. Is there anything in particular you think is not clear enough so I can correct it?

@carbontwelve
Copy link
Author

If I understand you correctly the issue in my code wasn't using IF argv:i but that I was doing a NUMBER comparison on a TEXT type value therefore necessitating the STORE as a NUMBER variable in order to work on it.

That does make sense and the documentation as a whole does describe type conversion very well. I figured out the issue almost as soon as the error returned - I look forward to better errors ;)

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