From 37c749e89c297b2ef20f2faea9276bba07df8f5e Mon Sep 17 00:00:00 2001 From: Vinicius Silva Date: Thu, 28 Dec 2023 00:40:28 -0300 Subject: [PATCH 1/5] Create map.v file --- 07_collections/map.v | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 07_collections/map.v diff --git a/07_collections/map.v b/07_collections/map.v new file mode 100644 index 0000000..1c4366a --- /dev/null +++ b/07_collections/map.v @@ -0,0 +1,4 @@ +pub fn main() +{ + println('oi') +} \ No newline at end of file From 0080ec1dfc6cafd88644f1a4bff3adfca02ecf4b Mon Sep 17 00:00:00 2001 From: Vinicius Silva Date: Thu, 28 Dec 2023 20:38:11 -0300 Subject: [PATCH 2/5] map.v implemented --- 07_collections/map.v | 77 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/07_collections/map.v b/07_collections/map.v index 1c4366a..8b0a10f 100644 --- a/07_collections/map.v +++ b/07_collections/map.v @@ -1,4 +1,79 @@ pub fn main() { - println('oi') + + mut m := map[string]int{} + + m['one'] = 1 + m['two'] = 2 + + println(m['one']) + println(m['two']) + println(m['bad_key']) + println('bad_key' in m) + println(m.keys()) + + m.delete('two') + + numbers := { + 'one' : 1 + 'two' : 2 + } + + println(numbers) + + // ====================================================== // + + sm := { + 'abc' : 'xyz' + } + + val := sm['bad_key'] + println(val) + + intm := { + 1: 1234 + 2: 5678 + } + + s := intm[3] + println(s) + + // ====================================================== // + + mm := map[string]int{} + val3 := mm['bad_key'] or { panic('key not found') } + println(val3) + m1 := { + 'abc' : 'def' + } + + if v := m1['abc']{ + println('the map value for that key is ${v}') + } + + // ====================================================== // + + arr := [1,2,3] + large_index := 999 + val6 := arr[large_index] or { panic('out of bounds') } + println(val6) + + val2 := arr[333]! + println(val2) + + // ====================================================== // + + mut m2 := map[string]map[string]int{} + + m2['greet'] = { + 'Hello' : 1 + } + + m2['place'] = { + 'World' : 2 + } + + m2['code']['orange'] = 123 + println(m2) + } \ No newline at end of file From f696aa4174731a85773c8d3b61c2c99bf72fe9f1 Mon Sep 17 00:00:00 2001 From: Vinicius Silva Date: Thu, 28 Dec 2023 20:59:19 -0300 Subject: [PATCH 3/5] 08_module_imports directory implemented --- 08_module_imports/aliasing_import.v | 5 +++++ 08_module_imports/basic_import.v | 6 ++++++ 08_module_imports/selective_import.v | 9 +++++++++ 3 files changed, 20 insertions(+) create mode 100644 08_module_imports/aliasing_import.v create mode 100644 08_module_imports/basic_import.v create mode 100644 08_module_imports/selective_import.v diff --git a/08_module_imports/aliasing_import.v b/08_module_imports/aliasing_import.v new file mode 100644 index 0000000..457e9fe --- /dev/null +++ b/08_module_imports/aliasing_import.v @@ -0,0 +1,5 @@ +import crypto.sha256 as v_sha256 + +pub fn main(){ + println('oi') +} \ No newline at end of file diff --git a/08_module_imports/basic_import.v b/08_module_imports/basic_import.v new file mode 100644 index 0000000..648ebb3 --- /dev/null +++ b/08_module_imports/basic_import.v @@ -0,0 +1,6 @@ +import os + +pub fn main(){ + name := os.input('Type your name') + println(name) +} \ No newline at end of file diff --git a/08_module_imports/selective_import.v b/08_module_imports/selective_import.v new file mode 100644 index 0000000..16929a6 --- /dev/null +++ b/08_module_imports/selective_import.v @@ -0,0 +1,9 @@ +import os { input, user_os } + +pub fn main(){ + name := input('Type yout name') + println('Nane ${name}') + current_os := user_os() + println('Your OS is ${current_os}') + +} \ No newline at end of file From fceb261963df7f8f619e24266c4a052f88ea2767 Mon Sep 17 00:00:00 2001 From: Vinicius Silva Date: Thu, 28 Dec 2023 23:57:05 -0300 Subject: [PATCH 4/5] 09_defer directory created --- 09_defer/log.txt | 2 ++ 09_defer/main.v | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 09_defer/log.txt create mode 100644 09_defer/main.v diff --git a/09_defer/log.txt b/09_defer/log.txt new file mode 100644 index 0000000..d01218d --- /dev/null +++ b/09_defer/log.txt @@ -0,0 +1,2 @@ +asiofjasodifjasdfasdfasdfasd +asdfasdfasdfasdfasdfasdfsadf \ No newline at end of file diff --git a/09_defer/main.v b/09_defer/main.v new file mode 100644 index 0000000..d48cb5d --- /dev/null +++ b/09_defer/main.v @@ -0,0 +1,16 @@ +import os + +pub fn main(){ + + ok := false + mut f := os.open('log.txt') or { panic('File cannot be read!') } + defer{ + f.close() + } + + if !ok{ + return + } + + +} \ No newline at end of file From f7173332b05730100ccb85452eeb0c19ba1125e0 Mon Sep 17 00:00:00 2001 From: Vinicius Silva Date: Fri, 29 Dec 2023 00:32:02 -0300 Subject: [PATCH 5/5] state.v file created --- 09_defer/log.txt | 3 +-- 09_defer/state.v | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 09_defer/state.v diff --git a/09_defer/log.txt b/09_defer/log.txt index d01218d..39d7707 100644 --- a/09_defer/log.txt +++ b/09_defer/log.txt @@ -1,2 +1 @@ -asiofjasodifjasdfasdfasdfasd -asdfasdfasdfasdfasdfasdfsadf \ No newline at end of file +This is a log file diff --git a/09_defer/state.v b/09_defer/state.v new file mode 100644 index 0000000..6eab58b --- /dev/null +++ b/09_defer/state.v @@ -0,0 +1,41 @@ +import os { create } + +enum State{ + normal + write_log + return_error +} + +fn write_log(state State) !int { + mut f := create('log.txt')! + + defer { + f.close() + println('File closed') + } + + match state{ + .normal{ + return f.writeln("This is a normal file") + } + + .write_log { + return f.writeln("This is a log file") + } + + .return_error{ + return error('nothing written; file open: ${f.is_opened}') + } + } + return 0 +} + +pub fn main(){ + n := write_log(.write_log) or { + println('Error ${err}') + 0 + } + + println('${n} bytes written') + +} \ No newline at end of file