v-community / v_by_example

Learn V by Example
https://v-community.gitbook.io/v-by-example/
MIT License
170 stars 30 forks source link

add match statement and variable examples #88

Closed spmse closed 4 years ago

spmse commented 4 years ago

add examples for match statement which was defined in issue 45.

Closes #45.

Ivo-Balbaert commented 4 years ago

The example: num2 := 3 s := match num2 { 1 { 'one' } 2 { 'two' } else { println('the input was not matched before') 'many' } }

gives an error on the println statement: expected type string, but got void If you leave it out, it works.

Ivo-Balbaert commented 4 years ago

Also: enum Animals should be enum Animal, so that the function definitions are consistent with the enum definition.

Ivo-Balbaert commented 4 years ago

Last comment: I think it is better to add code so that it is immediately executable, that way the user feels more confident and the code is tested(!) :

fn main() {
    cat1 := Animal.cat
    gf := Animal.goldfish
    println(makes_miau(cat1)) // true
    println(is_land_creature(cat1)) // true
    println(is_land_creature_alt(gf)) // false
}
spmse commented 4 years ago

Last comment: I think it is better to add code so that it is immediately executable, that way the user feels more confident and the code is tested(!) :

I just pushed tested code into code/match-statement with 1719d60 where you can see that println works in a match branch. The docs also say this, but I also noticed that it doesn't work compiling the example I created.

spmse commented 4 years ago

Also added execution examples to the .md file.

Ivo-Balbaert commented 4 years ago

Great!

From: Sven Patrick Meier [mailto:notifications@github.com] Sent: Thursday, November 28, 2019 11:46 AM To: v-community/v_by_example v_by_example@noreply.github.com Cc: ibalbaert ivo.balbaert@telenet.be; Comment comment@noreply.github.com Subject: Re: [v-community/v_by_example] add match statement example (#88)

Also added execution examples to the .md file.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/v-community/v_by_example/pull/88?email_source=notifications&email_token=AAHLG7F4D3IMINFU4UIPUSLQV6OPRA5CNFSM4JSM62OKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFMGVKA#issuecomment-559442600 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHLG7DO46MAZ77RE2BSLOTQV6OPRANCNFSM4JSM62OA . https://github.com/notifications/beacon/AAHLG7CQOFOBVDTZM63BO3LQV6OPRA5CNFSM4JSM62OKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFMGVKA.gif

vbrazo commented 4 years ago

@SuicideS3ason thanks for doing this. We need more maintainers to finish writing this book. You're welcome to collaborate more and be part of this.

spmse commented 4 years ago

Looking good. You should also update our README.md.

Done in 0cb785a 👍

@SuicideS3ason thanks for doing this. We need more maintainers to finish writing this book. You're welcome to collaborate more and be part of this.

I would love to do that, thank you!

spmse commented 4 years ago

I think indentation should 4 spaces.

should be 4. at least my config says so. 🙈

spmse commented 4 years ago

now it should be correct everywhere.

dhonx commented 4 years ago

Hahaha... yeah... it hurts until vfmt works 😁

spmse commented 4 years ago

haha yeah, but wasn't a vfmt thing, files on my computer still have correct indentation, but somehow github changed it during push. 😄

spmse commented 4 years ago

@SuicideS3ason thanks for doing this. We need more maintainers to finish writing this book. You're welcome to collaborate more and be part of this.

I just wanted to ask shortly what it means to be maintainer, or if this was an invitation to be maintainer for this project? 🙈 It's my first time contributing in an open source project, but I would love to help you guys!

dhonx commented 4 years ago

@SuicideS3ason https://github.com/v-community/v_by_example/invitations 😉