├── Chapter_12_Advanced_Topics
├── foo.txt
├── doom
│ └── chocolate-doom
│ │ ├── pkg
│ │ ├── osx
│ │ │ ├── PkgInfo
│ │ │ ├── .gitignore
│ │ │ ├── Resources
│ │ │ │ ├── app.icns
│ │ │ │ ├── app.png
│ │ │ │ ├── 128x128.png
│ │ │ │ ├── wadfile.icns
│ │ │ │ ├── wadfile.png
│ │ │ │ └── launcher.nib
│ │ │ │ │ └── keyedobjects.nib
│ │ │ └── disk
│ │ │ │ ├── dir.DS_Store
│ │ │ │ └── background.png
│ │ ├── win32
│ │ │ ├── .gitignore
│ │ │ └── README
│ │ └── .gitignore
│ │ ├── autogen.sh
│ │ ├── data
│ │ ├── .gitignore
│ │ ├── doom.ico
│ │ ├── doom8.ico
│ │ ├── setup.ico
│ │ ├── setup.png
│ │ ├── setup8.ico
│ │ ├── Makefile.am
│ │ └── README
│ │ ├── src
│ │ ├── doom
│ │ │ └── .gitignore
│ │ ├── hexen
│ │ │ └── .gitignore
│ │ ├── strife
│ │ │ └── .gitignore
│ │ ├── heretic
│ │ │ └── .gitignore
│ │ ├── setup
│ │ │ ├── .gitignore
│ │ │ └── Setup.desktop.in
│ │ ├── Doom.desktop.in
│ │ ├── Hexen.desktop.in
│ │ ├── Heretic.desktop.in
│ │ ├── Strife.desktop.in
│ │ ├── Doom_Screensaver.desktop.in
│ │ ├── .gitignore
│ │ ├── manifest.xml
│ │ └── net_petname.h
│ │ ├── midiproc
│ │ ├── .gitignore
│ │ ├── Makefile.am
│ │ └── CMakeLists.txt
│ │ ├── textscreen
│ │ ├── .gitignore
│ │ ├── examples
│ │ │ ├── .gitignore
│ │ │ └── Makefile.am
│ │ └── fonts
│ │ │ ├── large.png
│ │ │ ├── small.png
│ │ │ ├── normal.png
│ │ │ └── Makefile.am
│ │ ├── man
│ │ ├── bash-completion
│ │ │ └── .gitignore
│ │ ├── wikipages
│ │ ├── CMDLINE.template
│ │ ├── CMDLINE.template.md
│ │ └── .gitignore
│ │ ├── opl
│ │ ├── .gitignore
│ │ ├── examples
│ │ │ ├── .gitignore
│ │ │ └── Makefile.am
│ │ ├── CMakeLists.txt
│ │ └── Makefile.am
│ │ ├── pcsound
│ │ ├── .gitignore
│ │ ├── CMakeLists.txt
│ │ └── Makefile.am
│ │ ├── ChangeLog
│ │ ├── AUTHORS
│ │ └── cmake
│ │ └── config.h.cin
├── unsafe1.v
├── a.out
├── .vs
│ ├── slnx.sqlite
│ ├── VSWorkspaceState.json
│ └── Chapter_12_Advanced_Topics
│ │ └── v16
│ │ ├── .suo
│ │ └── Browse.VC.db
├── call_c.v
├── hot_reload
│ ├── bounce.exe
│ ├── bounce.so
│ ├── glfw3.dll
│ ├── graph.exe
│ ├── graph.so
│ └── message.v
├── test.v
├── js_backend
│ └── hi.v
├── generics0.v
├── asm.v
├── test.cpp
├── message.v
├── send_a_value_to_another_thread.v
├── prime.v
├── sqlite3.v
└── prime_multi.v
├── Chapter_15_V_Software
├── vos
│ ├── vore
│ │ ├── LICENSE
│ │ ├── vlib
│ │ │ ├── runtime
│ │ │ │ ├── runtime_linux.v
│ │ │ │ ├── runtime_mac.v
│ │ │ │ ├── runtime_nix.v
│ │ │ │ └── runtime_win.v
│ │ │ ├── builtin
│ │ │ │ └── bare
│ │ │ │ │ └── voredef.v
│ │ │ └── crypto
│ │ │ │ ├── crypto.v
│ │ │ │ ├── md5
│ │ │ │ └── md5_test.v
│ │ │ │ ├── sha1
│ │ │ │ └── sha1_test.v
│ │ │ │ ├── sha256
│ │ │ │ └── sha256_test.v
│ │ │ │ ├── sha512
│ │ │ │ └── sha512_test.v
│ │ │ │ ├── rand
│ │ │ │ ├── rand.v
│ │ │ │ └── rand_mac.v
│ │ │ │ ├── rc4
│ │ │ │ └── rc4_test.v
│ │ │ │ └── aes
│ │ │ │ └── cypher_generic.v
│ │ ├── README.md
│ │ └── vore.h
│ ├── kernel
│ │ ├── sys
│ │ │ ├── debug.v
│ │ │ └── kmain.v
│ │ ├── vrt_main.c
│ │ ├── mm
│ │ │ └── paging.v
│ │ ├── arch
│ │ │ └── amd64
│ │ │ │ └── io.asm
│ │ └── io
│ │ │ └── io.v
│ ├── README.md
│ └── make_iso.sh
└── V-software.xlsx
├── Chapter_4_Basic_Types_Strings
├── chars.c
├── constants.c
├── multi_line.v
├── hello_world_inter.v
├── variables1.v
├── float.v
├── type_keyword.v
├── malloc.v
├── variables3.v
├── variables2.v
├── enums.exe
├── modulo_by_zero.v
├── exercises
│ ├── int_pointer.v
│ ├── interpol.v
│ ├── divby0.v
│ ├── pointer_error.v
│ ├── exercise2.v
│ ├── global_local.v
│ ├── exercise4_1.v
│ ├── swap.v
│ ├── if_enum.v
│ └── print_dollar.v
├── conversions.exe
├── statements.v
├── pointer_function.v
├── redefinition.v
├── dereferencing.v
├── nested_comments.v
├── variables4.v
├── bitwise.v
├── hello_world2.v
├── hello_world3.v
├── unused.v
├── pointer_deref.v
├── code_blocks.v
├── exit.v
├── program_without_main.v
├── generate_random.v
├── unions.v
├── struct_pointer.v
├── server_time.v
├── string_pointer.v
├── type_mixing.v
├── pointer.v
├── string_builder.v
├── printing.v
├── panic.v
├── array_mean.v
├── isnil_test.v
├── concatenation.v
├── random_numbers.v
├── Vtemplate.v
├── pointer_arithmetic.v
├── stopwatch.v
├── constants.v
├── random_ips.v
├── operator_overloading.v
├── system_time.v
├── type_alias.v
├── conversions.v
├── chars.v
└── substitution.v
├── Chapter_5_Control_Structures
├── for4.c
├── for_range.v
├── for5.v
├── for_string.v
├── if_expressions2.v
├── match3.v
├── exercises
│ ├── for_sum.v
│ ├── for_sum2.v
│ ├── for_variable.v
│ ├── question5_1.v
│ ├── check_even.v
│ ├── check_positive.v
│ ├── check_equal.v
│ ├── rectangle_stars.v
│ └── check_leap_year.v
├── defer.v
├── booleans.v
├── match4.v
├── if_construct.v
├── match_expression.v
├── for1.v
├── match2.v
├── for2.v
├── for4.v
├── month_name.v
├── if_ct.v
├── for3.v
├── if_expressions.v
├── test_2866_defer.v
├── .vscode
│ └── launch.json
└── defer_mult.v
├── Chapter_10_Option_Types_Error_Handling
├── test.tmp
├── panic.v
├── option1B.v
├── option1.v
├── option1C.v
├── option2A.v
├── option1D.v
├── option3.v
└── option2B.v
├── Chapter_7_Arrays
├── game_of_life
│ ├── .gitignore
│ ├── demo.gif
│ └── README.md
├── chaining_append.v
├── first_last.exe
├── map_array.v
├── multidim.v
├── mutate_array.v
├── string_array.v
├── exercises
│ ├── for_array.v
│ ├── array_max.v
│ ├── array_mean.v
│ ├── array_max_fn.v
│ ├── pick_a_random_element_from_a_list.v
│ ├── array_readin.v
│ ├── array_dup_fun.v
│ ├── array_copy.v
│ ├── array_even.v
│ ├── stack.v
│ ├── shuffle_a_list.v
│ ├── array_dup.v
│ └── arr_dup_fn_gen.v
├── array_sum.v
├── first_last.v
├── slices.v
├── trailing_comma.v
├── prealloc_arrays.v
├── for_arrays.v
├── print_slice.v
├── multidim2_wrong.v
├── arr_reverse.v
├── multidim2.v
├── array_memory.v
├── hello_developers.v
├── mut_arrays.v
├── arrays1.v
├── forin_arrays.v
└── array_value.v
├── Chapter_13_Standard_Library_vlib
├── vcasino
│ ├── .gitignore
│ └── README.md
├── eventbus
│ ├── .gitignore
│ ├── eventbus.exe
│ ├── some_module
│ │ └── some_module.v
│ └── eventbus.v
├── databases
│ ├── pg
│ │ ├── .gitignore
│ │ └── libpq.dll
│ └── sqlite
│ │ ├── ex1_sqlite.exe
│ │ └── sqlite_test.v
├── graphical
│ ├── tetris
│ │ ├── .gitignore
│ │ ├── glfw3.dll
│ │ ├── freetype.dll
│ │ ├── screenshot.png
│ │ ├── RobotoMono-Regular.ttf
│ │ └── README.md
│ ├── game_of_life
│ │ ├── .gitignore
│ │ ├── demo.gif
│ │ ├── glfw3.dll
│ │ └── README.md
│ ├── v-pong
│ │ ├── .gitignore
│ │ ├── .gitmodules
│ │ ├── beta.png
│ │ ├── click.wav
│ │ ├── glfw3.dll
│ │ ├── freetype.dll
│ │ ├── RobotoMono-Regular.ttf
│ │ ├── resources
│ │ │ └── sounds
│ │ │ │ ├── click.wav
│ │ │ │ ├── enter.wav
│ │ │ │ ├── error.wav
│ │ │ │ ├── launch.wav
│ │ │ │ ├── boop_wall.wav
│ │ │ │ ├── destroyed.wav
│ │ │ │ ├── boop_paddle.wav
│ │ │ │ └── score_point.wav
│ │ ├── sound.v
│ │ └── README.MD
│ └── sdl
│ │ ├── basic_window
│ │ └── SDL2.dll
│ │ └── tvintris
│ │ ├── sounds
│ │ ├── block.wav
│ │ ├── single.wav
│ │ ├── triple.wav
│ │ └── TwintrisThosenine.mod
│ │ ├── images
│ │ ├── tvintris.png
│ │ └── v-logo_30_30.png
│ │ ├── fonts
│ │ └── RobotoMono-Regular.ttf
│ │ └── README.md
├── exercises
│ ├── test.txt
│ ├── test_json.txt
│ ├── test_json2.txt
│ ├── create_file.v
│ └── read_files.v
├── runtime.v
├── vweb
│ ├── vweb_example
│ │ └── index.html
│ ├── web_blog
│ │ ├── code.url
│ │ ├── tutorial.url
│ │ ├── spiral 2 - blog_template
│ │ │ ├── index.html
│ │ │ └── blog.v
│ │ ├── spiral 3 - blog_orm
│ │ │ ├── index.html
│ │ │ ├── article.v
│ │ │ ├── error.txt
│ │ │ ├── blog.sql
│ │ │ └── app.v
│ │ └── spiral 1 - hello_world
│ │ │ └── hello_webworld.v
│ └── hello_world
│ │ └── hello_webworld.v
├── os_env.v
├── vbench
│ ├── .gitignore
│ └── main.exe
├── vc140.pdb
├── greatest_common_divisor.v
├── links_scraper.ilk
├── links_scraper.pdb
├── chdir.vsh
├── os_get_line.v
├── chdir.v
├── os_examples.v
├── file_write.v
├── log.v
├── bare.v
├── os_args.v
├── os_getline2.v
├── os_reading_passwords.v
├── filter_log.v
├── http_get.v
├── math_op.v
├── clipboard_test.v
├── hangman
│ └── words.txt
├── word_counter_book
│ └── words.txt
├── terminal_control.v
├── weblate-memory.json
└── json_file.v
├── Chapter_8_Maps
├── word_counter
│ ├── .gitignore
│ └── README.md
├── pairs.v
├── maps_in.v
├── map_array.v
└── map_forin.v
├── Chapter_11_Modules_and_Testing
├── game_of_life
│ ├── .gitignore
│ ├── demo.gif
│ ├── README.md
│ └── life.v
├── project1
│ ├── project1.v
│ └── v.mod
├── hello
│ └── hello.v
├── app.v
├── sum
│ └── sum.v
├── mod1.vh
├── mod1_test.v
├── modulea
│ └── modulea.v
├── moduleb
│ └── moduleb.v
├── using_mod1.v
├── sum_test.v
├── mod1
│ └── mod1.v
├── dnc_sum_test.v
├── hello_test.v
├── mutable_struct.v
├── visibility.v
└── strings.vh
├── ideas.docx
├── Chapter_14_V_Modules
├── faker
│ └── faker-master
│ │ ├── CONTRIBUTING.md
│ │ ├── data
│ │ ├── address
│ │ │ ├── README.md
│ │ │ └── city_suffixes
│ │ ├── address_br
│ │ │ ├── README.md
│ │ │ ├── state_abbr
│ │ │ └── state
│ │ ├── address_ca
│ │ │ ├── README.md
│ │ │ └── province
│ │ └── address_us
│ │ │ ├── README.md
│ │ │ ├── state_abbr
│ │ │ ├── state_and_territories_abbr
│ │ │ └── state
│ │ ├── .gitignore
│ │ └── CHANGELOG.md
├── V-modules.xlsx
├── owmw.vh
├── use_owmw.v
└── owmw
│ └── owmw.v
├── ~WRL2289.tmp
├── Chapter_3_IDE
├── format_file.v
├── format_file_orig.v
├── debugging
│ ├── ex1_debug.exe
│ ├── ex1_debug.v
│ └── .vscode
│ │ └── launch.json
├── hello_world.v
├── assert.v
└── hi.v
├── update_repo.bat
├── X_Appendix_Keywords.docx
├── How to compile tetris.docx
├── The Way To V_Chapter 1.docx
├── The Way To V_Chapter 2.docx
├── The Way To V_Chapter 3.docx
├── The Way To V_Chapter 4.docx
├── The Way To V_Chapter 5.docx
├── The Way To V_Chapter 6.docx
├── The Way To V_Chapter 7.docx
├── The Way To V_Chapter 8.docx
├── The Way To V_Chapter 9.docx
├── The Way to V_Chapter 10.docx
├── The Way to V_Chapter 11.docx
├── The Way to V_Chapter 12.docx
├── The Way to V_Chapter 13.docx
├── The Way to V_Chapter 14.docx
├── The Way to V_Chapter 15.docx
├── sum_100.v
├── Chapter_6_Functions
├── anonymous.v
├── simple_function.v
├── simple_function2B.v
├── exercises
│ ├── square.v
│ ├── 10to1_recursive.v
│ ├── change_array.v
│ ├── function_param2.v
│ ├── match.v
│ ├── mutable_arguments.v
│ ├── odd_even.v
│ ├── fizzbuzz2.v
│ ├── is_prime.v
│ ├── pick_uniformly_a_random_int_point_number_in.v
│ ├── factorial_recursive.v
│ ├── factorial.v
│ ├── convert_decimal_binary.v
│ └── factorial_imperative.v
├── fibonacci_i64.v
├── add_sub.v
├── compare_values.v
├── function_param.v
├── varnumpar2.v
├── varnumpar3.v
├── season_of_month.v
├── greeting.v
├── logical_operations.v
├── simple_function2.v
├── defer.v
├── hanoi.v
├── defer_tracing.v
├── varnumpar.v
├── fibonacci.v
├── part_pure.v
├── defer_logvalues.v
├── mut_recurs.v
└── fibonacci_imperative.v
├── X_Appendix - Transforming Go programs into V programs.docx
├── .gitignore
├── Chapter_2_Compiler
└── hello_world.v
├── README.md
├── Chapter_9_Structs_Methods_and_Interfaces
├── exercises
│ ├── struct_multi.v
│ ├── struct_array.v
│ ├── str_point.v
│ ├── under_age.v
│ ├── has_fur.v
│ ├── embedding_structs.v
│ ├── rectangle.v
│ ├── employee_salary.v
│ └── persons.v
├── struct_arr2.v
├── struct_func2.v
├── alloc_struct.v
├── ref_field.v
├── struct_multi.v
├── embed_func1.v
├── mutable_receiver2.v
├── update_with_pipe.v
├── update_with_pipe0.v
├── methods.v
├── struct_pointer.v
├── user_struct.v
├── interface_point.v
├── struct_union.v
├── mutable_receiver.v
├── color_struct.v
├── house_animals.v
├── method_enum2.v
├── mut_pointer.v
├── test.v
├── method_enum.v
├── operator_overloading.v
├── interfaces.v
├── enum_interface.v
├── interval.v
├── structs.v
├── op_overload.v
├── mult_inheritance.v
├── struct_arr.v
├── duck_dance.v
└── multidim_struct.v
└── update_repo_full.txt
/Chapter_12_Advanced_Topics/foo.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/LICENSE:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/chars.c:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/for4.c:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/constants.c:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter_10_Option_Types_Error_Handling/test.tmp:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/game_of_life/.gitignore:
--------------------------------------------------------------------------------
1 | life
2 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vcasino/.gitignore:
--------------------------------------------------------------------------------
1 | VCasino
--------------------------------------------------------------------------------
/Chapter_8_Maps/word_counter/.gitignore:
--------------------------------------------------------------------------------
1 | word_counter
2 |
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/game_of_life/.gitignore:
--------------------------------------------------------------------------------
1 | life
2 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/eventbus/.gitignore:
--------------------------------------------------------------------------------
1 | eventbus
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/databases/pg/.gitignore:
--------------------------------------------------------------------------------
1 | customer
2 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/tetris/.gitignore:
--------------------------------------------------------------------------------
1 | tetris
2 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/PkgInfo:
--------------------------------------------------------------------------------
1 | APPL????
2 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/game_of_life/.gitignore:
--------------------------------------------------------------------------------
1 | life
2 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/runtime/runtime_linux.v:
--------------------------------------------------------------------------------
1 | module runtime
2 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/runtime/runtime_mac.v:
--------------------------------------------------------------------------------
1 | module runtime
2 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/multi_line.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | age := 21
3 | }
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/for_range.v:
--------------------------------------------------------------------------------
1 | for i in 0..10 { println(i) }
2 |
--------------------------------------------------------------------------------
/ideas.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/ideas.docx
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/exercises/test.txt:
--------------------------------------------------------------------------------
1 | testing file writing!
2 | hello!
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # CONTRIBUTING
2 |
3 | TODO
--------------------------------------------------------------------------------
/~WRL2289.tmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/~WRL2289.tmp
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/data/address/README.md:
--------------------------------------------------------------------------------
1 | # Address
2 |
3 | TODO
--------------------------------------------------------------------------------
/Chapter_3_IDE/format_file.v:
--------------------------------------------------------------------------------
1 | fn main()
2 | {
3 | println( "I have been formatted?") }
--------------------------------------------------------------------------------
/update_repo.bat:
--------------------------------------------------------------------------------
1 | git add .
2 | git commit -m "latest"
3 | git push -u origin master
4 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/win32/.gitignore:
--------------------------------------------------------------------------------
1 | staging-*
2 | *.zip
3 |
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/data/address_br/README.md:
--------------------------------------------------------------------------------
1 | # Address_br
2 |
3 | TODO
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/data/address_ca/README.md:
--------------------------------------------------------------------------------
1 | # Address_ca
2 |
3 | TODO
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/data/address_us/README.md:
--------------------------------------------------------------------------------
1 | # Address_us
2 |
3 | TODO
--------------------------------------------------------------------------------
/Chapter_3_IDE/format_file_orig.v:
--------------------------------------------------------------------------------
1 | fn main()
2 | {
3 | println( "I have been formatted?") }
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/hello_world_inter.v:
--------------------------------------------------------------------------------
1 | w := 'World'
2 | println('Hello $w!')
3 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/variables1.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | age := 63
3 | println(age) // 63
4 | }
--------------------------------------------------------------------------------
/Chapter_7_Arrays/chaining_append.v:
--------------------------------------------------------------------------------
1 | mut a := [1, 2, 3, 4]
2 | a << 5 << 6 << 7 << 8
3 | println(a)
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/runtime.v:
--------------------------------------------------------------------------------
1 | import runtime
2 |
3 | println(runtime.nr_cpus()) // 4
4 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile
2 | Makefile.in
3 | config.make
4 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/.gitignore:
--------------------------------------------------------------------------------
1 | fns.txt
2 | lookup_pong.c
3 | *.exe
4 | tetris*
--------------------------------------------------------------------------------
/X_Appendix_Keywords.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/X_Appendix_Keywords.docx
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/unsafe1.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | a := 10
3 | unsafe {
4 | println(a) // 10
5 | }
6 | }
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/vweb_example/index.html:
--------------------------------------------------------------------------------
1 | test app
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/float.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | age := f32(20)
3 | println(age) // 20.000000
4 | }
5 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/type_keyword.v:
--------------------------------------------------------------------------------
1 | type TZ int
2 |
3 | fn main() {
4 | println(5) // => 5
5 | }
6 |
--------------------------------------------------------------------------------
/How to compile tetris.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/How to compile tetris.docx
--------------------------------------------------------------------------------
/The Way To V_Chapter 1.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way To V_Chapter 1.docx
--------------------------------------------------------------------------------
/The Way To V_Chapter 2.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way To V_Chapter 2.docx
--------------------------------------------------------------------------------
/The Way To V_Chapter 3.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way To V_Chapter 3.docx
--------------------------------------------------------------------------------
/The Way To V_Chapter 4.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way To V_Chapter 4.docx
--------------------------------------------------------------------------------
/The Way To V_Chapter 5.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way To V_Chapter 5.docx
--------------------------------------------------------------------------------
/The Way To V_Chapter 6.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way To V_Chapter 6.docx
--------------------------------------------------------------------------------
/The Way To V_Chapter 7.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way To V_Chapter 7.docx
--------------------------------------------------------------------------------
/The Way To V_Chapter 8.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way To V_Chapter 8.docx
--------------------------------------------------------------------------------
/The Way To V_Chapter 9.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way To V_Chapter 9.docx
--------------------------------------------------------------------------------
/The Way to V_Chapter 10.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way to V_Chapter 10.docx
--------------------------------------------------------------------------------
/The Way to V_Chapter 11.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way to V_Chapter 11.docx
--------------------------------------------------------------------------------
/The Way to V_Chapter 12.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way to V_Chapter 12.docx
--------------------------------------------------------------------------------
/The Way to V_Chapter 13.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way to V_Chapter 13.docx
--------------------------------------------------------------------------------
/The Way to V_Chapter 14.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way to V_Chapter 14.docx
--------------------------------------------------------------------------------
/The Way to V_Chapter 15.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/The Way to V_Chapter 15.docx
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/project1/project1.v:
--------------------------------------------------------------------------------
1 | module main
2 |
3 | fn main() {
4 | println('Hello World !')
5 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | autoreconf -fi
4 | ./configure "$@"
5 |
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/hello/hello.v:
--------------------------------------------------------------------------------
1 | module hello
2 |
3 | pub fn hello() string {
4 | return 'Hello world'
5 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/a.out
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile.in
2 | Makefile
3 | *-doom.png
4 | *-setup.png
5 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/doom/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile
2 | Makefile.in
3 | .deps
4 | tags
5 | TAGS
6 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/malloc.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | str := malloc(4)
3 | println(str) // 00000000009A23F0
4 | }
5 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/first_last.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_7_Arrays/first_last.exe
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/app.v:
--------------------------------------------------------------------------------
1 | import modulea
2 | import moduleb
3 |
4 | modulea.hello()
5 | moduleb.world()
6 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/hexen/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile
2 | Makefile.in
3 | .deps
4 | tags
5 | TAGS
6 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/strife/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile
2 | Makefile.in
3 | .deps
4 | tags
5 | TAGS
6 |
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/V-modules.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_14_V_Modules/V-modules.xlsx
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/owmw.vh:
--------------------------------------------------------------------------------
1 | // E:/Vlang/The_Way_to_V/Chapter_14_V_Modules/owmw module header
2 |
3 | module owmw
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/variables3.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut age := 63
3 | age = 64
4 | println(age) // 64
5 | }
6 |
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/sum/sum.v:
--------------------------------------------------------------------------------
1 | // sum.v
2 | module sum
3 |
4 | pub fn sum(a, b int) int {
5 | return a + b
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/midiproc/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile.in
2 | Makefile
3 | *.exe
4 | .deps
5 | tags
6 | TAGS
7 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/.gitignore:
--------------------------------------------------------------------------------
1 | Info.plist
2 | launcher
3 | *.o
4 | *.d
5 | *.dmg
6 | staging
7 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/heretic/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile
2 | Makefile.in
3 | .deps
4 | tags
5 | TAGS
6 |
7 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/textscreen/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile
2 | Makefile.in
3 | .deps
4 | *.a
5 | tags
6 | TAGS
7 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/os_env.v:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | fn main() {
4 | home := os.getenv('PATH')
5 | println(home)
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/V-software.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_15_V_Software/V-software.xlsx
--------------------------------------------------------------------------------
/Chapter_3_IDE/debugging/ex1_debug.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_3_IDE/debugging/ex1_debug.exe
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/variables2.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | age := 63
3 | age = 64
4 | }
5 | // Output:
6 | // `age` is immutable
--------------------------------------------------------------------------------
/Chapter_7_Arrays/game_of_life/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_7_Arrays/game_of_life/demo.gif
--------------------------------------------------------------------------------
/Chapter_10_Option_Types_Error_Handling/panic.v:
--------------------------------------------------------------------------------
1 | fn main(){
2 | // println(9 / 0)
3 | panic('I created a deliberate panic!')
4 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/man/bash-completion/.gitignore:
--------------------------------------------------------------------------------
1 | *doom
2 | *heretic
3 | *hexen
4 | *strife
5 | *.template
6 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/enums.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_4_Basic_Types_Strings/enums.exe
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/modulo_by_zero.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | println(100 % 0) // error at compilation: undefined: `Floating`
3 | }
4 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/.vs/slnx.sqlite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/.vs/slnx.sqlite
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/call_c.v:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | fn main() {
4 | C.puts('hello, world from V!')
5 | }
6 | // NO OUTPUT ??
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/opl/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile.in
2 | Makefile
3 | .deps
4 | libopl.a
5 | *.rc
6 | tags
7 | TAGS
8 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vbench/.gitignore:
--------------------------------------------------------------------------------
1 | main.dSYM
2 | main
3 | tempCodeRunnerFile
4 | bench/bench_ips
5 | bench/bench_ips.dSYM/
6 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vc140.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/vc140.pdb
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/exercises/int_pointer.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | y := 3
3 | mut x := &y
4 | *x = 4
5 | println(y) // 4
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter_10_Option_Types_Error_Handling/option1B.v:
--------------------------------------------------------------------------------
1 | fn f() ?int {
2 | return error('nope')
3 | }
4 |
5 | x := f() or { 10 }
6 | println(x) // => 10
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/mod1.vh:
--------------------------------------------------------------------------------
1 | // E:/Vlang/The_Way_to_V/Chapter_11_Modules_and_Testing/mod1 module header
2 |
3 | module mod1
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/conversions.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_4_Basic_Types_Strings/conversions.exe
--------------------------------------------------------------------------------
/sum_100.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | sum := 0
3 | i := 0
4 | for i < 100 {
5 | i++
6 | sum += i
7 | }
8 | print(sum) // => 5050
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/opl/examples/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile.in
2 | Makefile
3 | .deps
4 | droplay
5 | *.exe
6 | tags
7 | TAGS
8 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pcsound/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile.in
2 | Makefile
3 | .deps
4 | libpcsound.a
5 | *.rc
6 | tags
7 | TAGS
8 |
9 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/hot_reload/bounce.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/hot_reload/bounce.exe
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/hot_reload/bounce.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/hot_reload/bounce.so
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/hot_reload/glfw3.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/hot_reload/glfw3.dll
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/hot_reload/graph.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/hot_reload/graph.exe
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/hot_reload/graph.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/hot_reload/graph.so
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/exercises/test_json.txt:
--------------------------------------------------------------------------------
1 | {"street":"Heideland","no":28,"ext":"","postal_code":"2640","city":"Mortsel","country":"Belgium"}
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vbench/main.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/vbench/main.exe
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/exercises/interpol.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | name := 'Bob'
3 | println('Hello, $name! ${name.len<5}') // => Hello, Bob! true
4 | }
--------------------------------------------------------------------------------
/Chapter_6_Functions/anonymous.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | an := fn () int {
3 | return 1+1
4 | }
5 | a := an()
6 | println(a) // => 2
7 | }
--------------------------------------------------------------------------------
/Chapter_7_Arrays/map_array.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | str := '1,2,3'
3 | ints := str.split(',').map(it.int())
4 | for i in ints { print(i) } // => 123
5 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/setup/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile.in
2 | Makefile
3 | .deps
4 | setup-manifest.xml
5 | *.rc
6 | tags
7 | TAGS
8 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/greatest_common_divisor.v:
--------------------------------------------------------------------------------
1 | import math
2 |
3 | fn main() {
4 | res := math.gcd(4585, 1589)
5 | println(res) // 7
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/links_scraper.ilk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/links_scraper.ilk
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/links_scraper.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/links_scraper.pdb
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/statements.v:
--------------------------------------------------------------------------------
1 | fn main(){ a := 3.14 + 9.333 b := 9.333 + 3.14 println('a = $a b = $b') }
2 | // a = 12.473000 b = 12.473000
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/game_of_life/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_11_Modules_and_Testing/game_of_life/demo.gif
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/win32/README:
--------------------------------------------------------------------------------
1 | Makefile to build Windows packages. Requires zip and unix2dos
2 | packages to be installed.
3 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/pointer_function.v:
--------------------------------------------------------------------------------
1 | fn do_smth(ptr &int){
2 | b:= *ptr
3 | println('"${b}"') // "5"
4 | }
5 |
6 | a:=5
7 | do_smth(&a)
8 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/redefinition.v:
--------------------------------------------------------------------------------
1 | // doesn't compile!
2 | fn main() {
3 | a := 42
4 | a := 50
5 | }
6 |
7 | // test.v:3
8 | // redefinition of `a`
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/test.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut s := []string
3 | s << 'V is '
4 | s << 'awesome'
5 | println(s.len) // 2
6 | }
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/databases/pg/libpq.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/databases/pg/libpq.dll
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/eventbus/eventbus.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/eventbus/eventbus.exe
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "miniaudio"]
2 | path = miniaudio
3 | url = https://github.com/Larpon/v-miniaudio.git
4 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/dereferencing.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | x := 3.14
3 | bits := (*u32)(&x)
4 | println(bits)
5 | }
6 | // 000000000062FE2C
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/nested_comments.v:
--------------------------------------------------------------------------------
1 | /*
2 | fn main() {
3 | /**/
4 | }
5 |
6 | */
7 | fn main() {
8 | println('it works') // it works
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/textscreen/examples/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile.in
2 | Makefile
3 | .deps
4 | guitest
5 | calculator
6 | *.exe
7 | tags
8 | TAGS
9 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/beta.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/beta.png
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/exercises/divby0.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | a := 10
3 | b := 0
4 | c := a / b // Floating point exception(core dumped) ./main
5 | println(c)
6 | }
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/variables4.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut a := 42
3 | a = 44
4 | b := a
5 | println(b) // 44
6 | // a := 108 // redefinition of `a`
7 | }
8 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/for5.v:
--------------------------------------------------------------------------------
1 | for i := 0; i < 10; i++ {
2 | if i == 5 {
3 | continue
4 | }
5 | print('$i ')
6 | }
7 |
8 | // Output: 0 1 2 3 4 6 7 8 9
9 |
--------------------------------------------------------------------------------
/X_Appendix - Transforming Go programs into V programs.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/X_Appendix - Transforming Go programs into V programs.docx
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/doom.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/doom.ico
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/tetris/glfw3.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/tetris/glfw3.dll
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/click.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/click.wav
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/glfw3.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/glfw3.dll
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/bitwise.v:
--------------------------------------------------------------------------------
1 | const (
2 | foo = 1
3 | bar = 2
4 | )
5 |
6 | println(foo | bar) // 3
7 | println(foo &bar) // 0
8 | println(foo ^ 2) // 3
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.exe
2 | *.o
3 | *.obj
4 | *.vrepl_temp.v
5 | *.tmp.c
6 | a.out.tmp.c
7 | *.vrepl.v
8 | *.vrepl*
9 | .vrepl_temp
10 |
11 | .DS_Store
12 | data/.DS_Store
13 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/.vs/VSWorkspaceState.json:
--------------------------------------------------------------------------------
1 | {
2 | "ExpandedNodes": [
3 | ""
4 | ],
5 | "SelectedNode": "\\test.v",
6 | "PreviewInSolutionExplorer": false
7 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/doom8.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/doom8.ico
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/setup.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/setup.ico
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/setup.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/setup.png
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/setup8.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/setup8.ico
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/tetris/freetype.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/tetris/freetype.dll
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/freetype.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/freetype.dll
--------------------------------------------------------------------------------
/Chapter_3_IDE/hello_world.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | println('Hello, World from V!')
3 | }
4 |
5 | // println('Hello, World from V!')
6 |
7 | // Output:
8 | // Hello, World from V!
9 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/databases/sqlite/ex1_sqlite.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/databases/sqlite/ex1_sqlite.exe
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/game_of_life/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/game_of_life/demo.gif
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/game_of_life/glfw3.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/game_of_life/glfw3.dll
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/tetris/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/tetris/screenshot.png
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/project1/v.mod:
--------------------------------------------------------------------------------
1 | #V Project#
2 |
3 | Module {
4 | name: 'project1',
5 | version: '0.0.1',
6 | description: 'description of project1',
7 | dependencies: []
8 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/.vs/Chapter_12_Advanced_Topics/v16/.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/.vs/Chapter_12_Advanced_Topics/v16/.suo
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/sdl/basic_window/SDL2.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/sdl/basic_window/SDL2.dll
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/for_string.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | s := 'hello'
3 | for c in s {
4 | println(c)
5 | }
6 | }
7 |
8 | /* Output:
9 | h
10 | e
11 | l
12 | l
13 | o
14 | */
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/if_expressions2.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | s := if true {
3 | 1
4 | } else {
5 | 'a'
6 | }
7 | println(s)
8 | }
9 | // 2:7: error: mismatched types `int` and `string`
--------------------------------------------------------------------------------
/Chapter_6_Functions/simple_function.v:
--------------------------------------------------------------------------------
1 | fn multiply_3nums(a, b, c int) {
2 | println('Multiply $a * $b * $c = ${a * b *c}') // Multiply 2 * 5 * 6 = 60
3 | }
4 |
5 | multiply_3nums(2, 5, 6)
6 |
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/mod1_test.v:
--------------------------------------------------------------------------------
1 | import mod1
2 |
3 | fn test_say_hi_str() {
4 | assert mod1.say_hi_str() == 'hello from mod1!'
5 | // assert mod1.say_hi_str() == 'Hello world!'
6 | }
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/modulea/modulea.v:
--------------------------------------------------------------------------------
1 | module modulea
2 |
3 | fn init() {
4 | println('Initializing module a!')
5 | }
6 |
7 | pub fn hello() {
8 | print('Hello ')
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/app.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/app.icns
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/app.png
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/disk/dir.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/disk/dir.DS_Store
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/textscreen/fonts/large.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/textscreen/fonts/large.png
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/textscreen/fonts/small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/textscreen/fonts/small.png
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/js_backend/hi.v:
--------------------------------------------------------------------------------
1 | // v -o hi.js hi.v && node hi.js
2 | fn main() {
3 | for i := 0; i < 3; i++ {
4 | println('Hello from V.js')
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/sounds/block.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/sounds/block.wav
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/sounds/single.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/sounds/single.wav
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/sounds/triple.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/sounds/triple.wav
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/tetris/RobotoMono-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/tetris/RobotoMono-Regular.ttf
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/RobotoMono-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/RobotoMono-Regular.ttf
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/hello_world2.v:
--------------------------------------------------------------------------------
1 | const (
2 | greeting = 'Hello, World from V!'
3 | const2 = 108
4 | )
5 |
6 | // fn main() {
7 | println(greeting) // Hello, World from V!
8 | // }
9 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/hello_world3.v:
--------------------------------------------------------------------------------
1 | // International greetings
2 | println('Καλημέρα κόσμε; or こんにちは 世界') // Greek or Asian greetings
3 |
4 | /* Output:
5 | Καλημέρα κόσμε; or こんにちは 世界
6 | */
--------------------------------------------------------------------------------
/Chapter_6_Functions/simple_function2B.v:
--------------------------------------------------------------------------------
1 | fn add_sub(x int, y int) (int, int) {
2 | return x + y, x - y
3 | }
4 |
5 | n1, n2 := add_sub(77, 33)
6 | println('n1 is $n1, n2 is $n2') // n1 is 110, n2 is 44
--------------------------------------------------------------------------------
/Chapter_7_Arrays/multidim.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | // m2arr := [][]int // specify array type: `[]typ` instead of `[]`
3 |
4 | m := [[0]]
5 | n := [ [3] ]
6 | k := n[0][0]
7 | println(k) // => 3
8 | }
9 |
--------------------------------------------------------------------------------
/Chapter_10_Option_Types_Error_Handling/option1.v:
--------------------------------------------------------------------------------
1 | fn f() ?int {
2 | a := 5
3 | return a
4 | }
5 |
6 | fn main() {
7 | o := f() or {
8 | return
9 | }
10 | println(o) // -> 5
11 | }
12 |
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/moduleb/moduleb.v:
--------------------------------------------------------------------------------
1 | module moduleb
2 |
3 | fn init() {
4 | println('Initializing module b!')
5 | }
6 |
7 | pub fn world() {
8 | println('world!')
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/using_mod1.v:
--------------------------------------------------------------------------------
1 | import mod1
2 | // import modulea // warning: using_mod1.v:1:6: the following imports were never used: * modulea
3 |
4 | fn main() {
5 | mod1.say_hi()
6 | }
7 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/.vs/Chapter_12_Advanced_Topics/v16/Browse.VC.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/.vs/Chapter_12_Advanced_Topics/v16/Browse.VC.db
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/disk/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/disk/background.png
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/textscreen/fonts/normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/textscreen/fonts/normal.png
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/exercises/test_json2.txt:
--------------------------------------------------------------------------------
1 | {"first_name":"Ivo","last_name":"Balbaert","addr":{"street":"Heideland","no":28,"ext":"","postal_code":"2640","city":"Mortsel","country":"Belgium"}}
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/images/tvintris.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/images/tvintris.png
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/web_blog/code.url:
--------------------------------------------------------------------------------
1 | [{000214A0-0000-0000-C000-000000000046}]
2 | Prop3=19,11
3 | [InternetShortcut]
4 | IDList=
5 | URL=https://github.com/vlang/v/tree/master/tutorials
6 |
--------------------------------------------------------------------------------
/Chapter_2_Compiler/hello_world.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | println('Hello, World from V!')
3 | }
4 |
5 | // println('Hello, World from V!') // doesn't work Apr 9
6 |
7 | // Output:
8 | // Hello, World from V!
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/match3.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | i := 0
3 | match i {
4 | 0 {}
5 | 1 { f() }
6 | }
7 | }
8 |
9 | fn f() {
10 | println('f is called')
11 | }
12 |
13 | // No output!
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/square.v:
--------------------------------------------------------------------------------
1 | // Write a V program to find the square of any number using the function.
2 |
3 | fn square(num int) int {
4 | return num * num
5 | }
6 |
7 | println(square(5))
--------------------------------------------------------------------------------
/Chapter_6_Functions/fibonacci_i64.v:
--------------------------------------------------------------------------------
1 | fn fib(n int) i64 {
2 | if n <= 1 {
3 | return i64(1)
4 | }
5 | return fib(n - 1) + fib(n - 2)
6 | }
7 |
8 | println(fib(45))
9 |
10 | // 1836311903
11 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/128x128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/128x128.png
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/wadfile.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/wadfile.icns
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/wadfile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/wadfile.png
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/click.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/click.wav
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/enter.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/enter.wav
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/error.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/error.wav
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/launch.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/launch.wav
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/exercises/pointer_error.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut i := 7
3 | p := &i
4 | println(p) // 000000000062FE44
5 | i = p // implicit dereference
6 | println(i) // 6487620
7 | }
8 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/unused.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | app := 'game'
3 | a := 10
4 | }
5 | // unused.v:2:9: warning: unused variable: `app`
6 | // unused.v:3:9: warning: unused variable: `a`
7 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/exercises/for_sum.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut sum := 0
3 | mut i := 0
4 | for i <= 100 {
5 | sum += i
6 | i++
7 | }
8 | println(sum)
9 | }
10 | // Output: 5050
11 |
12 |
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/sum_test.v:
--------------------------------------------------------------------------------
1 | // sum_test.v
2 | import sum
3 |
4 | fn test_sum() {
5 | assert sum.sum(2, 3) == 5
6 | // assert sum.sum(2, 3) == 777 // => sum_test.v:6: FAILED assertion
7 | }
8 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/chdir.vsh:
--------------------------------------------------------------------------------
1 | fn main() {
2 | println('[+] change directory to temp folder....')
3 | chdir(getenv('TEMP'))
4 | println(getenv('TEMP')) // => C:\Users\CVO\AppData\Local\Temp
5 | }
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/images/v-logo_30_30.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/images/v-logo_30_30.png
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/boop_wall.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/boop_wall.wav
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/destroyed.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/destroyed.wav
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/.gitignore:
--------------------------------------------------------------------------------
1 | .vrepl_temp.dSYM
2 | .vrepl_temp.tmp.c
3 | .vrepl_temp.v
4 | a.out.tmp.c
5 | faker.tmp.c
6 | main.dSYM
7 | main
8 |
9 | .DS_Store
10 | data/.DS_Store
11 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/add_sub.v:
--------------------------------------------------------------------------------
1 | fn add(x, y int) int {
2 | return x + y
3 | }
4 |
5 | fn sub(x, y int) int {
6 | return x - y
7 | }
8 |
9 | println(add(77, 33)) // 110
10 | println(sub(100, 50)) // 20
11 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/compare_values.v:
--------------------------------------------------------------------------------
1 | fn compare_values(a, b int) string {
2 | if a > b {
3 | return 'Bigger'
4 | }
5 | return 'Equal or Smaller'
6 | }
7 |
8 | println(compare_values(3, 10)) // => Equal or Smaller
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/10to1_recursive.v:
--------------------------------------------------------------------------------
1 | fn printrec(i int) {
2 | if i > 10 { return }
3 | printrec(i + 1)
4 | print('$i ')
5 | }
6 |
7 | printrec(1)
8 |
9 | /*
10 | 10 9 8 7 6 5 4 3 2 1
11 | */
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/change_array.v:
--------------------------------------------------------------------------------
1 | fn modify(data mut []string) {
2 | data[0] = 'hello'
3 | }
4 |
5 | mut a := ['A', 'B', 'C', 'D', 'E']
6 | modify(mut a)
7 | println(a) // => ["hello", "B", "C", "D", "E"]
--------------------------------------------------------------------------------
/Chapter_6_Functions/function_param.v:
--------------------------------------------------------------------------------
1 | fn call(fun fn (int) string) {
2 | println(fun(25))
3 | }
4 |
5 | fn say(n int) string {
6 | return 'I said it!'
7 | }
8 |
9 | call(say)
10 |
11 |
12 | // I said it!
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Thi is the repository for:
2 |
3 | The Way To V
4 |
5 | A collection of Word documents and code files that follows closely the progress of the V language, and tries to be as comprehensive as possible.
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/boop_paddle.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/boop_paddle.wav
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/score_point.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/v-pong/resources/sounds/score_point.wav
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/exercises/exercise2.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | b := 7
3 | {
4 | b = 67
5 | println(b)
6 | }
7 | println(b)
8 | }
9 | /* Output:
10 | panic: exercise2.v:4
11 | `b` is immutable
12 | */
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/defer.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | a := 1
3 | b := 2
4 | c := 3
5 | defer { println(a) }
6 | defer { println(b) }
7 | println(c)
8 | }
9 |
10 | /* Output:
11 | 3
12 | 2
13 | 1
14 | */
15 |
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/mod1/mod1.v:
--------------------------------------------------------------------------------
1 | module mod1
2 |
3 | fn init() {}
4 |
5 | pub fn say_hi() {
6 | println('hello from mod1!')
7 | }
8 |
9 | pub fn say_hi_str() string {
10 | return 'hello from mod1!'
11 | }
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/fonts/RobotoMono-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/fonts/RobotoMono-Regular.ttf
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/sounds/TwintrisThosenine.mod:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/sounds/TwintrisThosenine.mod
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/kernel/sys/debug.v:
--------------------------------------------------------------------------------
1 | module sys
2 |
3 | import io
4 |
5 | pub fn printk(msg string) {
6 | for i := 0; i < msg.len; i++ {
7 | io.outb(0xe9, msg.str[i])
8 | }
9 | io.outb(0xe9, `\n`)
10 | }
--------------------------------------------------------------------------------
/Chapter_7_Arrays/mutate_array.v:
--------------------------------------------------------------------------------
1 | fn multiply_by_2(arr mut []int) {
2 | for i := 0; i < arr.len; i++ {
3 | arr[i] *= 2
4 | }
5 | }
6 |
7 | mut nums := [1, 2, 3]
8 | multiply_by_2(mut nums)
9 | println(nums) // => [2, 4, 6]
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/os_get_line.v:
--------------------------------------------------------------------------------
1 | import os
2 | fn main() {
3 | a:=os.get_line()
4 | println(a)
5 | }
6 |
7 | /* Input:
8 | Wow that was a quick fix!
9 | Output:
10 | Wow that was a quick fix!
11 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/exercises/struct_multi.v:
--------------------------------------------------------------------------------
1 | struct Thing {
2 | mut:
3 | arr [5][10]int
4 | }
5 |
6 | fn main() {
7 | mut x := &Thing{}
8 | x.arr[0][0] = 6
9 | println(x.arr[0][0]) // => 6
10 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/ChangeLog:
--------------------------------------------------------------------------------
1 | Chocolate Doom's version history is stored in Git. For a full
2 | change log, clone the repository on Github:
3 |
4 | https://github.com/chocolate-doom/chocolate-doom
5 |
6 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/man/wikipages:
--------------------------------------------------------------------------------
1 | # This is a list of wiki pages to automatically link to when generating
2 | # wikitext output.
3 | Dehacked
4 | Doom 1.91
5 | Merging
6 | Multiplayer
7 | Three screen mode
8 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/pointer_deref.v:
--------------------------------------------------------------------------------
1 | fn test(i &int) {
2 | unsafe {
3 | *i = 2
4 | }
5 | println('test')
6 | }
7 | fn main() {
8 | a := 10
9 | test(&a) // => test
10 | println(a) // => 2
11 | }
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/booleans.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | bool1 := true
3 | if bool1 {
4 | println('The value is true') // => The value is true
5 | } else {
6 | println('The value is false')
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/match4.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | num := 1
3 | match num % 2 == 0 {
4 | true { print('The input number is even.') }
5 | else { print('The input number is odd.') } // The input number is odd.
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/function_param2.v:
--------------------------------------------------------------------------------
1 | fn sqr(n int) int {
2 | return n * n
3 | }
4 |
5 | fn run(value int, op fn(int) int) int {
6 | return op(value)
7 | }
8 |
9 | println(run(5, sqr)) // "25"
10 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/chdir.v:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | fn main() {
4 | println('[+] change directory to temp folder....')
5 | os.chdir(os.getenv('TEMP'))
6 | println(os.getenv('TEMP')) // => C:\Users\CVO\AppData\Local\Temp
7 | }
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/exercises/for_sum2.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut sum := 0
3 | for i := 0; i <= 100; i++ {
4 | sum += i
5 | i++
6 | }
7 | println(sum)
8 | }
9 |
10 | // 2550
11 | // Explanation: i is incremented twice!
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/match.v:
--------------------------------------------------------------------------------
1 | // Jul 17: doesn't yet run on Windows
2 | os := 'windows'
3 | print('V is running on ')
4 | match os {
5 | 'darwin' => println('macOS.')
6 | 'linux' => println('Linux.')
7 | else => println(os)
8 | }
--------------------------------------------------------------------------------
/Chapter_7_Arrays/string_array.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | names := ['Melissa', 'John']
3 | println(names) // => ["Melissa", "John"]
4 |
5 | println('John' in names ) // => true
6 | println('Alex' in names) // => false
7 | }
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/struct_arr2.v:
--------------------------------------------------------------------------------
1 | struct Data {
2 | field int
3 | }
4 |
5 | const (
6 | x = Data{1}
7 | y = Data{2}
8 | )
9 |
10 | fn main() {
11 | a := [x, y]
12 | println(a[1].field) // => 2
13 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/launcher.nib/keyedobjects.nib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ivo-Balbaert/way_to_v/HEAD/Chapter_12_Advanced_Topics/doom/chocolate-doom/pkg/osx/Resources/launcher.nib/keyedobjects.nib
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/generics0.v:
--------------------------------------------------------------------------------
1 | fn plus(a, b T) T {
2 | return a + b
3 | }
4 |
5 | fn main() {
6 | println(plus(10,11)) // 21
7 | println(plus(1.0, 2.0)) // 3.000000
8 | println(plus('hello', ' world!')) // hello world!
9 | }
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/exercises/for_variable.v:
--------------------------------------------------------------------------------
1 | // does not compile
2 | fn main() {
3 | for i := 0; i < 10; i++ {
4 | println(i)
5 | }
6 | println(i)
7 | }
8 |
9 | // undefined: `i`
10 | // i is only defined within the for block
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/asm.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | a := 10
3 | unsafe {
4 | asm {
5 | mov eax, [a]
6 | add eax, 10
7 | mov [a], eax
8 | }
9 | }
10 | }
11 |
12 | // Dec 1: asm.v:5:10: syntax error: unexpected `mov`, expecting `STR`
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/web_blog/tutorial.url:
--------------------------------------------------------------------------------
1 | [{000214A0-0000-0000-C000-000000000046}]
2 | Prop3=19,11
3 | [InternetShortcut]
4 | IDList=
5 | URL=https://github.com/vlang/v/blob/master/tutorials/building-a-simple-web-blog-with-vweb.md
6 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/if_construct.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | a := 10
3 | b := 20
4 | if a < b {
5 | println('$a < $b') // 10 < 20
6 | } else if a > b {
7 | println('$a > $b')
8 | } else {
9 | println('$a == $b')
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/opl/examples/Makefile.am:
--------------------------------------------------------------------------------
1 |
2 | AM_CFLAGS = -I$(top_srcdir)/opl
3 |
4 | noinst_PROGRAMS=droplay
5 |
6 | droplay_LDADD = ../libopl.a @LDFLAGS@ @SDL_LIBS@ @SDLMIXER_LIBS@
7 | droplay_SOURCES = droplay.c
8 |
9 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/os_examples.v:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | fn main () {
4 | println('This program is called ${os.executable()}')
5 | // This program is called e:\Vlang\The_Way_to_V\Chapter_13_Standard_Library_vlib\os_examples.exe
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/match_expression.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | number := 2
3 | s := match number {
4 | 1 { 'one' }
5 | 2 { 'two' }
6 | else {
7 | println('boo')
8 | 'many'
9 | }
10 | }
11 | println(s) // two
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/exercises/global_local.v:
--------------------------------------------------------------------------------
1 | const (
2 | a = 'G'
3 | )
4 |
5 | fn main() {
6 | n()
7 | m()
8 | n()
9 | }
10 |
11 | fn n() {
12 | print(a)
13 | }
14 |
15 | fn m() {
16 | b := 'O'
17 | print(b)
18 | }
19 |
20 | // GOG
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/for_array.v:
--------------------------------------------------------------------------------
1 | const (
2 | len = 15
3 | )
4 |
5 | fn main() {
6 | mut arr := [0].repeat(len)
7 | for i:=0; i < len; i++ {
8 | arr[i] = i
9 | }
10 | println(arr) // => [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]
11 | }
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/struct_func2.v:
--------------------------------------------------------------------------------
1 | module main
2 |
3 | struct Test {
4 | func fn()
5 | }
6 |
7 | fn main() {
8 | test := Test{print_func}
9 | test.func()
10 | }
11 |
12 | fn print_func() {
13 | println('Hello World')
14 | }
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/data/address/city_suffixes:
--------------------------------------------------------------------------------
1 | town
2 | ton
3 | land
4 | ville
5 | berg
6 | burgh
7 | borough
8 | bury
9 | view
10 | port
11 | mouth
12 | stad
13 | furt
14 | chester
15 | mouth
16 | fort
17 | haven
18 | side
19 | shire
20 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/code_blocks.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut a := 42
3 | a = 44
4 | println(a) // 44
5 | {
6 | b := 67
7 | println(b) // 67
8 | a = 45
9 | }
10 | // b = 9 // error: undefined `b`
11 | println(a) // 45
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter_8_Maps/pairs.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | params := {
3 | 'k1': 'v1',
4 | 'k2': 'v2',
5 | 'k3': 'v3'
6 | }
7 |
8 | keys := params.keys()
9 | pairs := keys.map('$it=${ params[it] }')
10 | println(pairs.join(' - ')) // => k1=v1 - k2=v2 - k3=v3
11 | }
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/exercises/create_file.v:
--------------------------------------------------------------------------------
1 | // Write a V program to create a new file with content
2 | import os
3 |
4 | fn main() {
5 | file_name := 'test.txt'
6 | content := 'testing file writing!\nhello!'
7 | os.write_file(file_name, content)
8 | }
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/builtin/bare/voredef.v:
--------------------------------------------------------------------------------
1 | module builtin
2 |
3 | #include
4 |
5 | __global stdout_consumer fn (byte)
6 | __global stderr_consumer fn (byte)
7 |
8 | pub struct C.string {
9 | pub:
10 | str byteptr
11 | len int
12 | }
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/alloc_struct.v:
--------------------------------------------------------------------------------
1 | struct Aex {
2 | id int
3 | }
4 |
5 | fn new_aex() Aex {
6 | return Aex{} // allocated on the stack
7 | // return &Aex{} // does a heap allocation
8 | }
9 |
10 | a := Aex{}
11 | b := new_aex()
12 |
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/use_owmw.v:
--------------------------------------------------------------------------------
1 | import owmw
2 |
3 | const (
4 | token = '6f3e9a53f0be3733968163891bd22f5d'
5 | )
6 |
7 | fn main() {
8 | w := owmw.start(token, 1)
9 | city := w.city_by_name('Antwerp')
10 | println(city.temperature())
11 | }
12 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/exercises/exercise4_1.v:
--------------------------------------------------------------------------------
1 | const (
2 | A = 'G'
3 | )
4 |
5 | fn main() {
6 | n()
7 | m()
8 | n()
9 | }
10 |
11 | fn n() {
12 | print(A)
13 | }
14 |
15 | fn m() {
16 | A := 'O'
17 | print(A)
18 | }
19 |
20 | // Output:
21 | // GOG
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/exit.v:
--------------------------------------------------------------------------------
1 | fn main(){
2 | println('before exiting...')
3 | exit(1)
4 | // println('after exit ???') // unreachable code
5 | }
6 |
7 | /*
8 | before exiting...
9 |
10 | [Done] exited with code=1 in 1.645 seconds
11 | */
12 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/ref_field.v:
--------------------------------------------------------------------------------
1 | struct Item {
2 | s string
3 | other &Item
4 | }
5 |
6 | fn main() {
7 | i_2 := &Item{s: 'Hello, '}
8 | i_1 := Item{s: 'World!', other: i_2}
9 | println(i_1.other.s + i_1.s) // Hello, World!
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/data/address_br/state_abbr:
--------------------------------------------------------------------------------
1 | AC
2 | AL
3 | AP
4 | AM
5 | BA
6 | CE
7 | DF
8 | ES
9 | GO
10 | MA
11 | MT
12 | MS
13 | MG
14 | PR
15 | PB
16 | PA
17 | PE
18 | PI
19 | RJ
20 | RN
21 | RS
22 | RO
23 | RR
24 | SC
25 | SE
26 | SP
27 | TO
28 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/program_without_main.v:
--------------------------------------------------------------------------------
1 | // module main // is implicit
2 | // c := 7 // error: redefinition of `c`
3 |
4 | fn ret_ints() (int, int) {
5 | return 42, 108
6 | }
7 |
8 | a, b := ret_ints()
9 | println(a) // 42
10 | println(b) // 108
11 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/varnumpar2.v:
--------------------------------------------------------------------------------
1 | fn print_out(test ...string) {
2 | for txt in test {
3 | println(txt)
4 | }
5 | }
6 |
7 | print_out("V", "is", "the", "best", "lang" , "ever")
8 |
9 | /* Output:
10 | V
11 | is
12 | the
13 | best
14 | lang
15 | ever
16 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/struct_multi.v:
--------------------------------------------------------------------------------
1 | struct Matrix {
2 | mut:
3 | data [][]f64
4 | }
5 |
6 | fn (c mut Matrix) assign(x int, y int, v f64) {
7 | c.data[x][y] = v
8 | }
9 |
10 | fn (c Matrix) getxy(x int, y int) f64 {
11 | return c.data[x][y]
12 | }
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/for1.v:
--------------------------------------------------------------------------------
1 | for i := 0; i < 5; i++ {
2 | println('This is the $i iteration')
3 | }
4 |
5 | /* Output:
6 | This is the 0 iteration
7 | This is the 1 iteration
8 | This is the 2 iteration
9 | This is the 3 iteration
10 | This is the 4 iteration
11 | */
--------------------------------------------------------------------------------
/Chapter_7_Arrays/array_sum.v:
--------------------------------------------------------------------------------
1 | fn sum(a []f32) f32 {
2 | mut sum := 0.0
3 | for v in a {
4 | sum += v
5 | }
6 | return sum
7 | }
8 |
9 | arr := [7.0, 8.5, 9.1]
10 | x := sum(arr)
11 | println('The sum of the array is: $x') // The sum of the array is: 24.600000
12 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/first_last.v:
--------------------------------------------------------------------------------
1 | fn main () {
2 | mut a := []int
3 | a << 4
4 | a << 6
5 | a << 7
6 | println(a.first()) // 4
7 | b := a.last()
8 | println('$b ${a.len}') // 7 3
9 | a.delete(a.len-1)
10 | println('$b ${a.len}') // 7 2
11 | }
12 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/exercises/struct_array.v:
--------------------------------------------------------------------------------
1 | struct SomeStruct {
2 | content []map[string]string
3 | }
4 |
5 | val := SomeStruct {content: [{"key": "val"}]}
6 | println(val)
7 |
8 | /*
9 | SomeStruct {
10 | content: [{'key': 'val'}]
11 | }
12 | */
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/test.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int main()
6 | {
7 | std::vector s;
8 | s.push_back("V is ");
9 | s.push_back("awesome");
10 | std::cout << s.size() << std::endl;
11 | return 0;
12 | }
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/web_blog/spiral 2 - blog_template/index.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | @message
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/generate_random.v:
--------------------------------------------------------------------------------
1 | import (
2 | rand
3 | time
4 | )
5 |
6 | fn main() {
7 | t := time.now()
8 | s := t.calc_unix()
9 | rand.seed(s)
10 | // generate a random number from 1 to 100
11 | j := rand.next(100)
12 | println(j) // e.g. 23
13 | }
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/mutable_arguments.v:
--------------------------------------------------------------------------------
1 | /: does not compile:
2 | // Jul 17: error: invalid operands to binary * (have 'int *' and 'int')
3 | fn main() {
4 | mut a := 10
5 | change_a(mut a)
6 | println(a)
7 | }
8 |
9 | fn change_a(n mut int) {
10 | n = n * 2
11 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/AUTHORS:
--------------------------------------------------------------------------------
1 | Simon Howard
2 | James Haley
3 | Samuel Villarreal
4 | Fabian Greffrath
5 | Jonathan Dowland
6 | Alexey Khokholov
7 |
--------------------------------------------------------------------------------
/Chapter_10_Option_Types_Error_Handling/option1C.v:
--------------------------------------------------------------------------------
1 | fn f() ?string {
2 | return error('nope')
3 | }
4 |
5 | fn report_error(s string) {
6 | println(s)
7 | }
8 |
9 | x := f() or {
10 | report_error('Error being reported')
11 | ' '
12 | }
13 |
14 | println('***' + x + '***') // => *** ***
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/man/CMDLINE.template:
--------------------------------------------------------------------------------
1 | == Command line parameters ==
2 |
3 | This is a full list of the supported command line parameters. A number of
4 | additional parameters are supported in addition to those present in the DOS
5 | version.
6 |
7 | @content
8 |
9 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/man/CMDLINE.template.md:
--------------------------------------------------------------------------------
1 | # Command line parameters
2 |
3 | This is a full list of the supported command line parameters. A number of
4 | additional parameters are supported in addition to those present in the DOS
5 | version.
6 |
7 | @content
8 |
9 |
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/data/address_ca/province:
--------------------------------------------------------------------------------
1 | Newfoundland and Labrador
2 | Nova Scotia
3 | Prince Edward Island
4 | New Brunswick
5 | Quebec
6 | Ontario
7 | Manitoba
8 | Saskatchewan
9 | Alberta
10 | British Columbia
11 | Yukon
12 | Northwest Territories
13 | Nunavut
14 |
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/dnc_sum_test.v:
--------------------------------------------------------------------------------
1 |
2 | // v 12.8: tests cannot have function `main`
3 | fn sum (a, b int) int {
4 | return a + b
5 | }
6 |
7 | fn check_sum() {
8 | assert sum(2, 3) == 5
9 | assert sum(2, 3) == 7
10 | }
11 |
12 | fn main(){
13 | check_sum()
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/Doom.desktop.in:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Name=@PACKAGE_SHORTNAME@ Doom
3 | Exec=@PROGRAM_PREFIX@doom
4 | Icon=@PROGRAM_PREFIX@doom
5 | Type=Application
6 | Comment=@PACKAGE_SHORTDESC@
7 | Categories=Game;ActionGame;
8 | Keywords=first;person;shooter;vanilla;
9 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/unions.v:
--------------------------------------------------------------------------------
1 | union Block {
2 | mut:
3 | x int
4 | str string
5 | }
6 |
7 | fn main() {
8 | mut q1 := Block{str: 'This'}
9 | q1.str = 'Rosa'
10 | mut q2 := Block{x: 40}
11 | q2.x = 42
12 | println(q1) // => Rosa
13 | println('$q2') // => 42
14 | }
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/match2.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | num1 := 99
3 |
4 | match num1 {
5 | 98, 99 { println('It\'s equal to 98 or 99') } // => It's equal to 98 or 99
6 | 100 { println('It\'s equal to 100') }
7 | else { println('It\'s not equal to 98, 99 or 100') }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/struct_pointer.v:
--------------------------------------------------------------------------------
1 | struct S {
2 | data int
3 | ptr *int
4 | }
5 |
6 | fn (s S) str() string {
7 | return s.data.str()
8 | }
9 |
10 | fn main() {
11 | s1 := S{}
12 | s2 := S{data: 5}
13 | println(s1)
14 | println(s2)
15 | }
16 |
17 | /* Output:
18 | 0
19 | 5
20 | */
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/odd_even.v:
--------------------------------------------------------------------------------
1 | // Write a V program to check a given number is even or odd using the function.
2 |
3 | fn is_even(num int) bool {
4 | if num % 2 == 0 { return true }
5 | else { return false }
6 | }
7 |
8 | println(is_even(77)) // => false
9 | println(is_even(108)) // => true
--------------------------------------------------------------------------------
/Chapter_7_Arrays/slices.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | arr := [1,2,3,4]
3 | println(arr[1..2]) // => [2]
4 | println(arr[0..4]) // => [1, 2, 3, 4]
5 |
6 | println(arr[1..arr.len]) // => [2, 3, 4]
7 |
8 | println(arr[..2]) // => [1, 2]
9 |
10 | str := 'hello'
11 | println(str[0..2]) // => he
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/trailing_comma.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 |
3 | x := [
4 | 'John'
5 | , 'Bob'
6 | , 'Julie'
7 | ,]
8 |
9 | n := [
10 | 1,
11 | 2,
12 | 3,
13 | ]
14 |
15 | println(x) // => ["John", "Bob", "Julie"]
16 | println(n) // => [1, 2, 3]
17 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/Hexen.desktop.in:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Name=@PACKAGE_SHORTNAME@ Hexen
3 | Exec=@PROGRAM_PREFIX@hexen
4 | Icon=@PROGRAM_PREFIX@doom
5 | Type=Application
6 | Comment=@PACKAGE_SHORTDESC@
7 | Categories=Game;ActionGame;
8 | Keywords=first;person;shooter;doom;vanilla;
9 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/message.v:
--------------------------------------------------------------------------------
1 | module main // ??
2 |
3 | import time
4 | import os
5 |
6 | [live]
7 | fn print_message() {
8 | println('Hello! Modify this message while the program is running.')
9 | }
10 |
11 | fn main() {
12 | for {
13 | print_message()
14 | time.sleep_ms(500)
15 | }
16 | }
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/fizzbuzz2.v:
--------------------------------------------------------------------------------
1 | fn fizzbuzz(i int) {
2 | if i % 15 == 0 {
3 | println('FizzBuzz')
4 | } else if i % 3 == 0 {
5 | println('Fizz')
6 | } else if i % 5 == 0 {
7 | println('Buzz')
8 | } else {
9 | println(i)
10 | }
11 | }
12 |
13 | fizzbuzz(50) // Buzz
14 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/varnumpar3.v:
--------------------------------------------------------------------------------
1 | struct Object {
2 | }
3 |
4 | struct Arg {
5 | }
6 |
7 | fn (this Object) varg(arg &Arg, args... f32) {
8 | println(args.len)
9 | }
10 |
11 | fn main() {
12 | obj := Object{}
13 | obj.varg(Arg{})
14 | obj.varg(Arg{}, 3.0, 4.2)
15 | }
16 |
17 | /*
18 | 0
19 | 2
20 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/embed_func1.v:
--------------------------------------------------------------------------------
1 | // TODO: this will be implemented later in May
2 | struct Button {
3 | widget Widget
4 | title string
5 | }
6 |
7 | button := new_button('Click me')
8 | button.set_pos(x, y)
9 |
10 | // Without embedding we'd have to do
11 | button.widget.set_pos(x,y)
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/Heretic.desktop.in:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Name=@PACKAGE_SHORTNAME@ Heretic
3 | Exec=@PROGRAM_PREFIX@heretic
4 | Icon=@PROGRAM_PREFIX@doom
5 | Type=Application
6 | Comment=@PACKAGE_SHORTDESC@
7 | Categories=Game;ActionGame;
8 | Keywords=first;person;shooter;doom;vanilla;
9 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/Strife.desktop.in:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Name=@PACKAGE_SHORTNAME@ Strife
3 | Exec=@PROGRAM_PREFIX@strife
4 | Icon=@PROGRAM_PREFIX@doom
5 | Type=Application
6 | Comment=@PACKAGE_SHORTDESC@
7 | Categories=Game;ActionGame;
8 | Keywords=first;person;shooter;doom;vanilla;
9 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/file_write.v:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | fn test_file_creation() {
4 | file_name := './new_file.txt'
5 | content := 'text'
6 | os.write_file(file_name, content)
7 | assert content.len == os.file_size(file_name)
8 | os.rm(file_name)
9 | }
10 |
11 | test_file_creation()
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/log.v:
--------------------------------------------------------------------------------
1 | import log
2 |
3 | fn main(){
4 | mut l := log.Log{log.INFO, 'terminal'}
5 | l.info('info')
6 | l.warn('warn')
7 | l.error('error')
8 | l.debug('no debug')
9 | l.set_level(log.DEBUG)
10 | l.debug('debug')
11 | l.fatal('fatal')
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/web_blog/spiral 3 - blog_orm/index.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | @for article in articles
8 |
9 | @article.title
10 | @article.text
11 |
12 | @end
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/server_time.v:
--------------------------------------------------------------------------------
1 | import time
2 | import http
3 |
4 | fn main() {
5 | resp := http.get('https://vlang.io/utc_now') or {
6 | eprintln('failed to fetch data from the server')
7 | return
8 | }
9 | t := time.unix(resp.text.int())
10 | println(t.format()) // 2019-12-13 10:11
11 | }
--------------------------------------------------------------------------------
/Chapter_7_Arrays/game_of_life/README.md:
--------------------------------------------------------------------------------
1 | # Conway's Game of Life
2 |
3 | 
4 |
5 |
6 | ```v
7 | v run life.v
8 | ```
9 |
10 | Created by fuyutarow: https://github.com/fuyutarow/Conways-Game-of-Life-with-Vlang
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/mutable_receiver2.v:
--------------------------------------------------------------------------------
1 | struct Item {
2 | mut:
3 | thing int
4 | }
5 |
6 | fn (i mut Item) do_thing() Item {
7 | i.thing = 1
8 | return *i
9 | }
10 |
11 | mut itm := Item{}
12 | itm.do_thing()
13 | println(itm)
14 |
15 | /* Output:
16 | {
17 | thing: 1
18 | }
19 | */
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/web_blog/spiral 3 - blog_orm/article.v:
--------------------------------------------------------------------------------
1 | module main
2 |
3 | struct Article {
4 | id int
5 | title string
6 | text string
7 | }
8 |
9 | pub fn (app &App) find_all_articles() []Article {
10 | db := app.db
11 | articles := db.select from Article
12 | return articles
13 | }
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/string_pointer.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | str := 'good bye'
3 | mut ptr := &str
4 | println(ptr) // prints address, for example: 0x7ffc58aee0f0
5 | *ptr = 'ciao'
6 | println(*ptr) // 'ciao'
7 | println(str) // 'ciao'
8 | }
9 |
10 | /*
11 | 000000000062FE20
12 | ciao
13 | ciao
14 | */
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/array_max.v:
--------------------------------------------------------------------------------
1 | // Write a V program that, given an array of numbers, returns the maximum value.
2 |
3 | fn main() {
4 | arr := [0, -45, 78, 345, 12, 77]
5 | mut max := arr[0]
6 | for item in arr {
7 | if item > max { max = item }
8 | }
9 | println('The maximum is: $max') // => 345
10 | }
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/update_with_pipe.v:
--------------------------------------------------------------------------------
1 | struct User {
2 | is_registered bool
3 | }
4 |
5 | fn register_user(u User) User {
6 | return {u | is_registered: true}
7 | }
8 |
9 | fn main() {
10 | mut u := User{}
11 | u = register_user(u)
12 | println(u.is_registered.str()) // => true
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/type_mixing.v:
--------------------------------------------------------------------------------
1 | // does not compile!
2 | fn main() {
3 | a := u32(15)
4 | mut b := i8(0)
5 | // b = a + a // error: cannot use type `u32` as type `i8` in assignment
6 | n := i16(34)
7 | mut m := i32(0)
8 | m = n // error: cannot use type `i16` as type `i32` in assignment
9 | }
10 |
--------------------------------------------------------------------------------
/update_repo_full.txt:
--------------------------------------------------------------------------------
1 | git add .
2 | git commit -m "rosetta"
3 | git push -u origin master
4 |
5 | Remote repo is: https://github.com/Ivo-Balbaert/way_to_v
6 |
7 |
8 | (forced update: git push https://github.com/Ivo-Balbaert/NimbleExample -f
9 | see: https://stackoverflow.com/questions/5509543/how-do-i-properly-force-a-git-push)
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/game_of_life/README.md:
--------------------------------------------------------------------------------
1 | # Conway's Game of Life
2 |
3 | 
4 |
5 |
6 | ```v
7 | v run life.v
8 | ```
9 |
10 | Created by fuyutarow: https://github.com/fuyutarow/Conways-Game-of-Life-with-Vlang
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/exercises/question5_1.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | k := 6
3 | match k {
4 | 4 { println('was <= 4') }
5 | 5 { println('was <= 5') }
6 | 6 { println('was <= 6') } // => was <= 6
7 | 7 { println('was <= 7') }
8 | 8 { println('was <= 8') }
9 | else { println('default case') }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/season_of_month.v:
--------------------------------------------------------------------------------
1 | fn season_of_month(month int) string {
2 | match month {
3 | 12,1,2 { return 'Winter' }
4 | 3,4,5 { return 'Spring'}
5 | 6,7,8 { return 'Summer'}
6 | 9,10,11 { return 'Autumn'}
7 | }
8 | return 'Season unknown'
9 | }
10 |
11 | println(season_of_month(2)) // => Winter
12 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/for2.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut i := 5
3 |
4 | for i > 0 {
5 | i -= 1
6 | println('The variable i is now: $i')
7 | }
8 | }
9 | /* Output:
10 | The variable i is now: 4
11 | The variable i is now: 3
12 | The variable i is now: 2
13 | The variable i is now: 1
14 | The variable i is now: 0
15 | */
16 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/greeting.v:
--------------------------------------------------------------------------------
1 | fn greeting() {
2 | println('In greeting: Hi!!!!!')
3 | }
4 |
5 | println('In main before calling greeting')
6 | greeting()
7 | println('In main after calling greeting')
8 |
9 | /* Output:
10 | In main before calling greeting
11 | In greeting: Hi!!!!!
12 | In main after calling greeting
13 | */
14 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/logical_operations.v:
--------------------------------------------------------------------------------
1 | fn print_logic(a, b bool) {
2 | print('a and b = ')
3 | println(a && b)
4 |
5 | print('a or b = ')
6 | println(a || b)
7 |
8 | print('not a = ')
9 | println(!a)
10 | }
11 |
12 | print_logic(true, false)
13 |
14 | /*
15 | a and b = false
16 | a or b = true
17 | not a = false
18 | */
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/bare.v:
--------------------------------------------------------------------------------
1 | // compile with v -bare bare.v)
2 | fn syscall5(number, arg1, arg2, arg3, arg4, arg5 voidptr) voidptr
3 |
4 | fn write(fd int, data voidptr, nbytes u64) int {
5 | return syscall5(1, fd, data, nbytes, 0, 0)
6 | }
7 |
8 | fn main() {
9 | write(1, "Hello from V running on bare metal!\n", 37)
10 | }
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/game_of_life/README.md:
--------------------------------------------------------------------------------
1 | # Conway's Game of Life
2 |
3 | 
4 |
5 |
6 | ```v
7 | v run life.v
8 | ```
9 |
10 | Created by fuyutarow: https://github.com/fuyutarow/Conways-Game-of-Life-with-Vlang
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/pointer.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | i := 100
3 | ptr := &i
4 | println(ptr) // 0x7ffecdee3f64
5 |
6 | println('An integer: $i, its location in memory: $ptr\n')
7 | // An integer: 100, its location in memory: 0x7ffecdee3f64
8 |
9 | m := *ptr
10 | println(m) // 100
11 |
12 | assert(i == m)
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/string_builder.v:
--------------------------------------------------------------------------------
1 | import strings
2 |
3 | fn main() {
4 | // 1million * 12 byte -> a line is (line word, space, middle_number_of_chars)
5 | mut builder := strings.new_builder(12000000)
6 | for i in 0..1000000 {
7 | builder.write('line $i\n')
8 | }
9 | print(builder.str())
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/prealloc_arrays.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | a := [0].repeat(5)
3 | println(a) // => [0, 0, 0, 0, 0]
4 |
5 | nr_ids := 13
6 | ids := [1].repeat(nr_ids)
7 | println(ids) // => [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
8 |
9 | arr := [1, 2].repeat(5)
10 | println(arr) // => [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
11 | }
12 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/exercises/str_point.v:
--------------------------------------------------------------------------------
1 | struct Point {
2 | x int
3 | y int
4 | }
5 |
6 | fn (p Point) str() string {
7 | return 'Point { x: $p.x, y: $p.y }'
8 | }
9 |
10 | fn main() {
11 | p := Point{x: 10, y: 20}
12 | println(p)
13 | }
14 | // Point { x: 10, y: 20 }
15 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/update_with_pipe0.v:
--------------------------------------------------------------------------------
1 | struct User {
2 | name string
3 | age int
4 | }
5 |
6 | fn main() {
7 | user1 := User{'Bob', 20}
8 | user2 := {user1 | name: 'Peter'}
9 | println(user1.name)
10 | println(user2)
11 | }
12 |
13 | /* Output:
14 | Bob
15 | {
16 | name: Peter
17 | age: 20
18 | }
19 | */
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/setup/Setup.desktop.in:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Name=@PACKAGE_SHORTNAME@ Setup
3 | Exec=@PROGRAM_PREFIX@setup
4 | Icon=@PROGRAM_PREFIX@setup
5 | Type=Application
6 | Comment=Setup tool for @PACKAGE_SHORTNAME@
7 | Categories=Settings;
8 | Keywords=first;person;shooter;doom;heretic;hexen;strife;vanilla;
9 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/printing.v:
--------------------------------------------------------------------------------
1 | const (
2 | lower_s = 'lower s'
3 | )
4 |
5 | fn main() {
6 | a := 42
7 | pi := 3.141592
8 | is_sharp := true
9 | println(a)
10 | println(pi)
11 | print(pi)
12 | println(is_sharp)
13 | println(lower_s)
14 | }
15 | /* Output:
16 | 42
17 | 3.141592
18 | 3.141592true
19 | lower s
20 | */
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/for4.v:
--------------------------------------------------------------------------------
1 | for i := 0; i < 3; i++ {
2 | for j := 0; j < 10; j++ {
3 | if j > 5 {
4 | break
5 | }
6 | print(j)
7 | }
8 | print(' ')
9 | }
10 |
11 | /* Output:
12 | 0
13 | 1
14 | 2
15 | 3
16 | 4
17 | 5
18 | 0
19 | 1
20 | 2
21 | 3
22 | 4
23 | 5
24 | 0
25 | 1
26 | 2
27 | 3
28 | 4
29 | 5
30 | */
--------------------------------------------------------------------------------
/Chapter_10_Option_Types_Error_Handling/option2A.v:
--------------------------------------------------------------------------------
1 | struct User {
2 | id int
3 | }
4 |
5 | fn find_user_by_id(id int) ?User {
6 | u := User{id: 10}
7 | return u
8 | }
9 |
10 | fn main() {
11 | user := find_user_by_id(10) or {
12 | return
13 | }
14 | println(user.id) // => 10
15 | }
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/hello_test.v:
--------------------------------------------------------------------------------
1 | import hello
2 |
3 | fn test_hello() {
4 | assert hello.hello() == 'Hello world'
5 | assert hello.hello() == 'Hello world!'
6 | }
7 |
8 | /* Output for 2nd assert:
9 | hello_test.v:5: FAILED assertion
10 | Function: test_hello()
11 | Source : assert hello.hello() == 'Hello world!'
12 | */
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/man/.gitignore:
--------------------------------------------------------------------------------
1 | CMDLINE.doom
2 | CMDLINE.doom.md
3 | CMDLINE.heretic
4 | CMDLINE.heretic.md
5 | CMDLINE.hexen
6 | CMDLINE.hexen.md
7 | CMDLINE.strife
8 | CMDLINE.strife.md
9 | INSTALL.doom
10 | INSTALL.heretic
11 | INSTALL.hexen
12 | INSTALL.strife
13 | Makefile.in
14 | Makefile
15 | *.6
16 | *.5
17 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/Doom_Screensaver.desktop.in:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Name=@PACKAGE_SHORTNAME@ Doom
3 | Comment=@PACKAGE_SHORTDESC@
4 | TryExec=@PROGRAM_PREFIX@doom
5 | Exec=@PROGRAM_PREFIX@doom
6 | StartupNotify=false
7 | Terminal=false
8 | Type=Application
9 | OnlyShowIn=GNOME;MATE;
10 | Categories=Screensaver;
11 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/exercises/swap.v:
--------------------------------------------------------------------------------
1 | // Idiom #21 Swap values of variables a and b
2 | fn main() {
3 | mut n := 1
4 | mut m := 2
5 | println('n is $n and m is $m')
6 | mut temp := 0
7 | temp = n
8 | n = m
9 | m = temp
10 | println('n is $n and m is $m')
11 | }
12 |
13 | // Output:
14 | // n is 1 and m is 2
15 | // n is 2 and m is 1
--------------------------------------------------------------------------------
/Chapter_7_Arrays/for_arrays.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut arr1 := [1, 2, 3, 4, 5]
3 |
4 | for i := 0; i < arr1.len; i++ {
5 | arr1[i] = i * 2
6 | println('Item at index $i is ${arr1[i]}')
7 | }
8 | }
9 |
10 | /*
11 | Item at index 0 is 0
12 | Item at index 1 is 2
13 | Item at index 2 is 4
14 | Item at index 3 is 6
15 | Item at index 4 is 8
16 | */
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/panic.v:
--------------------------------------------------------------------------------
1 | eprintln('I just felt an error!')
2 | panic('Something went terribly wrong here!')
3 |
4 | /*
5 | warning: test.v:1:4: unreachable code
6 | V panic: Someting terribly wrong here!
7 | TODO: print_backtrace_skipping_top_frames_mingw(2)
8 | print_backtrace_skipping_top_frames is not implemented on this platform for now...
9 | */
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/month_name.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | println(season_of_month(2))
3 | }
4 |
5 | fn season_of_month(month int) string {
6 | match month {
7 | 12,1,2 { return 'Winter' } // => Winter
8 | 3,4,5 { return 'Spring'}
9 | 6,7,8 { return 'Summer'}
10 | 9,10,11 { return 'Autumn'}
11 | }
12 | return 'Season unknown'
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/methods.v:
--------------------------------------------------------------------------------
1 | struct User {
2 | age int
3 | }
4 |
5 | fn (u User) can_register() bool {
6 | return u.age > 16
7 | }
8 |
9 | // fn main() {
10 | user := User{age: 10}
11 | println(user.can_register()) // => false
12 |
13 | user2 := User{age: 20}
14 | println(user2.can_register()) // => true
15 | //}
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/if_ct.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | $if windows {
3 | println('I run on a Windows machine') // => I run on a Windows machine
4 | }
5 | $if linux {
6 | println('I run on a Linux machine')
7 | }
8 | $if mac {
9 | println('I run on a macOS machine')
10 | }
11 | $if debug {
12 | println('I am debugging')
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/exercises/under_age.v:
--------------------------------------------------------------------------------
1 | struct Person {
2 | name string
3 | age int
4 | }
5 |
6 | fn (p Person) is_under_age() bool {
7 | return p.age < 21
8 | }
9 |
10 | fn main() {
11 | bob := Person {
12 | name: 'Bob'
13 | age: 17
14 | }
15 | println(bob.is_under_age()) // => true
16 | }
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/os_args.v:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | fn main() {
4 | for ix, arg in os.args {
5 | println('$ix: $arg')
6 | }
7 | }
8 |
9 | /* When called as: os_args A 1 Hello This prints out:
10 | E:\Vlang\The_Way_to_V\Chapter_9_Modules>os_args A 1 Hello
11 | 0: os_args
12 | 1: A
13 | 2: 1
14 | 3: Hello
15 | */
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/exercises/check_even.v:
--------------------------------------------------------------------------------
1 | // Write a V program to check whether a given number is even or odd.
2 | import os
3 |
4 | fn main() {
5 | print('Give the number: ')
6 | number := os.get_line().trim_space().int()
7 | if number % 2 == 0 {
8 | println('The number is even')
9 | } else {
10 | println('The number is odd')
11 | }
12 | }
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/array_mean.v:
--------------------------------------------------------------------------------
1 | // Write a V program to print the integers inside an array and also print their mean.
2 | fn main() {
3 | arr := [12, 45, 78, 108]
4 | mut sum := 0
5 | for item in arr {
6 | sum += item
7 | }
8 | mean := f32(sum) / arr.len
9 | println('The mean is: $mean') // => 60.750000
10 | // if f32 is left out, result is 60
11 | }
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/struct_pointer.v:
--------------------------------------------------------------------------------
1 | struct Sptr {
2 | data int
3 | ptr &int
4 | }
5 |
6 | fn main() {
7 | s1 := Sptr{}
8 | s2 := Sptr{data: 5}
9 | println(s1)
10 | println(s2)
11 | }
12 |
13 | /* Output:
14 | {
15 | data: 0
16 | ptr: 0000000000000000
17 | }
18 | {
19 | data: 5
20 | ptr: 0000000000000000
21 | }
22 | */
23 |
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/mutable_struct.v:
--------------------------------------------------------------------------------
1 | struct Point {
2 | x int
3 | mut:
4 | y int
5 | }
6 |
7 | fn main() {
8 | mut point := Point{x:10, y:20}
9 | // point.x++ // won't compile: cannot modify immutable field `x` (type `Point`)
10 | point.y++ // OK
11 | println(point)
12 | }
13 |
14 | /*
15 | {
16 | x: 10
17 | y: 21
18 | }
19 | */
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/hot_reload/message.v:
--------------------------------------------------------------------------------
1 | // Build this example with: v -live message.v
2 | import (
3 | os
4 | time
5 | )
6 |
7 | [live]
8 | fn print_message() {
9 | println('Hello! Modify this message while the program is running.')
10 | }
11 |
12 | fn main() {
13 | os.clear()
14 | for {
15 | print_message()
16 | time.sleep_ms(500)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/array_mean.v:
--------------------------------------------------------------------------------
1 | // Write a V program to print the integers inside an array and also print their mean.
2 | fn main() {
3 | arr := [12, 45, 78, 108]
4 | mut sum := 0
5 | for item in arr {
6 | sum += item
7 | }
8 | mean := f32(sum) / arr.len
9 | println('The mean is: $mean') // => 60.750000
10 | // if f32 is left out, result is 60
11 | }
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/for3.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut i := 5
3 | for {
4 | i = i - 1
5 | println('The variable i is now: $i')
6 | if i <= 0 {
7 | break
8 | }
9 | }
10 | }
11 |
12 | /* Output:
13 | The variable i is now: 4
14 | The variable i is now: 3
15 | The variable i is now: 2
16 | The variable i is now: 1
17 | The variable i is now: 0
18 | */
19 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/crypto/crypto.v:
--------------------------------------------------------------------------------
1 | module crypto
2 |
3 | pub enum Hash {
4 | md4
5 | md5
6 | sha1
7 | sha224
8 | sha256
9 | sha384
10 | sha512
11 | md5sha1
12 | ripemd160
13 | sha3_224
14 | sha3_256
15 | sha3_384
16 | sha3_512
17 | sha512_224
18 | sha512_256
19 | blake2s_256
20 | blake2b_256
21 | blake2b_384
22 | blake2b_512
23 | }
24 |
--------------------------------------------------------------------------------
/Chapter_3_IDE/assert.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | age := 63
3 | assert(age == 63)
4 | // assert(age == 64)
5 | }
6 |
7 | /* Output:
8 | assert.v:4: FAILED: main()
9 | Source: assert(age == 64)
10 | V panic: An assertion failed.
11 | print_backtrace_skipping_top_frames is not implemented on this platform for now...
12 |
13 | Apr 9: assert.v:4: FAIL: fn main(): assert age == 64
14 | */
--------------------------------------------------------------------------------
/Chapter_7_Arrays/print_slice.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | x := [byte(65), 66, 67]
3 | b := x[0..1]
4 | println(b) // [A]
5 | println(b.str()) // [A]
6 | println('$b') // [A]
7 |
8 | y := ['apple', 'banana', 'coconut']
9 | slice_of_y := y[0..1]
10 | println(slice_of_y) // ['apple']
11 | println(slice_of_y.str()) // ['apple']
12 | println('$slice_of_y') // ['apple']
13 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/midiproc/Makefile.am:
--------------------------------------------------------------------------------
1 |
2 | AM_CFLAGS=-I$(top_srcdir)/src @SDLMIXER_CFLAGS@
3 |
4 | EXTRA_DIST=CMakeLists.txt
5 |
6 | if HAVE_WINDRES
7 |
8 | noinst_PROGRAMS = @PROGRAM_PREFIX@midiproc
9 |
10 | @PROGRAM_PREFIX@midiproc_LDADD = @SDLMIXER_LIBS@
11 | @PROGRAM_PREFIX@midiproc_SOURCES = buffer.c buffer.h main.c proto.h
12 |
13 | endif
14 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/isnil_test.v:
--------------------------------------------------------------------------------
1 | fn test_isnil_byteptr(){
2 | pb := byteptr(0)
3 | assert isnil( pb )
4 | }
5 |
6 | fn test_isnil_voidptr(){
7 | pv := voidptr(0)
8 | assert isnil( pv )
9 | }
10 |
11 | fn test_isnil_charptr(){
12 | pc := &char(0)
13 | assert isnil( pc )
14 | }
15 |
16 | fn test_isnil_intptr(){
17 | pi := &int(0)
18 | assert isnil( pi )
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/exercises/check_positive.v:
--------------------------------------------------------------------------------
1 | // Write a V program to check whether a given number is positive or negative.
2 | import os
3 |
4 | fn main() {
5 | print('Give the number: ')
6 | number := os.get_line().trim_space().int()
7 | if number >= 0 {
8 | println('The number is 0 or positive')
9 | } else {
10 | println('The number is negative')
11 | }
12 | }
--------------------------------------------------------------------------------
/Chapter_6_Functions/simple_function2.v:
--------------------------------------------------------------------------------
1 | fn multiply_3nums(a, b, c int) int {
2 | // product := a * b * c
3 | // return product
4 | return a * b * c
5 | }
6 |
7 | i1 := multiply_3nums(2, 5, 6)
8 | println('Multiply 2 * 5 * 6 = $i1')
9 | println('Multiply 2 * 5 * 6 = ${multiply_3nums(2, 5, 6)}')
10 |
11 | /* Output:
12 | Multiply 2 * 5 * 6 = 60
13 | Multiply 2 * 5 * 6 = 60
14 | */
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/concatenation.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut s := 'Hel' + 'lo, '
3 | s += 'world!'
4 | println(s)// Hello, world!
5 |
6 | n := 7
7 | // println('n = ' + n) // error: expected type `string`, but got `int`
8 | println('n = $n') // 1)
9 | println('n = ' + n.str()) // 2)
10 | }
11 |
12 | /* Output:
13 | Hello, world!
14 | n = 7
15 | n = 7
16 | */
--------------------------------------------------------------------------------
/Chapter_8_Maps/maps_in.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | m := {'ford' : 'mustang', 'chevrolet' : 'camaro', 'dodge' : 'challenger'}
3 |
4 | y := if 'chevrolet' in m {
5 | 'The chevrolet in the list is a ' + m['chevrolet']
6 | }
7 | else {
8 | 'There were no chevrolets in the list :('
9 | }
10 | println(y) // The chevrolet in the list is a camaro
11 | }
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/user_struct.v:
--------------------------------------------------------------------------------
1 | struct User {
2 | id int
3 | }
4 |
5 | fn main() {
6 | user1 := User{id: 10}
7 | user2 := User{}
8 | user3 := User{id: 42}
9 | users := [user1, user2, user3]
10 | for user in users {
11 | println(user)
12 | }
13 | }
14 |
15 | /*
16 | {
17 | id: 10
18 | }
19 | {
20 | id: 0
21 | }
22 | {
23 | id: 42
24 | }
25 | */
26 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/textscreen/examples/Makefile.am:
--------------------------------------------------------------------------------
1 |
2 | AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/textscreen
3 |
4 | noinst_PROGRAMS=guitest calculator
5 |
6 | guitest_LDADD = ../libtextscreen.a @LDFLAGS@ @SDL_LIBS@
7 | guitest_SOURCES = guitest.c
8 |
9 | calculator_LDADD = ../libtextscreen.a @LDFLAGS@ @SDL_LIBS@
10 | calculator_SOURCES = calculator.c
11 |
12 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/crypto/md5/md5_test.v:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
2 | // Use of this source code is governed by an MIT license
3 | // that can be found in the LICENSE file.
4 |
5 | import crypto.md5
6 |
7 | fn test_crypto_md5() {
8 | assert md5.sum('this is a md5 checksum.'.bytes()).hex() == '6fb421ff99036547655984da12973431'
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/runtime/runtime_nix.v:
--------------------------------------------------------------------------------
1 | module runtime
2 |
3 | fn nr_cpus_nix() int {
4 | $if linux {
5 | return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
6 | }
7 | $if mac {
8 | return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
9 | }
10 | return 1
11 | }
12 |
13 | fn nr_cpus_win() int {
14 | eprintln('nr_cpus_win should be callable only for windows')
15 | return 1
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/os_getline2.v:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | fn main() {
4 | os.clear()
5 |
6 | print('Type your message: ')
7 | message := os.get_line()
8 |
9 | println('Your message is: $message')
10 | println('Your message has $message.len characters')
11 | }
12 |
13 | /*
14 | Type your message: Hi how is it ?
15 | Your message is: Hi how is it ?
16 | Your message has 14 characters
17 | */
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/web_blog/spiral 2 - blog_template/blog.v:
--------------------------------------------------------------------------------
1 | import vweb
2 |
3 | struct App {
4 | mut:
5 | vweb vweb.Context
6 | cnt int
7 | }
8 |
9 | pub fn (app &App) init() {}
10 |
11 | fn (app mut App) index() {
12 | app.cnt++
13 | message := 'Hello, world from Vweb!'
14 | $vweb.html()
15 | }
16 |
17 | fn main() {
18 | app := App{}
19 | vweb.run(mut app, 8080)
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/runtime/runtime_win.v:
--------------------------------------------------------------------------------
1 | module runtime
2 |
3 | import os
4 |
5 | fn nr_cpus_win() int {
6 | mut nr := int(C.GetCurrentProcessorNumber())
7 | if nr == 0 {
8 | nr = os.getenv('NUMBER_OF_PROCESSORS').int()
9 | }
10 | return nr
11 | }
12 |
13 | fn nr_cpus_nix() int {
14 | eprintln('nr_cpus_nix should be callable only for nix platforms')
15 | return 1
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/random_numbers.v:
--------------------------------------------------------------------------------
1 | import rand
2 |
3 | fn main() {
4 | rand.seed()
5 | ct := 10
6 | println('here are $ct random numbers:')
7 | for i := 0; i < ct; i ++ {
8 | r := rand.next(1000)
9 | println('$i $r')
10 | }
11 | }
12 |
13 | /* Output:
14 | 0 269
15 | 1 847
16 | ...
17 | 9 732
18 | */
19 | // ?? does it still use C random? see random/random.v
--------------------------------------------------------------------------------
/Chapter_6_Functions/defer.v:
--------------------------------------------------------------------------------
1 | fn fun1() {
2 | println("In fun1 at the top")
3 | defer { fun2() }
4 | println("In fun1 at the bottom!")
5 | }
6 |
7 | fn fun2() {
8 | println("fun2: Deferred until the end of the calling function fun1!")
9 | }
10 |
11 | fun1()
12 |
13 | /* Output:
14 | In fun1 at the top
15 | In fun1 at the bottom!
16 | fun2: Deferred until the end of the calling function fun1!
17 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/interface_point.v:
--------------------------------------------------------------------------------
1 | struct Point {
2 | x i8
3 | y i8
4 | z i8
5 | }
6 |
7 | fn (p Point) draw() string {
8 | return 'Point(${p.x},${p.y})'
9 | }
10 |
11 | fn to_string(d Drawer) string {
12 | return d.draw()
13 |
14 | }
15 |
16 | interface Drawer {
17 | draw() string
18 | }
19 |
20 | p := Point{x: 2, y: 3}
21 | println(to_string(p)) // Point(2,3)
22 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/midiproc/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | if(WIN32)
2 | add_executable("${PROGRAM_PREFIX}midiproc" WIN32 buffer.c buffer.h main.c proto.h)
3 | target_include_directories("${PROGRAM_PREFIX}midiproc"
4 | PRIVATE "../src/" "${CMAKE_CURRENT_BINARY_DIR}/../")
5 | target_link_libraries("${PROGRAM_PREFIX}midiproc" SDL2::SDL2main SDL2::mixer)
6 | endif()
7 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/kernel/vrt_main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void vrt_main(void* bootloader_info, int magic);
4 |
5 | void sys__init_consts();
6 | void mm__init_consts();
7 | void sys__kmain(void* bootloader_info, int magic);
8 |
9 | void vrt_main(void* bootloader_info, int magic) {
10 | sys__init_consts();
11 | mm__init_consts();
12 |
13 | sys__kmain(bootloader_info, magic);
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/crypto/sha1/sha1_test.v:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
2 | // Use of this source code is governed by an MIT license
3 | // that can be found in the LICENSE file.
4 |
5 | import crypto.sha1
6 |
7 | fn test_crypto_sha1() {
8 | assert sha1.sum('This is a sha1 checksum.'.bytes()).hex() == 'e100d74442faa5dcd59463b808983c810a8eb5a1'
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/Vtemplate.v:
--------------------------------------------------------------------------------
1 | import (
2 | math
3 | ui
4 | )
5 |
6 | const (
7 | greeting = 'Hello!'
8 | )
9 |
10 | struct T1 {
11 | field1 int
12 | field2 string
13 | }
14 |
15 | fn main() {
16 | a := 42
17 | func1()
18 | t := T1{}
19 | t.method1()
20 | // ...
21 | println(a)
22 | }
23 |
24 | fn (t T1) method1() {
25 | //...
26 | }
27 |
28 | fn func1() {
29 | //...
30 | }
31 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/pointer_arithmetic.v:
--------------------------------------------------------------------------------
1 | // pointer arithmetic
2 | // does not compile
3 | struct Point {
4 | x byte
5 | }
6 |
7 | fn main() {
8 | p1 := &Point{x: byte(0)}
9 | mut p2 := &Point{}
10 | println(p1)
11 | for i := 0; i < 50; i++ {
12 | p2 = p1 + i // error: operator + not defined on `Point*`
13 | if i == 5 {
14 | p2.x = byte(11)
15 | }
16 | println(p2.x)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/os_reading_passwords.v:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | fn main() {
4 | passwd := os.read_file('/etc/passwd') or {
5 | panic('Failed to open file')
6 | return
7 | }
8 |
9 | for line in passwd.split('\n') {
10 | println(line)
11 | for part in line.split(':') {
12 | println('PART: $part')
13 | }
14 | println('')
15 | }
16 | }
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/stopwatch.v:
--------------------------------------------------------------------------------
1 | import time
2 |
3 | fn main(){
4 | w := time.new_stopwatch()
5 | mut sum := u64(0)
6 | for i := 0; i < 1*1000*1000; i++ {
7 | sum += i*i + i
8 | }
9 | res := w.elapsed().nanoseconds()
10 | println('Result: $sum')
11 | println('Elapsed time: $res nanoseconds')
12 | }
13 |
14 | /*
15 | Elapsed time: 3474400 nanoseconds
16 | Result: 16881588911936
17 | */
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/is_prime.v:
--------------------------------------------------------------------------------
1 | // Write a V program to check whether a number is a prime number or not using a function:
2 |
3 | fn is_prime(num int) bool {
4 | for i := 2; i < num; i++ { // probably i < num / 2 also
5 | if num % i == 0 { return false }
6 | }
7 | return true
8 | }
9 |
10 | fn main () {
11 | println(is_prime(7).str()) // true
12 | println(is_prime(2020).str()) // false
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/exercises/if_enum.v:
--------------------------------------------------------------------------------
1 | enum Color {
2 | red
3 | green
4 | blue
5 | }
6 |
7 | fn is_red(c Color) bool {
8 | return match c {
9 | .red { true }
10 | else { false }
11 | }
12 | }
13 |
14 | fn main() {
15 | my_color := Color.red
16 |
17 | println(is_red(my_color)) // => true
18 | println(is_red(.green)) // => false
19 | }
--------------------------------------------------------------------------------
/Chapter_7_Arrays/multidim2_wrong.v:
--------------------------------------------------------------------------------
1 | fn main () {
2 | mut marr := [[0].repeat(3)].repeat(5)
3 | for i := 0; i < 5; i++ {
4 | for j := 0 ; j < 3; j++ {
5 | marr[i][j] = i + j
6 | // println( '$i, $j, ${i + j}' )
7 | }
8 | }
9 | for i := 0; i < 5; i++ { println(marr[i]) }
10 | }
11 |
12 | /*
13 | [4, 5, 6]
14 | [4, 5, 6]
15 | [4, 5, 6]
16 | [4, 5, 6]
17 | [4, 5, 6]
18 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/struct_union.v:
--------------------------------------------------------------------------------
1 | union Block {
2 | mut:
3 | x int
4 | str string
5 | }
6 |
7 | struct Sexpr {
8 | car Block
9 | cdr Block
10 | }
11 |
12 | fn main() {
13 | mut q1 := Block{str: 'This'}
14 | q1.str = 'Rosa'
15 | mut q2 := Block{x: 40}
16 | q2.x = 42
17 | q := Sexpr{car: q1, cdr: q2}
18 | println(q.car.str) // => Rosa
19 | println('$q.cdr.x') // => 42
20 | }
--------------------------------------------------------------------------------
/Chapter_7_Arrays/arr_reverse.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | names := ['Abby', 'Bob', 'Carl']
3 |
4 | for i := names.len-1; i >= 0; i-- {
5 | println(names[i])
6 | }
7 |
8 | mut j := names.len-1
9 | for j >= 0 {
10 | println(names[j])
11 | j--
12 | }
13 |
14 | for name in names.reverse() {
15 | println(name)
16 | }
17 | }
18 |
19 | /* 3 times:
20 | Carl
21 | Bob
22 | Abby
23 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/exercises/has_fur.v:
--------------------------------------------------------------------------------
1 | struct Animal {
2 | species string
3 | has_fur bool
4 | }
5 |
6 | fn main() {
7 | ali := Animal {
8 | species: 'alligator'
9 | has_fur: false
10 | }
11 | bob := Animal {
12 | species: 'dog'
13 | has_fur: true
14 | }
15 | println(ali.has_fur) // => false
16 | println(bob.has_fur) // => true
17 | }
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/mutable_receiver.v:
--------------------------------------------------------------------------------
1 | struct User {
2 | mut:
3 | is_registered bool
4 | }
5 |
6 | fn (u mut User) register() {
7 | u.is_registered = true
8 | }
9 |
10 | mut user := User{}
11 | println(user.is_registered) // => false
12 | user.register()
13 | println(user.is_registered) // => true
14 | println(user)
15 |
16 | /*
17 | false
18 | true
19 | {
20 | is_registered: 1
21 | }
22 | */
--------------------------------------------------------------------------------
/Chapter_8_Maps/word_counter/README.md:
--------------------------------------------------------------------------------
1 | ```
2 | usage: word_counter [text_file]
3 | using cinderella.txt
4 | a => 25
5 | able => 2
6 | after => 1
7 | afterwards => 1
8 | again => 10
9 | against => 2
10 | all => 12
11 | allow => 1
12 | allowed => 2
13 | along => 1
14 | also => 2
15 | always => 2
16 | an => 4
17 | and => 140
18 | anew => 1
19 | anger => 1
20 | another => 2
21 | answered => 1
22 | any => 1
23 | anyone => 2
24 | ...
25 | ```
26 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/send_a_value_to_another_thread.v:
--------------------------------------------------------------------------------
1 | // Idiom #25 Send a value to another thread
2 | // Share the string value "Alan" with an existing running process
3 | // which will then display "Hello, Alan"
4 | import (
5 | time
6 | )
7 |
8 | fn send(s string) {
9 | println(s) // Alan
10 | }
11 |
12 | str := 'Alan'
13 | go send(str)
14 | // Make sure the non-main coroutine had the chance to finish.
15 | time.sleep(1)
16 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vcasino/README.md:
--------------------------------------------------------------------------------
1 | # VCasino
2 | VCasino is a very simple game made to learn V.
3 |
4 | # Compile and Run
5 |
6 | Use this to generate a binary and then launch the game.
7 | ```bash
8 | v VCasino.v
9 | ./VCasino
10 | ```
11 |
12 | And this to compile and launch the game directly.
13 | ```bash
14 | v run VCasino.v
15 | ```
16 |
17 | Created by Thomas Senechal : https://github.com/thomas-senechal/VCasino
18 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/hanoi.v:
--------------------------------------------------------------------------------
1 | // hanoi tower
2 | const (
3 | Num = 7
4 | )
5 |
6 | fn main() {
7 | hanoi(Num, 'A','B','C')
8 | }
9 |
10 | fn move(n int, a, b string) int {
11 | println('Disc $n from $a to $b\...')
12 | return 0
13 | }
14 |
15 | fn hanoi(n int, a, b, c string) int {
16 | if n == 1 {
17 | move(1,a,c)
18 | } else {
19 | hanoi(n-1, a, c, b)
20 | move(n,a,c)
21 | hanoi(n-1, b, a, c)
22 | }
23 | return 0
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/visibility.v:
--------------------------------------------------------------------------------
1 | struct User {
2 | email string
3 | mut:
4 | first_name string
5 | last_name string
6 |
7 | pub:
8 | sin_number int
9 | pub mut:
10 | phone int // this is public mutable
11 | __global: // this is mutable in- and out, and public
12 | address_1 string
13 | address_2 string
14 | city string
15 | country string
16 | zip string
17 | }
18 |
19 | fn main() {}
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile
2 | Makefile.in
3 | .deps
4 | *.rc
5 | chocolate-doom
6 | chocolate-heretic
7 | chocolate-hexen
8 | chocolate-server
9 | chocolate-strife
10 | chocolate-doom-setup
11 | chocolate-heretic-setup
12 | chocolate-hexen-setup
13 | chocolate-strife-setup
14 | chocolate-setup
15 | *.cfg
16 | *.exe
17 | *.desktop
18 | *.txt
19 | !CMakeLists.txt
20 | *.metainfo.xml
21 | tags
22 | TAGS
23 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/filter_log.v:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | // Print file lines that starth with "DEBUG:"
4 | fn main() {
5 | // `read_file` returns an optional (`?string`), it must be checked
6 | text := os.read_file('app.log') or {
7 | eprintln('failed to read the file')
8 | return
9 | }
10 | lines := text.split_into_lines()
11 | for line in lines {
12 | if line.starts_with('DEBUG:') {
13 | println(line)
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/Chapter_3_IDE/debugging/ex1_debug.v:
--------------------------------------------------------------------------------
1 | const (
2 | ac = 'budapest'
3 | )
4 |
5 | fn main() {
6 | println(ac)
7 | mut n := 3
8 | mut m := 7
9 | for i in 1..5 {
10 | n++
11 | m += n * 2
12 | println('$m after $i times')
13 | }
14 | println('')
15 | println(n) // 7
16 | println(m) // 51
17 | }
18 | /* Output:
19 | budapest
20 | 15 after 1 times
21 | 25 after 2 times
22 | 37 after 3 times
23 | 51 after 4 times
24 |
25 | 7
26 | 51
27 | */
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/if_expressions.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | num := 777
3 | s := if num % 2 == 0 {
4 | 'even'
5 | }
6 | else {
7 | 'odd'
8 | }
9 | println(s) // => "odd"
10 |
11 | // multiple lines in each branch
12 | s2 := if num % 2 == 0 {
13 | println('1st branch')
14 | 'even'
15 | }
16 | else {
17 | println('2nd branch') // => 2nd branch
18 | 'odd'
19 | }
20 | println(s2) // => "odd"
21 | }
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/data/address_us/state_abbr:
--------------------------------------------------------------------------------
1 | AL
2 | AK
3 | AZ
4 | AR
5 | CA
6 | CO
7 | CT
8 | DE
9 | FL
10 | GA
11 | HI
12 | ID
13 | IL
14 | IN
15 | IA
16 | KS
17 | KY
18 | LA
19 | ME
20 | MD
21 | MA
22 | MI
23 | MN
24 | MS
25 | MO
26 | MT
27 | NE
28 | NV
29 | NH
30 | NJ
31 | NM
32 | NY
33 | NC
34 | ND
35 | OH
36 | OK
37 | OR
38 | PA
39 | RI
40 | SC
41 | SD
42 | TN
43 | TX
44 | UT
45 | VT
46 | VA
47 | WA
48 | WV
49 | WI
50 | WY
51 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/crypto/sha256/sha256_test.v:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
2 | // Use of this source code is governed by an MIT license
3 | // that can be found in the LICENSE file.
4 |
5 | import crypto.sha256
6 |
7 | fn test_crypto_sha256() {
8 | assert sha256.sum('This is a sha256 checksum.'.bytes()).hex() ==
9 | 'dc7163299659529eae29683eb1ffec50d6c8fc7275ecb10c145fde0e125b8727'
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/defer_tracing.v:
--------------------------------------------------------------------------------
1 | fn trace(s string) { println('entering: $s') }
2 | fn untrace(s string) { println('leaving: $s') }
3 |
4 | fn a() {
5 | trace("a")
6 | defer { untrace("a") }
7 | println("in a")
8 | }
9 |
10 | fn b() {
11 | trace("b")
12 | defer { untrace("b") }
13 | println("in b")
14 | a()
15 | }
16 |
17 | b()
18 |
19 | /*
20 | entering: b
21 | in b
22 | entering: a
23 | in a
24 | leaving: a
25 | leaving: b
26 | */
27 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/multidim2.v:
--------------------------------------------------------------------------------
1 | fn main () {
2 | mut marr := [[0].repeat(3)].repeat(5)
3 | for i := 0; i < 5; i++ {
4 | marr[i] = [0].repeat(3)
5 | for j :=0 ; j < 3; j++ {
6 | marr[i][j] = i + j
7 | // println( '$i, $j, ${i + j}' )
8 | }
9 | }
10 | for i := 0; i < 5; i++ { println(marr[i]) }
11 | }
12 |
13 | /* Output:
14 | [0, 1, 2]
15 | [1, 2, 3]
16 | [2, 3, 4]
17 | [3, 4, 5]
18 | [4, 5, 6]
19 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/color_struct.v:
--------------------------------------------------------------------------------
1 | struct Color {
2 | r int
3 | g int
4 | b int
5 | }
6 |
7 | pub fn (c Color) str() string { return '{$c.r, $c.g, $c.b}' }
8 |
9 | fn rgb(r, g, b int) Color { return Color{r: r, g: g, b: b} }
10 |
11 | const (
12 | red = Color{r: 255, g: 0, b: 0}
13 | blue = rgb(0, 0, 255)
14 | )
15 |
16 | println(red) // => {255, 0, 0}
17 | println(blue) // => {0, 0, 255}
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/data/address_br/state:
--------------------------------------------------------------------------------
1 | Acre
2 | Alagoas
3 | Amapá
4 | Amazonas
5 | Bahia
6 | Ceará
7 | Distrito Federal
8 | Espírito Santo
9 | Goiás
10 | Maranhão
11 | Mato Grosso
12 | Mato Grosso do Sul
13 | Minas Gerais
14 | Paraná
15 | Paraíba
16 | Pará
17 | Pernambuco
18 | Piauí
19 | Rio de Janeiro
20 | Rio Grande do Norte
21 | Rio Grande do Sul
22 | Rondonia
23 | Roraima
24 | Santa Catarina
25 | Sergipe
26 | São Paulo
27 | Tocantins
28 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/constants.v:
--------------------------------------------------------------------------------
1 | const (
2 | pi = 3.1415
3 | inch_to_cm = 2.54
4 | greek_greeting = 'Καλημέρα κόσμε'
5 | asian_greeting = 'こんにちは 世界'
6 | input = '{ "name": "Frodo", "age": 25 }'
7 | )
8 |
9 | println(pi)
10 | println(inch_to_cm )
11 | println(greek_greeting)
12 | println(asian_greeting)
13 | println(input)
14 |
15 | /* Output:
16 | 3.141500
17 | 2.540000
18 | Καλημέρα κόσμε
19 | こんにちは 世界
20 | { "name": "Frodo", "age": 25 }
21 | */
--------------------------------------------------------------------------------
/Chapter_6_Functions/varnumpar.v:
--------------------------------------------------------------------------------
1 | fn min(a ...int) int {
2 | if a.len == 0 { return 0 }
3 | mut min := a[0]
4 | for v in a {
5 | if v < min { min = v }
6 | }
7 | return min
8 | }
9 |
10 | x := min(1, 3, -8, 2, 0)
11 | println('The minimum is: $x') // The minimum is: -8
12 |
13 | /* doesn't work yet:
14 | arr := [7, 9, -8, 3, 5, 1]
15 | y := min(arr...) // expected type `[]int`, but got `int`
16 | println('The minimum in the array arr is: $y')
17 | */
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/array_max_fn.v:
--------------------------------------------------------------------------------
1 | // Write a V program to get the largest element of an array using a function.
2 |
3 | fn arr_max(arr []int) int {
4 | mut max := arr[0]
5 | for item in arr {
6 | if item > max { max = item }
7 | }
8 | return max
9 | }
10 |
11 | fn main() {
12 | arr := [0, -45, 78, 345, 12, 77]
13 | max := arr_max(arr)
14 | println('The maximum is: $max') // => 345
15 | println('The maximum is: ${arr_max(arr)}') // => 345
16 | }
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/http_get.v:
--------------------------------------------------------------------------------
1 | import time
2 | import net.http
3 |
4 | fn main() {
5 | resp := http.get('https://vlang.io/utc_now') or {
6 | println('failed to fetch data from the server')
7 | return
8 | }
9 |
10 | t := time.unix(resp.text.int())
11 | println(t.format())
12 | }
13 |
14 | /*
15 | warning: c:\v\vlib\net\http\backend_windows.v:18:19: you are calling an unsafe function outside of an unsafe block
16 | 2020-03-17 09:58
17 | */
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/owmw/owmw.v:
--------------------------------------------------------------------------------
1 | module owmw
2 |
3 | const (
4 | base_url = 'https://api.openweathermap.org/data/2.5/'
5 | )
6 |
7 | // owmw\owmw.v:7:12: init function cannot be public
8 | // fn init() {}
9 |
10 | pub fn start(token string, m int) Weather {
11 | mut metric := 'imperial'
12 | if (m == 1) {
13 | metric = 'metric'
14 | }
15 |
16 | return Weather {
17 | metric: metric
18 | token: token
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/pick_a_random_element_from_a_list.v:
--------------------------------------------------------------------------------
1 | // Idiom #11 Pick a random element from a list
2 | // List x must be non-empty.
3 |
4 | import (
5 | rand
6 | time
7 | )
8 |
9 | fn main() {
10 | nums := [1, 2, 3, 4, 5]
11 |
12 | t := time.now()
13 | s := t.calc_unix()
14 | rand.seed(s)
15 |
16 | println(rand_pick(nums))
17 | }
18 |
19 | fn rand_pick(x []int) int {
20 | return x[rand.next(x.len)]
21 | }
22 |
23 | // Output e.g.: 4
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/README.md:
--------------------------------------------------------------------------------
1 | # VORE (vOS Runtime Environment)
2 |
3 | A fork of [vlib](https://github.com/vlang/v/tree/master/vlib) optimized for bare-metal/embedded environments.
4 |
5 | Usage:
6 |
7 | ```
8 | $ v -freestanding -vlib_path /path/to/v_runtime/vlib -o /path/to/output.c build /path/to/source_directory
9 | $ gcc -ffreestanding -std=gnu-99 -nostdlib -lgcc -I/path/to/v_runtime -o output.elf output.c vrt_main.c /path/to/v_runtime/vrt_impl.c
10 | ```
--------------------------------------------------------------------------------
/Chapter_8_Maps/map_array.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | // areas := ['game', 'web', "\\'", 'systems', 'GUI', 'mobile']
3 | areas := ['game', 'web', r'\'', 'systems', 'GUI', 'mobile']
4 | for _, area in areas {
5 | println('Hello, $area developers!')
6 | }
7 | }
8 |
9 | /*
10 | Hello, game developers!
11 | Hello, web developers!
12 | Hello, \' developers!
13 | Hello, systems developers!
14 | Hello, GUI developers!
15 | Hello, mobile developers!
16 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/house_animals.v:
--------------------------------------------------------------------------------
1 | interface Speaker {
2 | speak() string
3 | }
4 |
5 | struct Dog { }
6 | struct Cat { }
7 |
8 | fn (d Dog) speak() string {
9 | return 'woof'
10 | }
11 |
12 | fn (c Cat) speak() string {
13 | return 'meow'
14 | }
15 |
16 | fn perform(s Speaker) string {
17 | return s.speak()
18 | }
19 |
20 | dog := Dog{}
21 | cat := Cat{}
22 | println(perform(dog)) // -> "woof"
23 | println(perform(cat)) // -> "meow"
24 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/hello_world/hello_webworld.v:
--------------------------------------------------------------------------------
1 | //module main
2 | import (
3 | time
4 | vweb
5 | )
6 |
7 | struct App {
8 | mut:
9 | vweb vweb.Context
10 | }
11 |
12 | pub fn (app &App) init() {}
13 |
14 | fn (app mut App) index() {
15 | app.vweb.text('Hello, world from vweb!')
16 | }
17 |
18 | fn (app mut App) time() {
19 | app.vweb.text(time.now().format())
20 | }
21 |
22 | fn main() {
23 | app := App{}
24 | vweb.run(mut app, 8080)
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/array_memory.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut a := [1, 2, 3]
3 | mut b := a
4 | loc1 := &a
5 | loc2 := &b
6 | println(loc1) // => 000000000061FD60
7 | println(loc2) // => 000000000061FD40
8 | b[0] = 0
9 | println(a) // => [0, 2, 3]
10 | println(b) // => [0, 2, 3]
11 |
12 | c := a.clone()
13 | println(&c) // => // 000000000061FCD0
14 | a[2] = 9
15 | println(a) // => [0, 2, 9]
16 | println(b) // => [0, 2, 9]
17 | println(c) // => [0, 2, 3]
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/method_enum2.v:
--------------------------------------------------------------------------------
1 | enum Feeling {
2 | happy
3 | sad
4 | nothing
5 | }
6 |
7 | fn (f Feeling) to_byte() byte {
8 | return match f {
9 | .happy { 0 }
10 | .sad { 1 }
11 | .nothing { 2 }
12 | }
13 | }
14 |
15 | fn encode_feeling(f Feeling) byte {
16 | b := f.to_byte()
17 | return b
18 | }
19 |
20 | fn main() {
21 | f1 := Feeling.sad
22 | println(int(f1.to_byte())) // 1
23 | println(int(encode_feeling(f1))) // 1
24 | }
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/web_blog/spiral 3 - blog_orm/error.txt:
--------------------------------------------------------------------------------
1 | ivo@ivo-SATELLITE-L50D-B:~/blog_orm$ v run .
2 | sql query="select id, title, text from Articles"
3 | /tmp/v/blog_orm.tmp.c: In function ‘pg__connect’:
4 | /tmp/v/blog_orm.tmp.c:3960:18: warning: pointer targets in initialization of ‘byte *’ {aka ‘unsigned char *’} from ‘char *’ differ in signedness [-Wpo...
5 | (Use `v -g` to print the entire error message)
6 |
7 | V error: C error. This should never happen.
8 |
--------------------------------------------------------------------------------
/Chapter_10_Option_Types_Error_Handling/option1D.v:
--------------------------------------------------------------------------------
1 | import os
2 | fn test_file(fnameout string) {
3 | mut fout := os.File{cfile: 0}
4 | if fnameout != '' {
5 | fout = os.create(fnameout) or {panic(err)}
6 | println(fout)
7 | }
8 | println(fout)
9 | }
10 |
11 | test_file('test.tmp')
12 |
13 | /*
14 | os.File {
15 | cfile: -620627312
16 | fd: 3
17 | opened: true
18 | }
19 | os.File {
20 | cfile: -620627312
21 | fd: 3
22 | opened: true
23 | }
24 | */
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/array_readin.v:
--------------------------------------------------------------------------------
1 | // Write a V program to read n number of values in an array and display it in reverse order:
2 | import os
3 |
4 | fn main() {
5 | print('Give in the length of the array: ')
6 | arr_len := os.get_line().trim_space().int()
7 | mut arr := []int
8 | for i := 0; i < arr_len; i++ {
9 | print('Give an integer number: ')
10 | num := os.get_line().trim_space().int()
11 | arr << num
12 | }
13 | println(arr.reverse())
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/exercises/check_equal.v:
--------------------------------------------------------------------------------
1 | // Write a V program to accept two integers and check whether they are equal or not.
2 | import os
3 |
4 | fn main() {
5 | print('Give the 1st number: ')
6 | number1 := os.get_line().trim_space().int()
7 | print('Give the 2nd number: ')
8 | number2 := os.get_line().trim_space().int()
9 | if number1 == number2 {
10 | println('Both numbers are equal')
11 | } else {
12 | println('The two numbers are not equal')
13 | }
14 | }
--------------------------------------------------------------------------------
/Chapter_6_Functions/fibonacci.v:
--------------------------------------------------------------------------------
1 | fn fib(n int) int {
2 | if n <= 1 {
3 | return 1
4 | }
5 | return fib(n - 1) + fib(n - 2)
6 | }
7 |
8 | for i := 0; i < 10; i++ {
9 | println('fibonacci($i) is: ${fib(i)}')
10 | }
11 |
12 | /* Output:
13 | fibonacci(0) is: 1
14 | fibonacci(1) is: 1
15 | fibonacci(2) is: 2
16 | fibonacci(3) is: 3
17 | fibonacci(4) is: 5
18 | fibonacci(5) is: 8
19 | fibonacci(6) is: 13
20 | fibonacci(7) is: 21
21 | fibonacci(8) is: 34
22 | fibonacci(9) is: 55
23 | */
24 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/exercises/embedding_structs.v:
--------------------------------------------------------------------------------
1 | struct Thing {
2 | i int
3 | j int
4 | }
5 | struct Something {
6 | k int
7 | l Thing
8 | }
9 |
10 | fn main() {
11 | x := Thing{
12 | i: 2,
13 | j: 3
14 | }
15 | y := Something {
16 | k: 1,
17 | l: x
18 | }
19 | println(y)
20 | }
21 |
22 | /*
23 | Something {
24 | k: 1
25 | l: Thing {
26 | i: 2
27 | j: 3
28 | }
29 | }
30 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/mut_pointer.v:
--------------------------------------------------------------------------------
1 | struct S1 {
2 | mut:
3 | i int
4 | }
5 |
6 | fn main() {
7 | mut p1 := &S1{} // type: *S1
8 | p1.i++
9 | mut p2 := p1 // type: mut(*)S ??
10 | s1 := S1{}
11 | p2 = &s1
12 | p2.i++
13 | println(s1)
14 | s2 := S1{}
15 | p2 = &s2
16 | mut p3 := &s2 // type: *mut(S) ??
17 | p3.i++
18 | mut p4 := &s2
19 | p4.i++
20 | println(s2)
21 | }
22 |
23 | /* Output:
24 | {
25 | i: 1
26 | }
27 | {
28 | i: 2
29 | }
30 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/test.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | // areas := ['game', 'web', "\\'", 'systems', 'GUI', 'mobile']
3 | areas := ['game', 'web', r'\'', 'systems', 'GUI', 'mobile']
4 | for _, area in areas {
5 | println('Hello, $area developers!')
6 | }
7 | }
8 |
9 | /*
10 | Hello, game developers!
11 | Hello, web developers!
12 | Hello, \' developers!
13 | Hello, systems developers!
14 | Hello, GUI developers!
15 | Hello, mobile developers!
16 | */
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/tetris/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | Tetris has a temporary dependency on GLFW.
4 |
5 | ## macOS
6 | `brew install glfw`
7 |
8 | ## Ubuntu
9 | `sudo apt install libglfw3 libglfw3-dev libfreetype6-dev libssl-dev`
10 |
11 | ## Arch (and Manjaro)
12 | `sudo pacman -S glfw-x11`
13 |
14 | ## Windows
15 | Copy `thirdparty/glfw/glfw3.dll` to this directory.
16 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/web_blog/spiral 1 - hello_world/hello_webworld.v:
--------------------------------------------------------------------------------
1 | //module main
2 | import (
3 | time
4 | vweb
5 | )
6 |
7 | struct App {
8 | mut:
9 | vweb vweb.Context
10 | }
11 |
12 | pub fn (app &App) init() {}
13 |
14 | fn (app mut App) index() {
15 | app.vweb.text('Hello, world from vweb!')
16 | }
17 |
18 | fn (app mut App) time() {
19 | app.vweb.text(time.now().format())
20 | }
21 |
22 | fn main() {
23 | app := App{}
24 | vweb.run(mut app, 8080)
25 | }
26 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/cmake/config.h.cin:
--------------------------------------------------------------------------------
1 | #cmakedefine PACKAGE_NAME "@PACKAGE_NAME@"
2 | #cmakedefine PACKAGE_TARNAME "@PACKAGE_TARNAME@"
3 | #cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
4 | #cmakedefine PACKAGE_STRING "@PACKAGE_STRING@"
5 | #cmakedefine PROGRAM_PREFIX "@PROGRAM_PREFIX@"
6 |
7 | #cmakedefine HAVE_LIBSAMPLERATE
8 | #cmakedefine HAVE_LIBPNG
9 | #cmakedefine HAVE_DIRENT_H
10 | #cmakedefine01 HAVE_DECL_STRCASECMP
11 | #cmakedefine01 HAVE_DECL_STRNCASECMP
12 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/exercises/rectangle_stars.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | w := 20
3 | h := 10
4 | for y := 0; y < h; y++ {
5 | for x := 0; x < w; x++ {
6 | print('*')
7 | }
8 | println('')
9 | }
10 | }
11 |
12 | /* Output:
13 | ********************
14 | ********************
15 | ********************
16 | ********************
17 | ********************
18 | ********************
19 | ********************
20 | ********************
21 | ********************
22 | ********************
23 | */
24 |
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/test_2866_defer.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | println('this order is ok, because the defer is activated at the end if the for }')
3 | for i := 0; i < 5; i++ {
4 | defer { println(i) }
5 | }
6 | println('correct order')
7 | defer { println(0) }
8 | defer { println(1) }
9 | defer { println(2) }
10 | defer { println(3) }
11 | defer { println(4) }
12 | }
13 | /*
14 | wrong order
15 | 0
16 | 1
17 | 2
18 | 3
19 | 4
20 | correct order
21 | 4
22 | 3
23 | 2
24 | 1
25 | 0
26 | */
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/array_dup_fun.v:
--------------------------------------------------------------------------------
1 | fn get_no_dup(arr mut []int) int {
2 | mut dup := 0
3 | arr.sort()
4 | for i := 0; i < arr.len; i++ {
5 | if i + 1 == arr.len { break } // to avoid index out of range
6 | if arr[i + 1] == arr[i] { dup++ }
7 | }
8 | return dup
9 | }
10 |
11 | fn main() {
12 | mut arr1 := [12, 2, -3, 42, 2, 42, 108, 42] // no of duplicates: 3
13 | println('The number of duplicates is: ${get_no_dup(mut arr1)}') // => The number of duplicates is: 3
14 | }
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | ## [v0.1.0](https://github.com/vbrazo/faker/tree/v0.1.0) (2019-14-09)
4 |
5 | ## Feature Request
6 |
7 | - [PR #3](https://github.com/fvbrazo/faker/pull/3) Add address_ca data [@vbrazo](https://github.com/vbrazo)
8 | - [PR #2](https://github.com/vbrazo/faker/pull/2) Add address_br data [@vbrazo](https://github.com/vbrazo)
9 | - [PR #1](https://github.com/vbrazo/faker/pull/1) Add Address data [@vbrazo](https://github.com/vbrazo)
10 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/kernel/mm/paging.v:
--------------------------------------------------------------------------------
1 | module mm
2 |
3 | pub const (
4 | PAGE_SIZE = 0x1000
5 | LARGE_PAGE_SIZE = 0x200000
6 | HUGE_PAGE_SIZE = 0x40000000
7 |
8 | PFLAG_PRESENT = (1 << 0)
9 | PFLAG_READ_WRITE = (1 << 1)
10 | PFLAG_USER = (1 << 2)
11 | PFLAG_WRITE_THROUGH = (1 << 3)
12 | PFLAG_CACHE_DISABLED = (1 << 4)
13 | PFLAG_ACCESSED = (1 << 5)
14 | PFLAG_DIRTY = (1 << 6)
15 | PFLAG_PAGE_SIZE = (1 << 7)
16 | PFLAG_GLOBAL = (1 << 8)
17 | )
18 |
19 | pub fn paging_init() {
20 |
21 | }
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/random_ips.v:
--------------------------------------------------------------------------------
1 | import (
2 | rand
3 | time
4 | )
5 |
6 | fn main() {
7 | rand.seed(time.now().calc_unix()) // voorlopig opsplitsen
8 |
9 | for _ in 0..10 {
10 | println('${rand.next(255)}.${rand.next(255)}.${rand.next(255)}.${rand.next(255)}')
11 | }
12 | }
13 |
14 | /* Output:
15 | 60.188.170.141
16 | 113.78.59.121
17 | 87.71.87.7
18 | 69.27.231.62
19 | 35.27.206.65
20 | 178.221.12.147
21 | 181.21.138.11
22 | 89.189.10.49
23 | 34.133.12.204
24 | 205.213.77.234
25 | */
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/array_copy.v:
--------------------------------------------------------------------------------
1 | // Write a V program to copy the elements of one array into another array
2 | // doesn't work without main
3 | // use clone() method
4 |
5 | fn main() {
6 | arr1 := [1, 2, 3, 4]
7 | mut arr2 := [0].repeat(arr1.len)
8 | println('arr2 before copy: $arr2')
9 | for i := 0; i < arr1.len; i++ {
10 | arr2[i] = arr1[i]
11 | }
12 | println('arr2 after copy: $arr2')
13 | }
14 |
15 | /*
16 | arr2 before copy: [0, 0, 0, 0]
17 | arr2 after copy: [1, 2, 3, 4]
18 | */
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/crypto/sha512/sha512_test.v:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
2 | // Use of this source code is governed by an MIT license
3 | // that can be found in the LICENSE file.
4 |
5 | import crypto.sha512
6 |
7 | fn test_crypto_sha512() {
8 | assert sha512.sum512('This is a sha512 checksum.'.bytes()).hex() == '4143e55fcba7e39b20f62a1368e5eb28f64a8859458886117ac66027832e0f9f5263daec688c439d2d0fa07059334668d39e59543039703dbb7e03ec9da7f8d7'
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/operator_overloading.v:
--------------------------------------------------------------------------------
1 | struct Vec {
2 | x int
3 | y int
4 | }
5 |
6 | fn (a Vec) str() string {
7 | return '{$a.x, $a.y}'
8 | }
9 |
10 | fn (a Vec) + (b Vec) Vec {
11 | return Vec {
12 | a.x + b.x,
13 | a.y + b.y
14 | }
15 | }
16 |
17 | fn (a Vec) - (b Vec) Vec {
18 | return Vec {
19 | a.x - b.x,
20 | a.y - b.y
21 | }
22 | }
23 |
24 | fn main() {
25 | a := Vec{2, 3}
26 | b := Vec{4, 5}
27 | println(a + b) // "{6, 8}"
28 | println(a - b) // "{-2, -2}"
29 | }
30 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pcsound/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_library(pcsound STATIC
2 | pcsound.c pcsound.h
3 | pcsound_bsd.c
4 | pcsound_sdl.c
5 | pcsound_linux.c
6 | pcsound_win32.c
7 | pcsound_internal.h)
8 | target_include_directories(pcsound
9 | INTERFACE "."
10 | PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
11 | target_link_libraries(pcsound SDL2::mixer)
12 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/part_pure.v:
--------------------------------------------------------------------------------
1 | // This cannot work:
2 | /*
3 | part_pure.v:6 mutable arguments are only allowed for arrays, maps, and structs.
4 | return values instead: `foo(n mut int)` => `foo(n int) int`
5 |
6 | fn non_pure (a mut int) int {
7 | b := a * 5
8 | return b
9 | }
10 |
11 | n := non_pure(10)
12 | println(n)
13 |
14 | */
15 |
16 | // This works:
17 | fn non_pure (a int) int {
18 | b := a * 5
19 | return b
20 | }
21 |
22 | n := non_pure(10)
23 | println(n) // => 50
24 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/method_enum.v:
--------------------------------------------------------------------------------
1 | enum Format {
2 | undefined
3 | a
4 | rgb
5 | rgba
6 | }
7 |
8 | fn (format Format) bytes_per_pixel() int {
9 | if format == .a {
10 | return 1
11 | } else if format == .rgb {
12 | return 3
13 | } else if format == .rgba {
14 | return 4
15 | } else {
16 | panic('can\'t derive bpp from format $format')
17 | }
18 | }
19 |
20 | fn main() {
21 | v := Format.a
22 | println(v.bytes_per_pixel()) // => 1
23 | }
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/operator_overloading.v:
--------------------------------------------------------------------------------
1 | struct Vec {
2 | x int
3 | y int
4 | }
5 |
6 | fn (a Vec) str() string {
7 | return '{$a.x, $a.y}'
8 | }
9 |
10 | fn (a Vec) + (b Vec) Vec {
11 | return Vec {
12 | a.x + b.x,
13 | a.y + b.y
14 | }
15 | }
16 |
17 | fn (a Vec) - (b Vec) Vec {
18 | return Vec {
19 | a.x - b.x,
20 | a.y - b.y
21 | }
22 | }
23 |
24 | fn main() {
25 | a := Vec{2, 3}
26 | b := Vec{4, 5}
27 | println(a + b) // "{6, 8}"
28 | println(a - b) // "{-2, -2}"
29 | }
30 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/interfaces.v:
--------------------------------------------------------------------------------
1 | interface Shaper {
2 | area() f64
3 | // perimeter() f64
4 | }
5 |
6 | struct Square {
7 | mut:
8 | side f64
9 | }
10 |
11 | fn (sq Square) area() f64 {
12 | return sq.side * sq.side
13 | }
14 |
15 | fn calc_area(sh Shaper) f64 {
16 | return sh.area()
17 | }
18 |
19 | fn main() {
20 | mut sq1 := Square{}
21 | sq1.side = 5
22 | println('The square has area: ${calc_area(sq1)}')
23 | }
24 | // The square has area: 25.000000
25 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/exercises/print_dollar.v:
--------------------------------------------------------------------------------
1 | const (
2 | USD_VALUE = 1.0
3 | YEN_VALUE = 108.0
4 | DYNAMIC_DISPLAY_STR = '$$USD_VALUE = ¥$YEN_VALUE'
5 | )
6 |
7 | fn main() {
8 | ss_var := '$:USD'
9 | println('Vlang : $ inside string')
10 | println('ss_var = $ss_var')
11 |
12 | println(USD_VALUE)
13 | println(YEN_VALUE)
14 | println(DYNAMIC_DISPLAY_STR)
15 | }
16 |
17 | /* Output:
18 | Vlang : $ inside string
19 | ss_var = $:USD
20 | 1.000000
21 | 108.000000
22 | $1.000000 = ¥108.000000
23 | */
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/pick_uniformly_a_random_int_point_number_in.v:
--------------------------------------------------------------------------------
1 | // Idiom #15 Pick uniformly a random integer in [a..b]
2 | // Pick a random integer greater than or equals to a, inferior or equals to b. Precondition : a < b.
3 |
4 | import (
5 | rand
6 | time
7 | )
8 |
9 | fn main() {
10 | t := time.now()
11 | s := t.calc_unix()
12 | rand.seed(s)
13 |
14 | println(rand_picki(314, 516))
15 | }
16 |
17 | fn rand_picki(a, b int) int {
18 | return a + (rand.next(b - a + 1))
19 | }
20 |
21 | // Output e.g.: 491
--------------------------------------------------------------------------------
/Chapter_7_Arrays/hello_developers.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | areas := ['game', 'web', 'tools', 'science', 'systems',
3 | 'embedded', 'drivers', 'GUI', 'mobile']
4 | for area in areas {
5 | println('Hello, $area developers!')
6 | }
7 | }
8 |
9 | /* Output:
10 | Hello, game developers!
11 | Hello, web developers!
12 | Hello, tools developers!
13 | Hello, science developers!
14 | Hello, systems developers!
15 | Hello, embedded developers!
16 | Hello, drivers developers!
17 | Hello, GUI developers!
18 | Hello, mobile developers!
19 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/enum_interface.v:
--------------------------------------------------------------------------------
1 | interface Byter {
2 | to_byte() byte
3 | }
4 |
5 | enum Feeling {
6 | happy
7 | sad
8 | nothing
9 | }
10 |
11 | fn (f Feeling) to_byte() byte {
12 | return match f {
13 | .happy { 0 }
14 | .sad { 1 }
15 | .nothing { 2 }
16 | }
17 | }
18 |
19 | fn encode_byter(byter Byter) byte {
20 | b := int(byter.to_byte())
21 | return b
22 | }
23 |
24 | fn main() {
25 | f1 := Feeling.sad
26 | println(int(f1.to_byte())) // 1
27 | println(int(encode_byter(f1))) // 1
28 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/textscreen/fonts/Makefile.am:
--------------------------------------------------------------------------------
1 | FONT_HDRS = small.h normal.h large.h codepage.h
2 | EXTRA_DIST = small.png normal.png large.png convert-font $(FONT_HDRS)
3 |
4 | noinst_DATA = $(FONT_HDRS)
5 |
6 | if HAVE_PYTHON
7 |
8 | small.h: small.png convert-font
9 | ./convert-font small small.png small.h
10 |
11 | normal.h: normal.png convert-font
12 | ./convert-font normal normal.png normal.h
13 |
14 | large.h: large.png convert-font
15 | ./convert-font large large.png large.h
16 |
17 | endif
18 |
19 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/defer_logvalues.v:
--------------------------------------------------------------------------------
1 | // defer_logvalues.go
2 | package main
3 |
4 | import (
5 | "io"
6 | "log"
7 | )
8 |
9 | func func1(s string) (n int, err error) {
10 | defer func() {
11 | log.Printf("func1(%q) = %d, %v", s, n, err)
12 | }()
13 | return 7, io.EOF
14 | }
15 |
16 | func main() {
17 | func1("Go")
18 | }
19 | // Output: 2019/02/23 14:49:39 func1("Go") = 7, EOF
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/manifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 | true
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/eventbus/some_module/some_module.v:
--------------------------------------------------------------------------------
1 | module some_module
2 |
3 | import (
4 | eventbus
5 | )
6 |
7 | const (
8 | eb = eventbus.new()
9 | )
10 |
11 | pub fn do_work(){
12 | mut params := eventbus.Params{}
13 | for i in 0..20 {
14 | println("working...")
15 | if i == 15 {
16 | params.put_string("error", "CRASH!!")
17 | eb.publish("error", params)
18 | eb.publish("error", params)
19 | return
20 | }
21 | }
22 | }
23 |
24 | pub fn get_subscriber() eventbus.Subscriber {
25 | return eb.subscriber
26 | }
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/array_even.v:
--------------------------------------------------------------------------------
1 | // Write a V program that creates an array of all even numbers from 1 to 50
2 |
3 | fn is_even(num int) bool {
4 | return match num % 2 {
5 | 0 {true}
6 | else {false}
7 | }
8 | }
9 |
10 | fn main() {
11 | // println(is_even(4)) // true
12 | // println(is_even(7)) // false
13 | mut arr := []int
14 | for i := 0; i < 50; i++ {
15 | if is_even(i) { arr << i }
16 | }
17 | println(arr) // => [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48]
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/sound.v:
--------------------------------------------------------------------------------
1 | module main
2 |
3 | import os
4 | import time
5 | import miniaudio as ma
6 |
7 | fn main() {
8 | os.clear()
9 | //load sounds
10 | wav_file := 'click.wav'
11 | println('Loading wav')
12 | mut a := ma.from(wav_file)
13 | length := int(a.length())
14 |
15 | println('Playing wav '+length.str())
16 | a.play()
17 | time.sleep_ms(length)
18 |
19 | println('Playing wav '+length.str())
20 | a.play()
21 | time.sleep_ms(length)
22 |
23 | a.free()
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/web_blog/spiral 3 - blog_orm/blog.sql:
--------------------------------------------------------------------------------
1 | create database blog;
2 |
3 | \c blog
4 |
5 | drop table articles;
6 |
7 | create table articles
8 | (
9 | id serial primary key,
10 | title text default '',
11 | text text default ''
12 | );
13 |
14 | insert into articles
15 | (title, text)
16 | values
17 | (
18 | 'Hello, world!',
19 | 'V is great.'
20 | );
21 |
22 | insert into articles
23 | (title, text)
24 | values
25 | (
26 | 'Second post.',
27 | 'Hm... what should I write about?'
28 | );
29 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/stack.v:
--------------------------------------------------------------------------------
1 |
2 | fn main() {
3 | mut stack := []f32
4 |
5 | // push
6 | stack << 1.2
7 | stack << 2.2
8 | stack << 3.2
9 |
10 | // print the array and its length
11 | println(stack) // => [1.200000, 2.200000, 3.200000]
12 | println(stack.len) // => 3
13 |
14 | // pop last item
15 | temp := stack[stack.len - 1]
16 | stack.delete(stack.len - 1)
17 |
18 | // print the array and the popped item
19 | println(stack) // [1.200000, 2.200000]
20 | println(temp) // 3.200000
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/kernel/sys/kmain.v:
--------------------------------------------------------------------------------
1 | module sys
2 |
3 | import mm
4 |
5 | const (
6 | PHYS_BASE = 0xfffffeff00000000
7 | )
8 |
9 | enum BootloaderType {
10 | multiboot
11 | }
12 |
13 | struct BootloaderInfo {
14 | btype BootloaderType
15 | }
16 |
17 | pub fn kmain(bootloader_info &BootloaderInfo, magic int) {
18 | printk('Hello from bare-metal V world!')
19 |
20 | printk('info: $bootloader_info magic: $magic')
21 |
22 | mm.paging_init()
23 | printk('Paging initialized')
24 |
25 | printk('init exited, stalling...')
26 | for {
27 | }
28 | }
--------------------------------------------------------------------------------
/Chapter_8_Maps/map_forin.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut m := map[string]int
3 | m['one'] = 1
4 | m['two'] = 2
5 |
6 | for key, val in m {
7 | println('$key => $val')
8 | }
9 | /*
10 | one => 1
11 | two => 2
12 | */
13 | // only keys:
14 | for key, _ in m {
15 | println('$key')
16 | }
17 | /*
18 | one
19 | two
20 | */
21 | // or same output for:
22 | for key in m.keys() {
23 | println('$key')
24 | }
25 | // only values:
26 | for _, val in m {
27 | println('$val')
28 | }
29 | /*
30 | 1
31 | 2
32 | */
33 | }
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/interval.v:
--------------------------------------------------------------------------------
1 | struct Interval {
2 | start int
3 | end int
4 | }
5 |
6 | fn main() {
7 | inter := Interval{start: 0, end: 3}
8 | inter2 := Interval{end: 3, start: 0}
9 | inter3 := Interval{start: 0}
10 | inter4 := Interval{end: 3}
11 | println(inter)
12 | println(inter2)
13 | println(inter3)
14 | println(inter4)
15 | }
16 |
17 | /*
18 | {
19 | start: 0
20 | end: 3
21 | }
22 | {
23 | start: 0
24 | end: 3
25 | }
26 | {
27 | start: 0
28 | end: 0
29 | }
30 | {
31 | start: 0
32 | end: 3
33 | }
34 | */
35 |
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/data/address_us/state_and_territories_abbr:
--------------------------------------------------------------------------------
1 | AL
2 | AK
3 | AS
4 | AZ
5 | AR
6 | CA
7 | CO
8 | CT
9 | DE
10 | DC
11 | FM
12 | FL
13 | GA
14 | GU
15 | HI
16 | ID
17 | IL
18 | IN
19 | IA
20 | KS
21 | KY
22 | LA
23 | ME
24 | MH
25 | MD
26 | MA
27 | MI
28 | MN
29 | MS
30 | MO
31 | MT
32 | NE
33 | NV
34 | NH
35 | NJ
36 | NM
37 | NY
38 | NC
39 | ND
40 | MP
41 | OH
42 | OK
43 | OR
44 | PW
45 | PA
46 | PR
47 | RI
48 | SC
49 | SD
50 | TN
51 | TX
52 | UT
53 | VT
54 | VI
55 | VA
56 | WA
57 | WV
58 | WI
59 | WY
60 | AE
61 | AA
62 | AP
63 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/exercises/rectangle.v:
--------------------------------------------------------------------------------
1 | struct Rect {
2 | height int
3 | width int
4 | }
5 |
6 | fn (r Rect) area() int {
7 | return r.height * r.width
8 | }
9 |
10 | fn (r Rect) perimeter() int {
11 | return 2 * (r.height + r.width)
12 | }
13 |
14 | r1 := Rect{width: 4, height: 3}
15 | println(r1)
16 | println('Rectangle area is: ${r1.area()}')
17 | println('Rectangle perimeter is: ${r1.perimeter()}')
18 |
19 | /* Output:
20 | {
21 | height: 3
22 | width: 4
23 | }
24 | Rectangle area is: 12
25 | Rectangle perimeter is: 14
26 | */
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/math_op.v:
--------------------------------------------------------------------------------
1 | import math
2 |
3 | // where `x' and `y' are f64
4 | fn main() {
5 | x := 1.0
6 | y := 2.0
7 | println(math.e)
8 | println(math.pi)
9 | println(math.sqrt(x))
10 | println(math.log(x))
11 | println(math.log10(x))
12 | println(math.exp(x))
13 | println(math.abs(x))
14 | println(math.floor(x))
15 | println(math.ceil(x))
16 | println(math.pow(x, y))
17 | }
18 |
19 | /*
20 | 2.718282
21 | 3.141593
22 | 1.000000
23 | 0.000000
24 | 0.000000
25 | 2.718282
26 | 1.000000
27 | 1.000000
28 | 1.000000
29 | 1.000000
30 | */
31 |
--------------------------------------------------------------------------------
/Chapter_3_IDE/debugging/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 |
8 |
9 | {
10 | "name": "Debug",
11 | "type": "gdb",
12 | "request": "launch",
13 | "target": "${workspaceFolder}/ex1_debug.exe",
14 | "cwd": "${workspaceRoot}",
15 | "valuesFormatting": "parseText"
16 | }
17 | ]
18 | }
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 |
8 |
9 | {
10 | "name": "Debug",
11 | "type": "gdb",
12 | "request": "launch",
13 | "target": "${workspaceFolder}/match.exe",
14 | "cwd": "${workspaceRoot}",
15 | "valuesFormatting": "parseText"
16 | }
17 | ]
18 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/pcsound/Makefile.am:
--------------------------------------------------------------------------------
1 |
2 | AM_CFLAGS=@SDLMIXER_CFLAGS@
3 |
4 | EXTRA_DIST=CMakeLists.txt
5 |
6 | noinst_LIBRARIES=libpcsound.a
7 |
8 | libpcsound_a_SOURCES = \
9 | pcsound.c pcsound.h \
10 | pcsound_bsd.c \
11 | pcsound_sdl.c \
12 | pcsound_linux.c \
13 | pcsound_win32.c \
14 | pcsound_internal.h
15 |
16 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/shuffle_a_list.v:
--------------------------------------------------------------------------------
1 | // Idiom #10 Shuffle a list
2 | // Generate a random permutation of the elements of list x
3 |
4 | import (
5 | rand
6 | time
7 | )
8 |
9 | fn main() {
10 | mut nums := [1, 2, 3, 4, 5]
11 | mut temp := 0
12 |
13 | t := time.now()
14 | s := t.calc_unix()
15 | rand.seed(s)
16 |
17 | for ix, _ in nums {
18 | jx := rand.next(ix + 1)
19 | temp = nums[ix]
20 | nums[ix] = nums[jx]
21 | nums[jx] = temp
22 | }
23 | println(nums)
24 | }
25 |
26 | // Output: e.g.
27 | // [2, 1, 3, 5, 4]
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/structs.v:
--------------------------------------------------------------------------------
1 | struct User {
2 | id string
3 | name string
4 | }
5 |
6 | fn (u User) str() string {
7 | return u.name
8 | }
9 |
10 | fn main() {
11 | users := [
12 | User{id: '01', name: 'John'},
13 | User{id: '02', name: 'Amy'},
14 | ]
15 | for user in users {
16 | println(user)
17 | }
18 | }
19 |
20 | /* Output:
21 | John
22 | Amy
23 | */
24 |
25 | // Make an array with an empty User: users := [User{}]
26 |
27 | /* Make an array with one struct instance:
28 | u := User{id: '01', name: 'John'}
29 | users := [u]
30 | */
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/v-pong/README.MD:
--------------------------------------------------------------------------------
1 | # v-pong
2 | Pong written in V https://vlang.io/
3 | ## Project
4 | I was just fiddling around with V and the ui, and managed to create this.
5 |
6 | Preview on Twitter: https://twitter.com/XenialDan/status/1203521657266200576
7 | ## Build
8 | - To build on Windows you need the dll files
9 | - v build pong.v
10 | ## Planned
11 | - Better UI
12 | - Better platform control
13 | - Better enemy
14 | - Pause screen
15 | - Launch ball with space
16 | - Short boost with space
17 | - Cleanup
18 | - 2 Player mode
19 | - Key setup
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/system_time.v:
--------------------------------------------------------------------------------
1 | import time
2 |
3 | fn main() {
4 | t := time.now()
5 |
6 | // String representation
7 | println(t)
8 |
9 | // Unix time (number of seconds that have elapsed since 1970-01-01)
10 | println(t.uni)
11 |
12 | // There are different formats
13 | // YYYY-MM-DD HH:MM:SS
14 | println(t.format_ss())
15 | }
16 |
17 | /* Output:
18 | {
19 | year: 2019
20 | month: 11
21 | day: 21
22 | hour: 10
23 | minute: 49
24 | second: 45
25 | uni: 1574329785
26 | }
27 | 1574329785
28 | 2019-11-21 10:49:45
29 | */
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/type_alias.v:
--------------------------------------------------------------------------------
1 | type Integer i64
2 | type Float f64
3 |
4 | fn (i Integer) name() {
5 | println("Integer: $i")
6 | }
7 |
8 | fn (f Float) name() {
9 | println("Float: $f")
10 | }
11 |
12 | fn (i Integer) str() string {
13 | return "${int(i)}"
14 | }
15 |
16 | fn (f Float) str() string {
17 | return "${f64(f)}"
18 | }
19 |
20 | fn main() {
21 | i := Integer(42)
22 | i.name() // => Integer: 42
23 | println(i) // => 42
24 | f := Float(3.14)
25 | f.name() // => Float: 3.14
26 | println(f) // => 3.14
27 | }
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/exercises/check_leap_year.v:
--------------------------------------------------------------------------------
1 | // Write a V program to find whether a given year is a leap year or not.
2 | import os
3 |
4 | fn main() {
5 | mut leap := false
6 | print('Give the year: ')
7 | year := os.get_line().trim_space().int()
8 |
9 | // algorithm:
10 | if year % 4 != 0 { leap = false }
11 | else if year % 100 != 0 { leap = true }
12 | else if year % 400 != 0 { leap = false }
13 | else { leap = true }
14 |
15 | if leap {
16 | println('The year is a leap year')
17 | } else {
18 | println("The year isn't a leap year")
19 | }
20 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/prime.v:
--------------------------------------------------------------------------------
1 | fn main(){
2 | total := 100
3 | mut list := []bool{}
4 | for i := 0; i < total; i++{
5 | list << true
6 | }
7 | list[0] = false
8 | list[1] = false
9 | mut primes := [0,1]
10 | for i, index in list{
11 | //println(i)
12 | if index == false{
13 | continue
14 | }
15 | if index == true{
16 | primes << i
17 | for j := i * 2; j < total; j += i{
18 | list[j] = false
19 | }
20 | }
21 | }
22 | println(primes)
23 | }
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/strings.vh:
--------------------------------------------------------------------------------
1 | // vlib/strings module header
2 |
3 | module strings
4 |
5 | struct Builder {
6 | mut :
7 | buf []byte
8 | pub :
9 | len int
10 |
11 | }
12 | fn repeat (c byte, n int) string
13 | fn new_builder (initial_size int) Builder
14 | fn (b mut Builder) write (s string)
15 | fn (b mut Builder) writeln (s string)
16 | fn (b mut Builder) str () string
17 | fn (b mut Builder) free ()
18 | fn levenshtein_distance (a, b string) int
19 | fn levenshtein_distance_percentage (a, b string) f32
20 | fn dice_coefficient (s1, s2 string) f32
21 |
22 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/exercises/read_files.v:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | fn main() {
4 | file1 := 'test.txt'
5 | text := os.read_file(file1) or {
6 | eprintln('failed to read $file1')
7 | return
8 | }
9 | lines := text.split_into_lines()
10 | for line in lines { println(line) }
11 |
12 | file2 := 'no_test.txt'
13 | text2 := os.read_file(file2) or {
14 | eprintln('failed to read $file2')
15 | return
16 | }
17 | for line in text2.split_into_lines() { println(line) }
18 | }
19 |
20 | /*
21 | testing file writing!
22 | hello!
23 | failed to read no_test.txt
24 | */
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/exercises/employee_salary.v:
--------------------------------------------------------------------------------
1 | struct Employee {
2 | mut:
3 | salary f32
4 | }
5 |
6 | // a method which will add a specified percent to an employees salary
7 | fn (emp mut Employee) give_raise(pct f32) {
8 | emp.salary += emp.salary * pct
9 | }
10 |
11 | // create an employee instance
12 | mut e := Employee{}
13 | e.salary = 100.000
14 | println('Employee earns $e.salary$')
15 | // call our method
16 | e.give_raise(0.04)
17 | println('Employee now makes $e.salary$')
18 |
19 | /*
20 | Employee earns 100.000000$
21 | Employee now makes 104.000000$
22 | */
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/crypto/rand/rand.v:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
2 | // Use of this source code is governed by an MIT license
3 | // that can be found in the LICENSE file.
4 |
5 | module rand
6 |
7 | const (
8 | read_error = error('crypto.rand.read() error reading random bytes')
9 | )
10 |
11 | // NOTE: temp until we have []bytes(buff)
12 | fn c_array_to_bytes_tmp(len, buffer voidptr) []byte {
13 | mut arr := []byte
14 | arr = array {
15 | len: len
16 | cap: 1
17 | element_size: 1
18 | data: buffer
19 | }
20 | return arr
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/crypto/rand/rand_mac.v:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
2 | // Use of this source code is governed by an MIT license
3 | // that can be found in the LICENSE file.
4 |
5 | module rand
6 |
7 | #include
8 |
9 | #flag darwin -framework Security
10 |
11 | pub fn read(bytes_needed int) ?[]byte {
12 | mut buffer := malloc(bytes_needed)
13 | status := C.SecRandomCopyBytes(0, bytes_needed, buffer)
14 | if status != 0 {
15 | return read_error
16 | }
17 | return c_array_to_bytes_tmp(bytes_needed, buffer)
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/exercises/persons.v:
--------------------------------------------------------------------------------
1 | struct Person {
2 | name string
3 | gender string
4 | }
5 |
6 | fn main(){
7 | person_1 := Person{name: 'Roger', gender: 'M'}
8 | person_2 := Person{name: 'Jessica', gender: 'F'}
9 |
10 | println(person_1)
11 | println(person_2)
12 |
13 | persons := [person_1, person_2]
14 | println(persons)
15 | }
16 |
17 | /*
18 | {
19 | name: Roger
20 | gender: M
21 | }
22 | {
23 | name: Jessica
24 | gender: F
25 | }
26 | [{
27 | name: Roger
28 | gender: M
29 | }, {
30 | name: Jessica
31 | gender: F
32 | }]
33 | */
34 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/vweb/web_blog/spiral 3 - blog_orm/app.v:
--------------------------------------------------------------------------------
1 | module main
2 | import (
3 | pg // (1)
4 | vweb
5 | )
6 |
7 | struct App {
8 | mut:
9 | vweb vweb.Context
10 | db pg.DB
11 | }
12 |
13 | pub fn (app mut App) init() { // (2) mut App ipv &App
14 | db := pg.connect(pg.Config{
15 | host: '127.0.0.1'
16 | dbname: 'blog'
17 | user: 'postgress'
18 | }) or { panic(err) }
19 | app.db = db
20 | }
21 |
22 | fn (app App) index() {
23 | articles := app.find_all_articles()
24 | $vweb.html()
25 | }
26 |
27 | fn main() {
28 | app := App{}
29 | vweb.run(mut app, 8080)
30 | }
31 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/clipboard_test.v:
--------------------------------------------------------------------------------
1 | import clipboard
2 |
3 | fn run_test(is_primary bool){
4 | mut cb := if is_primary {clipboard.new_primary()} else {clipboard.new()}
5 | if !cb.is_available() {return}
6 | assert cb.check_ownership() == false
7 | assert cb.copy("I am a good boy!") == true
8 | assert cb.check_ownership() == true
9 | assert cb.paste() == "I am a good boy!"
10 | cb.clear_all()
11 | assert cb.paste().len <= 0
12 | cb.destroy()
13 | }
14 |
15 | fn test_primary(){
16 | $if linux {
17 | run_test(true)
18 | }
19 | }
20 |
21 | fn test_clipboard(){
22 | run_test(false)
23 | }
24 |
--------------------------------------------------------------------------------
/Chapter_3_IDE/hi.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | for i := 0; i < 3; i++ {
3 | println('Hello from V.js')
4 | }
5 | }
6 |
7 | // Windows:
8 | V.js compiler not found, building...
9 | c:\v\v.exejs.tmp.c: In function 'os__ls':
10 | c:\v\v.exejs.tmp.c:8013:42: error: dereferencing pointer to incomplete type 'struct dirent'
11 | string name= tos_clone ( ((byteptr)( ent ->d_name ) ) ) ;
12 | ...
13 | (Use `v -g` to print the entire error message)
14 |
15 | V error: C error. This should never happen.
16 | Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose
17 | Failed.
18 | */
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/factorial_recursive.v:
--------------------------------------------------------------------------------
1 | // recursive solution:
2 | const (
3 | MAX = 10
4 | )
5 |
6 | fn fac(n int) int {
7 | if n == 0 {
8 | return 1
9 | }
10 | return n * fac(n - 1)
11 | }
12 |
13 | for i := 0; i <= MAX; i++ {
14 | println('factorial($i) is: ${fac(i)}')
15 | }
16 |
17 | // Output:
18 | /*
19 | factorial(0) is: 1
20 | factorial(1) is: 1
21 | factorial(2) is: 2
22 | factorial(3) is: 6
23 | factorial(4) is: 24
24 | factorial(5) is: 120
25 | factorial(6) is: 720
26 | factorial(7) is: 5040
27 | factorial(8) is: 40320
28 | factorial(9) is: 362880
29 | factorial(10) is: 3628800
30 | */
--------------------------------------------------------------------------------
/Chapter_6_Functions/mut_recurs.v:
--------------------------------------------------------------------------------
1 | fn even(nr int) bool {
2 | if nr == 0 {return true}
3 | return odd(rev_sign(nr) - 1)
4 | }
5 |
6 | fn odd(nr int) bool {
7 | if nr == 0 {return false}
8 | return even(rev_sign(nr) - 1)
9 | }
10 |
11 | fn rev_sign(nr int) int {
12 | if nr < 0 {return -nr}
13 | return nr
14 | }
15 |
16 | println('16 is even: is ${even(16)}') // 16 is even: is 1
17 | println('17 is odd: is ${odd(17)}') // 17 is odd: is 1
18 | println('18 is odd: is ${odd(18)}') // 18 is odd: is 0
19 |
20 | /* Output:
21 | 16 is even: is 1
22 | 17 is odd: is 1
23 | 18 is odd: is 0
24 | */
25 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/mut_arrays.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut nums := [1, 2, 3, 4, 5]
3 | println(nums) // => [1, 2, 3, 4, 5]
4 | nums[2] = 7
5 | println(nums) // [1, 2, 7, 4, 5]
6 |
7 | // changing an item to a different type:
8 | // nums[2] = 'V' // cannot use type `string` as type `int` in assignment
9 |
10 | // insert:
11 | // mut names := ['Samuel', 'John', 'Peter']
12 | // names.insert(2, 'Tom') // Nov 16: error in Windows
13 | // println(names)
14 |
15 | // delete:
16 | mut even_numbers := [2, 4, 6, 8, 10]
17 | even_numbers.delete(3)
18 | println(even_numbers) // => [2, 4, 6, 10]
19 |
20 | }
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/conversions.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | a := u32(15)
3 | mut b := i8(0)
4 | println(a) // 15
5 | println(b) // 0
6 | b = i8(a + a)
7 | println(b) // => 30
8 |
9 | // n := i16(34)
10 | n := 34 as i16
11 | mut m := 0
12 | m = int(n) // explicit cast
13 | m = n as int
14 | println('16 bit int is: $n') // 16 bit int is: 34
15 | println('32 bit int is: $m') // 32 bit int is: 34
16 |
17 | c := 5.23
18 | d := int(c) // convert the float number a to an integer number
19 | println(d) // 5
20 | }
21 | /* Output:
22 | 15
23 | 0
24 | 30
25 | 16 bit int is: 34
26 | 32 bit int is: 34
27 | 5
28 | */
29 |
--------------------------------------------------------------------------------
/Chapter_6_Functions/fibonacci_imperative.v:
--------------------------------------------------------------------------------
1 | const (
2 | MAX = 10
3 | )
4 |
5 | fn main() {
6 | mut fibs := [0].repeat(MAX)
7 | fibs[0] = 1
8 | fibs[1] = 1
9 |
10 | for i := 2; i < MAX; i++ {
11 | fibs[i] = fibs[i-1] + fibs[i-2]
12 | println('The $i-th Fibonacci number is: ${fibs[i]}')
13 | }
14 | }
15 |
16 | /* Output:
17 | The 2-th Fibonacci number is: 2
18 | The 3-th Fibonacci number is: 3
19 | The 4-th Fibonacci number is: 5
20 | The 5-th Fibonacci number is: 8
21 | The 6-th Fibonacci number is: 13
22 | The 7-th Fibonacci number is: 21
23 | The 8-th Fibonacci number is: 34
24 | The 9-th Fibonacci number is: 55
25 | */
--------------------------------------------------------------------------------
/Chapter_11_Modules_and_Testing/game_of_life/life.v:
--------------------------------------------------------------------------------
1 | import (
2 | automaton
3 | time
4 | )
5 |
6 | fn print_automaton(a &automaton.Automaton){
7 | for y := 1; y < a.field.maxy; y++ {
8 | mut s := ' '
9 | for x := 1; x < a.field.maxx; x++ {
10 | cell := a.field.get(x,y)
11 | s += if cell == 1 { '@' } else { '.' } // @ = alive . = dead
12 | }
13 | println(s)
14 | }
15 | println('')
16 | }
17 |
18 | mut aut := automaton.gun() // initialization
19 | for { // game-loop
20 | aut.update() // calculate new generation
21 | print_automaton(aut) // display new generation
22 | time.sleep_ms(100)
23 | }
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/opl/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_library(opl STATIC
2 | opl_internal.h
3 | opl.c opl.h
4 | opl_linux.c
5 | opl_obsd.c
6 | opl_queue.c opl_queue.h
7 | opl_sdl.c
8 | opl_timer.c opl_timer.h
9 | opl_win32.c
10 | ioperm_sys.c ioperm_sys.h
11 | opl3.c opl3.h)
12 | target_include_directories(opl
13 | INTERFACE "."
14 | PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
15 | target_link_libraries(opl SDL2::mixer)
16 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/graphical/sdl/tvintris/README.md:
--------------------------------------------------------------------------------
1 | # tVintris
2 |
3 | tvintris.v is a dual-player (local) version based on original source from tetris example by Alex M.
4 | It is largely inspired by ancient game Twintris.
5 | -uses vlib sdl module
6 |
7 | 
8 |
9 | # how to run tVintris
10 |
11 | `$ v run .`
12 |
13 | # Credits
14 |
15 | Colors, Music and Sounds inspired/ripped from amiga title Twintris (1990 nostalgia !)
16 | - Graphician : Svein Berge
17 | - Musician : Tor Bernhard Gausen (Walkman/Cryptoburners)
18 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/op_overload.v:
--------------------------------------------------------------------------------
1 | struct Vec {
2 | x int
3 | y int
4 | }
5 |
6 | fn (a Vec) str() string {
7 | return '{$a.x, $a.y}'
8 | }
9 |
10 | fn (a Vec) + (b Vec) Vec {
11 | return Vec {
12 | a.x + b.x ,
13 | a.y + b.y
14 | }
15 | }
16 |
17 | fn (a Vec) - (b Vec) Vec {
18 | return Vec {
19 | a.x - b.x,
20 | a.y - b.y
21 | }
22 | }
23 |
24 | fn main() {
25 | a := Vec{2, 3}
26 | b := Vec{4, 5}
27 | println(a + b) // ==> "{6, 8}"
28 | println(a - b) // ==> "{-2, -2}"
29 | }
30 |
31 | /* Output:
32 | {6, 8}
33 | {-2, -2}
34 | */
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/crypto/rc4/rc4_test.v:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
2 | // Use of this source code is governed by an MIT license
3 | // that can be found in the LICENSE file.
4 |
5 | import crypto.rc4
6 |
7 | fn test_crypto_rc4() {
8 | key := 'tthisisourrc4key'.bytes()
9 |
10 | mut c := rc4.new_cipher(key) or {
11 | println(err)
12 | return
13 | }
14 |
15 | mut src := 'toencrypt'.bytes()
16 |
17 | // src & dst same, encrypt in place
18 | c.xor_key_stream(mut src, src) // encrypt data
19 |
20 | c.reset()
21 |
22 | assert src.hex() == '189a39a91aea8afa65'
23 | }
24 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/eventbus/eventbus.v:
--------------------------------------------------------------------------------
1 | module main
2 |
3 | import (
4 | some_module
5 | eventbus
6 | )
7 |
8 | fn main(){
9 | mut sub := some_module.get_subscriber()
10 | sub.subscribe("error", on_error)
11 | some_module.do_work()
12 | }
13 |
14 | fn on_error(p eventbus.Params) {
15 | println(p.get_string("error"))
16 | }
17 |
18 | /* Output:
19 | working...
20 | working...
21 | working...
22 | working...
23 | working...
24 | working...
25 | working...
26 | working...
27 | working...
28 | working...
29 | working...
30 | working...
31 | working...
32 | working...
33 | working...
34 | working...
35 | CRASH!!
36 | CRASH!!
37 | */
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/sqlite3.v:
--------------------------------------------------------------------------------
1 | #flag -lsqlite3
2 |
3 | #include "sqlite3.h"
4 |
5 | struct C.sqlite3
6 | struct C.sqlite3_stmt
7 |
8 | fn C.sqlite3_column_int(C.sqlite_stmt, int) int
9 |
10 | fn main() {
11 | path := 'sqlite3_users.db'
12 | db := &C.sqlite3{}
13 | C.sqlite3_open(path.cstr(), &db)
14 |
15 | query := 'select count(*) from users'
16 | stmt := &C.sqlite3_stmt{}
17 | C.sqlite3_prepare_v2(db, query.cstr(), - 1, &stmt, 0)
18 | C.sqlite3_step(stmt)
19 | nr_users := C.sqlite3_column_int(res, 0)
20 | C.sqlite3_finalize(res)
21 | println(nr_users)
22 | }
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/README.md:
--------------------------------------------------------------------------------
1 | # vOS
2 |
3 | An attempt to write an operating system in V.
4 |
5 | Brainstorming started on November 15 2019.
6 |
7 | Join the [Discord chat](https://discordapp.com/invite/n7c74HM) (`#v-os` channel). (PM one of the moderators if you don't want to verify your phone.)
8 |
9 | Goals:
10 |
11 | - Microkernel architecture.
12 | - Unix/POSIX subsystem for compatibility with lots of software that already exists.
13 | - UEFI support, Multiboot compliant.
14 | - Written in V as much as possible (including libc), not dependent on external libs written in C.
15 | - Targetted at modern 64-bit architectures (amd64, aarch64, risc-v).
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/chars.v:
--------------------------------------------------------------------------------
1 | fn char_example() {
2 | a_char := `a`
3 | println('The ascii value of this char is: $a_char') // => The ascii value of this char is: 97
4 | println('The char is: ${a_char.str()}') // => The char is: a
5 |
6 | mut concat := 'b' + a_char.str() + 'dnews be' + a_char.str() + 'rs'
7 | print(concat) // => badnews bears
8 |
9 | // use += to append to a string
10 | concat += '_appended'
11 | println(', $concat') // => , badnews bears_appended
12 |
13 | // raw string:
14 | raw_hello := r'Hello\nWorld'
15 | println(raw_hello) // => Hello\nWorld
16 | }
17 |
18 | char_example()
19 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/mult_inheritance.v:
--------------------------------------------------------------------------------
1 | // Nov 9: type `SmartPhone` has no field or method `take_picture`
2 | struct Phone { }
3 |
4 | fn (p Phone ) call() string {
5 | return 'Ring Ring'
6 | }
7 |
8 | struct Camera { }
9 |
10 | fn (c Camera) take_picture() string {
11 | return 'Click'
12 | }
13 |
14 | // multiple inheritance
15 | struct SmartPhone {
16 | phone Phone
17 | camera Camera
18 | }
19 |
20 | cp := SmartPhone{}
21 | println('Our new SmartPhone exhibits multiple behaviors ...')
22 | println('It exhibits behavior of a Camera: $cp.take_picture()')
23 | println('It works like a Phone too: $cp.call()')
24 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/hangman/words.txt:
--------------------------------------------------------------------------------
1 | afford
2 | ignorance
3 | beam
4 | abnormal
5 | flu
6 | emphasis
7 | brown
8 | compliance
9 | jury
10 | judicial
11 | bulb
12 | depend
13 | marsh
14 | syndrome
15 | jaw
16 | understanding
17 | fortune
18 | wage
19 | cruel
20 | wrong
21 | outlet
22 | presidential
23 | average
24 | make
25 | trip
26 | champion
27 | high
28 | advice
29 | bargain
30 | cup
31 | constitution
32 | onion
33 | arrangement
34 | temporary
35 | ecstasy
36 | disaster
37 | extract
38 | cutting
39 | employee
40 | horizon
41 | day
42 | railcar
43 | immune
44 | carpet
45 | bloodshed
46 | chimpanzee
47 | explosion
48 | admit
49 | variable
50 | attract
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/factorial.v:
--------------------------------------------------------------------------------
1 | fn factorial(n int) int {
2 | if n > 0 {
3 | return n * factorial(n-1)
4 | }
5 | return 1
6 | }
7 |
8 | for i := 0; i < 30; i++ {
9 | println('factorial of $i is ${factorial(i)}')
10 | }
11 |
12 | /* Output:
13 | factorial of 0 is 1
14 | factorial of 1 is 1
15 | factorial of 2 is 2
16 | factorial of 3 is 6
17 | factorial of 4 is 24
18 | factorial of 5 is 120
19 | factorial of 6 is 720
20 | factorial of 7 is 5040
21 | factorial of 8 is 40320
22 | factorial of 9 is 362880
23 | factorial of 10 is 3628800
24 | factorial of 11 is 39916800
25 | factorial of 12 is 479001600...
26 | // overflow occurs from 13 onwards
27 | */
--------------------------------------------------------------------------------
/Chapter_7_Arrays/arrays1.v:
--------------------------------------------------------------------------------
1 | const (
2 | numbers = [1, 2, 3]
3 | )
4 |
5 | fn main() {
6 | println(numbers) // => [1, 2, 3]
7 |
8 | nums := [1, 2, 3, 4, 5]
9 | println(nums[0]) // => 1
10 | println(nums[1]) // => 2
11 | println(nums[4]) // => 5
12 |
13 | println(nums) // => [1, 2, 3, 4, 5]
14 | println(nums.len) // => 5
15 |
16 | // println(nums[5]) // => V panic: index out of range (i == 5, a.len == 5)
17 |
18 | arr := []int
19 | println(arr.len) // => 0
20 | println(arr) // => []
21 |
22 | // array with different types:
23 | // nums2 := [1, 2, 'abc'] // => arrays1.v:23:24: bad array element type `string` instead of `int`
24 | }
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/kernel/arch/amd64/io.asm:
--------------------------------------------------------------------------------
1 | section .text
2 | bits 64
3 |
4 | global outb
5 | outb:
6 | mov rax, rsi
7 | mov rdx, rdi
8 | out dx, al
9 | ret
10 |
11 | global outw
12 | outw:
13 | mov rax, rsi
14 | mov rdx, rdi
15 | out dx, ax
16 | ret
17 |
18 | global outl
19 | outl:
20 | mov rax, rsi
21 | mov rdx, rdi
22 | out dx, eax
23 | ret
24 |
25 | global inb
26 | inb:
27 | mov rdx, rdi
28 | xor rax, rax
29 | in al, dx
30 | ret
31 |
32 | global inw
33 | inw:
34 | mov rdx, rdi
35 | xor rax, rax
36 | in ax, dx
37 | ret
38 |
39 | global inl
40 | inl:
41 | mov rdx, rdi
42 | xor rax, rax
43 | in eax, dx
44 | ret
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/word_counter_book/words.txt:
--------------------------------------------------------------------------------
1 | afford
2 | ignorance
3 | beam
4 | abnormal
5 | flu
6 | emphasis
7 | brown
8 | compliance
9 | jury
10 | judicial
11 | bulb
12 | depend
13 | marsh
14 | syndrome
15 | jaw
16 | understanding
17 | fortune
18 | wage
19 | cruel
20 | wrong
21 | outlet
22 | presidential
23 | average
24 | make
25 | trip
26 | champion
27 | high
28 | advice
29 | bargain
30 | cup
31 | constitution
32 | onion
33 | arrangement
34 | temporary
35 | ecstasy
36 | disaster
37 | extract
38 | cutting
39 | employee
40 | horizon
41 | day
42 | railcar
43 | immune
44 | carpet
45 | bloodshed
46 | chimpanzee
47 | explosion
48 | admit
49 | variable
50 | attract
--------------------------------------------------------------------------------
/Chapter_7_Arrays/forin_arrays.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | numbers := [1, 2, 3, 4, 5]
3 | for num in numbers {
4 | print(num) // => 12345
5 | }
6 | println('')
7 | names := ['Sam', 'Peter']
8 | for i, name in names {
9 | println('$i) $name') // => 0) Sam
10 | } // 1) Peter
11 |
12 | for _, name in names { // _ discards the index, but can be left out entirely
13 | print('$name - ') // => Sam - Peter -
14 | }
15 | println('')
16 | for name in names {
17 | print('$name - ') // => Sam - Peter -
18 | }
19 | println('')
20 | for ix, _ in names { // _ discards the name
21 | print('$ix ') // => 0 1
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/terminal_control.v:
--------------------------------------------------------------------------------
1 | import term
2 |
3 | fn sleeping_line(x,y,size int, ch string) {
4 | mut i := 0
5 | for i < size {
6 | term.set_cursor_position(x+i,y)
7 | print(term.bold(term.yellow(ch)))
8 | i++
9 | }
10 | }
11 |
12 | fn standing_line(x,y,size int, ch string) {
13 | mut i := 0
14 | for i < size {
15 | term.set_cursor_position(x,y+i)
16 | print(term.bold(term.yellow(ch)))
17 | i++
18 | }
19 | }
20 |
21 | term.erase_clear()
22 | sleeping_line(5,5,5,'*')
23 | standing_line(5,5,5,'*')
24 | sleeping_line(5,10,5,'*')
25 | standing_line(9,5,5,'*')
26 | term.cursor_down(5)
27 | print('\n')
28 | println(term.bold(term.red('It Worked!')))
29 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/kernel/io/io.v:
--------------------------------------------------------------------------------
1 | module io
2 |
3 | fn C.outb(port u16, val byte)
4 |
5 | fn C.outw(port u16, val u16)
6 |
7 | fn C.outl(port u16, val u32)
8 |
9 | fn C.inb(port u16) byte
10 |
11 | fn C.inw(port u16) u16
12 |
13 | fn C.inl(port u16) u32
14 |
15 | pub fn outb(port u16, val byte) {
16 | C.outb(port, val)
17 | }
18 |
19 | pub fn outw(port u16, val u16) {
20 | C.outw(port, val)
21 | }
22 |
23 | pub fn outl(port u16, val u32) {
24 | C.outl(port, val)
25 | }
26 |
27 | pub fn inb(port u16) byte {
28 | return C.inb(port)
29 | }
30 |
31 | pub fn inw(port u16) u16 {
32 | return C.inw(port)
33 | }
34 |
35 | pub fn inl(port u16) u32 {
36 | return C.inl(port)
37 | }
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/struct_arr.v:
--------------------------------------------------------------------------------
1 | struct Foo {
2 | mut:
3 | a []&Bar
4 | }
5 |
6 | struct Bar {
7 | b int
8 | }
9 |
10 | fn main() {
11 | mut f := Foo{}
12 | f.a = [&Bar{}].repeat(10)
13 | for i, x in f.a {
14 | println("$i => $x")
15 | }
16 | }
17 |
18 | /*
19 | 0 => &Bar {
20 | b: 0
21 | }
22 | 1 => &Bar {
23 | b: 0
24 | }
25 | 2 => &Bar {
26 | b: 0
27 | }
28 | 3 => &Bar {
29 | b: 0
30 | }
31 | 4 => &Bar {
32 | b: 0
33 | }
34 | 5 => &Bar {
35 | b: 0
36 | }
37 | 6 => &Bar {
38 | b: 0
39 | }
40 | 7 => &Bar {
41 | b: 0
42 | }
43 | 8 => &Bar {
44 | b: 0
45 | }
46 | 9 => &Bar {
47 | b: 0
48 | }
49 | */
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/weblate-memory.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "origin": "lxqt/pavucontrol-qt",
4 | "target_language": "or",
5 | "category": 20000227,
6 | "source": "Card callback failure",
7 | "source_language": "en",
8 | "target": "\u0b15\u0b3e\u0b30\u0b4d\u0b21\u0b3c \u0b15\u0b32\u0b2c\u0b4d\u0b5f\u0b3e\u0b15 \u0b05\u0b38\u0b2b\u0b33"
9 | },
10 | {
11 | "origin": "lxqt/pavucontrol-qt",
12 | "target_language": "or",
13 | "category": 20000227,
14 | "source": "Sink callback failure",
15 | "source_language": "en",
16 | "target": "\u0b38\u0b3f\u0b19\u0b4d\u0b15 \u0b15\u0b32\u0b2c\u0b4d\u0b5f\u0b3e\u0b15 \u0b05\u0b38\u0b2b\u0b33"
17 | }
18 | ]
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/Makefile.am:
--------------------------------------------------------------------------------
1 |
2 | EXTRA_DIST= \
3 | README \
4 | doom.ico \
5 | doom8.ico \
6 | doom.png \
7 | setup.ico \
8 | setup8.ico \
9 | setup.png \
10 | convert-icon
11 |
12 | iconsdir = $(prefix)/share/icons/hicolor/128x128/apps
13 | icons_DATA = @PROGRAM_PREFIX@doom.png \
14 | @PROGRAM_PREFIX@setup.png
15 |
16 | @PROGRAM_PREFIX@doom.png : doom.png
17 | cp $(top_srcdir)/data/doom.png $@
18 |
19 | @PROGRAM_PREFIX@setup.png : setup.png
20 | cp $(top_srcdir)/data/setup.png $@
21 |
22 | CLEANFILES = $(icons_DATA)
23 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/make_iso.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 | cd "${0%/*}"
5 |
6 | KERNEL=build/kernel.elf
7 | grub-file --is-x86-multiboot2 $KERNEL || (echo "[!] Not a valid multiboot kernel!" ; exit 1)
8 |
9 | mkdir -p build/iso
10 | mkdir -p build/iso/boot/grub
11 |
12 | cp $KERNEL build/iso/kernel.elf
13 |
14 | cat > build/iso/boot/grub/grub.cfg << EOF
15 | loadfont "unicode"
16 | insmod all_video
17 | insmod gfxterm
18 |
19 | set gfxmode=auto
20 | set gfxpayload=keep
21 | terminal_output gfxterm
22 |
23 | echo "Booting the vOS kernel"
24 | multiboot2 /kernel.elf
25 | boot
26 | EOF
27 |
28 | grub-mkrescue -o build/boot.iso build/iso
29 | echo "[*] Done, boot image saved to 'build/boot.iso'!"
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vlib/crypto/aes/cypher_generic.v:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
2 | // Use of this source code is governed by an MIT license
3 | // that can be found in the LICENSE file.
4 |
5 | module aes
6 |
7 | import (
8 | // crypto.cipher
9 | // crypto.internal.subtle
10 | )
11 |
12 | // new_cipher_generic creates and returns a new cipher.Block
13 | // this is the generiv v version, no arch optimisations
14 | fn new_cipher_generic(key []byte) AesCipher {
15 | n := key.len + 28
16 | mut c := AesCipher{
17 | enc: [u32(0)].repeat(n)
18 | dec: [u32(0)].repeat(n)
19 | }
20 | expand_key_generic(key, mut c.enc, mut c.dec)
21 | return c
22 | }
23 |
--------------------------------------------------------------------------------
/Chapter_15_V_Software/vos/vore/vore.h:
--------------------------------------------------------------------------------
1 | #ifndef _VORE_H_
2 | #define _VORE_H_
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | // V types
9 | typedef uint8_t byte;
10 |
11 | typedef struct string string;
12 |
13 | struct string {
14 | byte* str;
15 | int len;
16 | };
17 |
18 | void v_panic(string s);
19 | void panic_debug(string s);
20 | int strlen(byte* s);
21 | string tos(byte* s, int len);
22 | string tos2(byte* s);
23 | string tos3(char* s);
24 |
25 | void memset(char* addr, char val, int count);
26 | void memput(byte* addr, int off, byte val);
27 |
28 | string v_sprintf(const char* fmt, ...);
29 | #define _STR(...) v_sprintf(__VA_ARGS__)
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/duck_dance.v:
--------------------------------------------------------------------------------
1 | // Nov 10: V error: C error. This should never happen.
2 | interface IDucker {
3 | quack() string
4 | walk() string
5 | }
6 |
7 | fn duck_dance(duck IDucker) {
8 | for i := 1; i <= 3; i++ {
9 | println(duck.quack())
10 | println(duck.walk())
11 | }
12 | }
13 |
14 | struct Bird {}
15 |
16 | fn (b Bird) quack() string {
17 | return 'I am quacking!'
18 | }
19 |
20 | fn (b Bird) walk() string {
21 | return 'I am walking!'
22 | }
23 |
24 | fn main() {
25 | b := Bird{}
26 | duck_dance(b)
27 | }
28 |
29 | /* Output:
30 | I am quacking!
31 | I am walking!
32 | I am quacking!
33 | I am walking!
34 | I am quacking!
35 | I am walking!
36 | */
37 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/prime_multi.v:
--------------------------------------------------------------------------------
1 | fn multiple_thread(i int, mut list []bool) {
2 | total := 100
3 | for j := i * 2; j < total; j += i{
4 | list[j] = false
5 | }
6 | }
7 |
8 | fn main(){
9 | total := 100
10 | mut list := []bool{}
11 | for i := 0; i < total; i++{
12 | list << true
13 | }
14 | list[0] = false
15 | list[1] = false
16 | mut primes := [0,1]
17 |
18 | for i, index in list{
19 | if index == false{
20 | continue
21 | }
22 | if index == true{
23 | primes << i
24 | println(i)
25 | go multiple_thread(i, &list)
26 | }
27 | }
28 | // println(primes)
29 | }
--------------------------------------------------------------------------------
/Chapter_10_Option_Types_Error_Handling/option3.v:
--------------------------------------------------------------------------------
1 | struct DivisionResult {
2 | result f64
3 | }
4 |
5 | fn divide(a, b f64) ?DivisionResult {
6 | if (b != 0) {
7 | return DivisionResult {result : a/b }
8 | }
9 | return error('Can\'t divide by zero!')
10 | }
11 |
12 | fn error_handling_example() {
13 | x := f64(10.0)
14 | y := f64(0)
15 | z := f64(2.5)
16 |
17 | succeed := divide(x, z) or {
18 | println(err)
19 | return
20 | }
21 | println(succeed.result) // => 4.000000
22 |
23 | fail := divide(x, y) or {
24 | println(err) // => Can't divide by zero!
25 | return
26 | }
27 | println(fail.result)
28 | }
29 |
30 | error_handling_example()
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/array_dup.v:
--------------------------------------------------------------------------------
1 | // Write a V program to count a total number of duplicate elements in an array.
2 |
3 | /* algorithm:
4 | - dup_counter
5 | - sort array
6 | - loop over array:
7 | compare next item with previous item: if equal dup_counter++
8 | - display dup_counter
9 | */
10 |
11 |
12 | fn main() {
13 | mut arr1 := [12, 2, -3, 42, 2, 42, 108, 42] // no of duplicates: 3
14 | mut dup := 0
15 | arr1.sort() // sort arr in place
16 | // println(arr1)
17 | for i := 0; i < arr1.len; i++ {
18 | if i + 1 == arr1.len { break } // to avoid index out of range
19 | if arr1[i + 1] == arr1[i] { dup++ }
20 | }
21 | println('The number of duplicates is: $dup') // => The number of duplicates is: 3
22 | }
--------------------------------------------------------------------------------
/Chapter_7_Arrays/exercises/arr_dup_fn_gen.v:
--------------------------------------------------------------------------------
1 | fn get_no_dup(arr mut []T) int {
2 | mut dup := 0
3 | arr.sort()
4 | for i := 0; i < arr.len; i++ {
5 | if i + 1 == arr.len { break } // to avoid index out of range
6 | if arr[i + 1] == arr[i] { dup++ }
7 | }
8 | return dup
9 | }
10 |
11 | fn main() {
12 | mut arr1 := [12, 2, -3, 42, 2, 42, 108, 42] // no of duplicates: 3
13 | println('The number of duplicates is: ${get_no_dup(mut arr1)}') // => The number of duplicates is: 3
14 | mut arr2 := ['12', '2', '-3', '42', '2', '42', '108', '42'] // no of duplicates: 3
15 | // mut arr3 := [true, false, true, false, true]
16 | // println('The number of duplicates is: ${get_no_dup(mut arr3)}') // []bool` has no field or method `sort`
17 | }
--------------------------------------------------------------------------------
/Chapter_14_V_Modules/faker/faker-master/data/address_us/state:
--------------------------------------------------------------------------------
1 | Alabama
2 | Alaska
3 | Arizona
4 | Arkansas
5 | California
6 | Colorado
7 | Connecticut
8 | Delaware
9 | Florida
10 | Georgia
11 | Hawaii
12 | Idaho
13 | Illinois
14 | Indiana
15 | Iowa
16 | Kansas
17 | Kentucky
18 | Louisiana
19 | Maine
20 | Maryland
21 | Massachusetts
22 | Michigan
23 | Minnesota
24 | Mississippi
25 | Missouri
26 | Montana
27 | Nebraska
28 | Nevada
29 | New Hampshire
30 | New Jersey
31 | New Mexico
32 | New York
33 | North Carolina
34 | North Dakota
35 | Ohio
36 | Oklahoma
37 | Oregon
38 | Pennsylvania
39 | Rhode Island
40 | South Carolina
41 | South Dakota
42 | Tennessee
43 | Texas
44 | Utah
45 | Vermont
46 | Virginia
47 | Washington
48 | West Virginia
49 | Wisconsin
50 | Wyoming
51 |
--------------------------------------------------------------------------------
/Chapter_9_Structs_Methods_and_Interfaces/multidim_struct.v:
--------------------------------------------------------------------------------
1 | struct MultArray {
2 | pub mut:
3 | data [][]f64
4 | }
5 |
6 | fn main () {
7 | mut mat := MultArray {
8 | data : [[f64(11),12,13]
9 | ,[f64(21),22,23]
10 | ,[f64(31),32,33]
11 | ,[f64(41),42,43]]
12 | }
13 | mat.data << [[f64(98),97,96,95,94,93]]
14 | // Work around
15 | b := mat.data
16 | c := b[4][4]
17 | println( c ) // 94.000000
18 |
19 | // same case on local variable
20 | mut data_local := [[f64(11),12,13]
21 | ,[f64(21),22,23]
22 | ,[f64(31),32,33]
23 | ,[f64(41),42,43]]
24 |
25 | data_local << [[f64(98),97,96,95,94,93]]
26 | println(data_local[4][4]) // 94.000000
27 | }
--------------------------------------------------------------------------------
/Chapter_5_Control_Structures/defer_mult.v:
--------------------------------------------------------------------------------
1 | import math
2 |
3 | fn defer_example() {
4 | mut a := f64(3)
5 | mut b := f64(4)
6 |
7 | // anything within this block won't run until the code after it has completed
8 | defer {
9 | c := math.sqrt(a+b)
10 | println('The hypotenuse of the triangle is $c')
11 | }
12 |
13 | // this should be executed before the statements above
14 | a = math.pow(a, 2)
15 | b = math.pow(b, 2)
16 | print('square of the length of side A is $a')
17 | println(', square of the length of side B is $b')
18 | }
19 |
20 | defer_example()
21 |
22 | /* Output:
23 | square of the length of side A is 9.000000, square of the length of side B is 16.000000
24 | The hypotenuse of the triangle is 5.000000
25 | */
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/convert_decimal_binary.v:
--------------------------------------------------------------------------------
1 | // Write a V program to convert decimal number to binary number using a function:
2 | /* Algorithm:
3 | Conversion steps:
4 | Divide the number by 2.
5 | Get the integer quotient for the next iteration.
6 | Get the remainder for the binary digit.
7 | Repeat the steps until the quotient is equal to 0.
8 | */
9 |
10 | fn convert_dec_bin(num int) int {
11 | mut tmp := num
12 | mut arr_bin := []string
13 | for tmp != 0 {
14 | arr_bin << (tmp % 2).str()
15 | tmp = tmp / 2
16 | }
17 | //arr_bin = arr_bin.reverse()
18 | // println(arr_bin) // => ["1", "0", "0", "0"]
19 | return arr_bin.reverse().join('').int()
20 | }
21 |
22 | println(convert_dec_bin(8)) // => 1000
23 | println(convert_dec_bin(13)) // => 1101
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/databases/sqlite/sqlite_test.v:
--------------------------------------------------------------------------------
1 | import sqlite
2 |
3 | fn test_sqlite() {
4 | db := sqlite.connect(':memory:')
5 | db.exec("drop table if exists users")
6 | db.exec("create table users (id integer primary key, name text default '');")
7 |
8 | db.exec("insert into users (name) values ('Sam')")
9 | db.exec("insert into users (name) values ('Peter')")
10 | db.exec("insert into users (name) values ('Kate')")
11 |
12 | nr_users := db.q_int('select count(*) from users')
13 | println('nr users = $nr_users')
14 |
15 | name := db.q_string('select name from users where id = 1')
16 | assert name == 'Sam'
17 |
18 | users := db.exec('select * from users')
19 | assert users.len == 3
20 | for row in users {
21 | println(row.vals)
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Chapter_4_Basic_Types_Strings/substitution.v:
--------------------------------------------------------------------------------
1 | const (
2 | lower_s = 'lower s'
3 | )
4 |
5 | fn get_val() int {
6 | return 13
7 | }
8 |
9 | fn main() {
10 | person := 'Harris'
11 | println('Hello, $person!')
12 |
13 | println('lower_s = $lower_s')
14 |
15 | pi := 3.141592
16 | is_sharp := true
17 | print('$pi')
18 | println('pi is $pi')
19 | println('pi with 2 decimals is ${pi:.2f}')
20 | println('is_sharp is $is_sharp')
21 |
22 | a := 5
23 | b := 7
24 | println('The sum is ${a + b}')
25 |
26 | // Interpolated strings now allow function calls:
27 | println('val = $get_val()')
28 | }
29 | /* Output:
30 | Hello, Harris!
31 | lower_s = lower s
32 | 3.141592pi is 3.141592
33 | pi with 2 decimals is 3.14
34 | is_sharp is 1
35 | The sum is 12
36 | val = 13
37 | */
--------------------------------------------------------------------------------
/Chapter_10_Option_Types_Error_Handling/option2B.v:
--------------------------------------------------------------------------------
1 | struct User {
2 | id int
3 | name string
4 | }
5 |
6 | struct Repo {
7 | users []User
8 | }
9 |
10 | fn new_repo() Repo {
11 | return Repo {
12 | users: [User{1, 'Andrew'}, User {2, 'Bob'}, User {10, 'Charles'}]
13 | }
14 | }
15 |
16 | fn (r Repo) find_user_by_id(id int) ?User {
17 | for user in r.users {
18 | if user.id == id {
19 | // V automatically wraps this into an option type
20 | return user
21 | }
22 | }
23 | return error('User $id not found!')
24 | }
25 |
26 | fn main() {
27 | repo := new_repo()
28 | user := repo.find_user_by_id(11) or {
29 | println(err)
30 | return
31 | }
32 | println(user.id) // => 10
33 | println(user.name) // => "Charles"
34 | }
35 |
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/src/net_petname.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright(C) 2019 Jonathan Dowland
3 | //
4 | // This program is free software; you can redistribute it and/or
5 | // modify it under the terms of the GNU General Public License
6 | // as published by the Free Software Foundation; either version 2
7 | // of the License, or (at your option) any later version.
8 | //
9 | // This program is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // DESCRIPTION:
15 | // Generate a randomized, private, memorable name for a Player
16 | //
17 |
18 | char *NET_GetRandomPetName();
19 |
--------------------------------------------------------------------------------
/Chapter_13_Standard_Library_vlib/json_file.v:
--------------------------------------------------------------------------------
1 | import os
2 | import json
3 |
4 | struct Extract {
5 | origin string
6 | target_language string
7 | category int
8 | source string
9 | source_language string
10 | target string
11 | }
12 |
13 | fn main() {
14 | file := os.read_file('weblate-memory.json') or {
15 | eprintln('Error opening file!')
16 | return
17 | }
18 |
19 | users:= json.decode([]Extract, file) or {
20 | eprintln('Failed to decode json')
21 | return
22 | }
23 |
24 | for u in users {
25 | println(u.source)
26 | println(u.target)
27 | }
28 | }
29 |
30 | /* Output:
31 | Card callback failure
32 | କାର୍ଡ଼ କଲବ୍ୟାକ ଅସଫଳ
33 | Sink callback failure
34 | ସିଙ୍କ କଲବ୍ୟାକ ଅସଫଳ
35 | */
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/opl/Makefile.am:
--------------------------------------------------------------------------------
1 |
2 | AM_CFLAGS=@SDLMIXER_CFLAGS@
3 |
4 | EXTRA_DIST=CMakeLists.txt
5 |
6 | SUBDIRS = . examples
7 |
8 | noinst_LIBRARIES=libopl.a
9 |
10 | libopl_a_SOURCES = \
11 | opl_internal.h \
12 | opl.c opl.h \
13 | opl_linux.c \
14 | opl_obsd.c \
15 | opl_queue.c opl_queue.h \
16 | opl_sdl.c \
17 | opl_timer.c opl_timer.h \
18 | opl_win32.c \
19 | ioperm_sys.c ioperm_sys.h \
20 | opl3.c opl3.h
21 |
22 |
--------------------------------------------------------------------------------
/Chapter_7_Arrays/array_value.v:
--------------------------------------------------------------------------------
1 | fn main() {
2 | mut arr1 := [1, 2, 3]
3 | println(arr1) // => [1, 2, 3]
4 | mut arr3 := arr1
5 | println(arr3) // => [1, 2, 3]
6 | arr1[2] = 100
7 | println(arr1) // => [1, 2, 100]
8 | println(arr3) // => [1, 2, 100]
9 | arr3[1] = 77
10 | println(arr1) // => [1, 77, 100]
11 | println(arr3) // => [1, 77, 100]
12 |
13 | arr4 := &arr1
14 | println(arr4) // => 000000000061FCE0
15 | arr5 := &arr3
16 | println(arr5) // => 000000000061FCC0
17 | println(*arr4) // => [1, 77, 100]
18 |
19 | arr1 = [1, 2, 108]
20 | println(*arr4) // => [1, 2, 108]
21 | println(arr3) // => [1, 77, 108]
22 | }
--------------------------------------------------------------------------------
/Chapter_6_Functions/exercises/factorial_imperative.v:
--------------------------------------------------------------------------------
1 | // imperative solution:
2 | const (
3 | MAX = 10
4 | )
5 |
6 | fn main() {
7 | mut facs := [0].repeat(MAX+1)
8 | facs[0] = 1
9 | println('The 0-th Factorial number is: 1')
10 |
11 | for i:= 1; i <= MAX; i++ {
12 | facs[i] = i * facs[i-1]
13 | println('The $i-th Factorial number is: ${facs[i]}')
14 | }
15 | }
16 |
17 | // Output:
18 | /*
19 | The 0-th Factorial number is: 1
20 | The 1-th Factorial number is: 1
21 | The 2-th Factorial number is: 2
22 | The 3-th Factorial number is: 6
23 | The 4-th Factorial number is: 24
24 | The 5-th Factorial number is: 120
25 | The 6-th Factorial number is: 720
26 | The 7-th Factorial number is: 5040
27 | The 8-th Factorial number is: 40320
28 | The 9-th Factorial number is: 362880
29 | The 10-th Factorial number is: 3628800
30 | */
--------------------------------------------------------------------------------
/Chapter_12_Advanced_Topics/doom/chocolate-doom/data/README:
--------------------------------------------------------------------------------
1 | The Chocolate Doom icon is based on an image by Chris Metcalf
2 | (http://www.chrismetcalf.org/) which is copyrighted to him:
3 |
4 | http://www.flickr.com/photos/laffy4k/448920776/
5 |
6 | Chris has kindly agreed that the Chocolate Doom icon may be used under
7 | the GNU GPL, so the copyright status of the icon is the same as that of
8 | the rest of the project.
9 |
10 | The "foo8.ico" files are 8-bit depth only, while the "foo.ico" files
11 | contain full 32-bit versions, scaled to different sizes and with proper
12 | alpha masks (as well as the 8-bit versions). The 8-bit versions are
13 | used when setting the icon within SDL, as SDL under Windows displays
14 | full color icons in a very poor quality. The full-color versions are
15 | used in the resource files.
16 |
17 |
--------------------------------------------------------------------------------