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

C3-tutorial: in the "More" section, the "Named arguments" piece is out of date (at least that's my guess) #2045

Open
tebokial opened this issue Mar 13, 2025 · 2 comments
Labels
Additional info please Further information is requested

Comments

@tebokial
Copy link

With V0.6.8 as the current C3 release, I am working my way through the C3-tutorial. No problems in the "Basics" section. But under "More", the Namedarguments example reads :

import std::io;
fn void test(int x, double y)
{
io::printfn("%f", x + y);
}

fn void main()
{
test(.y = 3.0, .x = 1); => compiler error : expected an expression
test(3, 4.0);
test(15, .y = 3.141592);
}

On reading the reference, I first replaced that statement with : test(y: 3.0, x: 1) but then got another compiler error: named arg's must be in order ... which I corrected, now it runs fine. So no big deal (it's the curse of documenting), but still it's rather confusing ...

@lerno
Copy link
Collaborator

lerno commented Mar 13, 2025

Where is this exactly? Can you give me a link?

@lerno lerno added the Additional info please Further information is requested label Mar 13, 2025
@tebokial
Copy link
Author

Additional info : what I observe is not a bug in the C3-compiler, but a divergence between the current state of C3 and your interactive C3-tutorial. Specifically:

  1. Go to https://learn-c3.org/More/16/ which is the Named Arguments example. Do Copy and Run => output is as expected.
  2. Now in your local v0.6.8 install of c3c : copy the source into a file, and compile it: then I get the following console output:
    ===========================================================================
    herman@D830:~/c3-tutorial$ c3c compile namedargs_erroneous.c3
    7:
    8: fn void main()
    9: {
    10: test(.y = 3.0, .x = 1);
    ^
    (/home/herman/c3-tutorial/namedargs_erroneous.c3:10:7) Error: An expression was expected.
    ===========================================================================

The compiler errors go away when I change two things:
a) test(y: 3.0, x: 1); => now the compiler complains that I need to give the named args in order
b) test(x: 1, y: 3.0); Ok

So this C3-tutorial example is clearly out of sync with the current state C3 ... and a noob like me gets confused ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Additional info please Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants