c3c icon indicating copy to clipboard operation
c3c copied to clipboard

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

Open tebokial opened this issue 9 months ago • 3 comments

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 ...

tebokial avatar Mar 13 '25 18:03 tebokial

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

lerno avatar Mar 13 '25 21:03 lerno

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 ...

tebokial avatar Mar 14 '25 10:03 tebokial

Hello,

You asked for additional info, here it is.

Go to https://learn-c3.org/More/16/ which is the Named Arguments example. Do Copy and Run => output is as expected.

Now in my local v0.6.8 install of c3c : after copying the source into a file, and compiling it, I get the following console output:

=========================================================================== @.***:~/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 it looks like the C3-tutorial example is out of sync with the current state C3 ... and a noob like me gets confused ...

Greetings, Herman / tebokial

tebokial avatar Mar 17 '25 20:03 tebokial