From b24d6d4b6a57a14aba0b22a9ea888a4adb19928c Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Tue, 5 Jan 2021 13:45:58 -0300 Subject: [PATCH] Remove old untested undocumented examples (#16595) --- examples/allany.nim | 24 ----------- examples/extract_keyval_pairs_pegs.nim | 7 --- examples/extract_keyval_pairs_re.nim | 8 ---- examples/hallo.nim | 3 -- examples/maximum.nim | 6 --- examples/myfile.txt | 11 ----- examples/readme.txt | 2 - examples/statcsv.nim | 60 -------------------------- examples/talk/dsl.nim | 33 -------------- examples/talk/formatoptimizer.nim | 55 ----------------------- examples/talk/hoisting.nim | 23 ---------- examples/talk/lazyeval.nim | 12 ------ examples/talk/quasiquote.nim | 11 ----- examples/talk/tags.nim | 9 ---- examples/tunit.nim | 47 -------------------- 15 files changed, 311 deletions(-) delete mode 100644 examples/allany.nim delete mode 100644 examples/extract_keyval_pairs_pegs.nim delete mode 100644 examples/extract_keyval_pairs_re.nim delete mode 100644 examples/hallo.nim delete mode 100644 examples/maximum.nim delete mode 100644 examples/myfile.txt delete mode 100644 examples/readme.txt delete mode 100644 examples/statcsv.nim delete mode 100644 examples/talk/dsl.nim delete mode 100644 examples/talk/formatoptimizer.nim delete mode 100644 examples/talk/hoisting.nim delete mode 100644 examples/talk/lazyeval.nim delete mode 100644 examples/talk/quasiquote.nim delete mode 100644 examples/talk/tags.nim delete mode 100644 examples/tunit.nim diff --git a/examples/allany.nim b/examples/allany.nim deleted file mode 100644 index 8a5ab81f05..0000000000 --- a/examples/allany.nim +++ /dev/null @@ -1,24 +0,0 @@ -# All and any - -template all(container, cond: untyped): bool = - var result = true - for it in items(container): - if not cond(it): - result = false - break - result - -template any(container, cond: untyped): bool = - var result = false - for it in items(container): - if cond(it): - result = true - break - result - -if all("mystring", {'a'..'z'}.contains) and any("myohmy", 'y'.`==`): - echo "works" -else: - echo "does not work" - - diff --git a/examples/extract_keyval_pairs_pegs.nim b/examples/extract_keyval_pairs_pegs.nim deleted file mode 100644 index 2a56432768..0000000000 --- a/examples/extract_keyval_pairs_pegs.nim +++ /dev/null @@ -1,7 +0,0 @@ -# Filter key=value pairs from "myfile.txt" -import pegs - -for x in lines("myfile.txt"): - if x =~ peg"{\ident} \s* '=' \s* {.*}": - echo "Key: ", matches[0], - " Value: ", matches[1] diff --git a/examples/extract_keyval_pairs_re.nim b/examples/extract_keyval_pairs_re.nim deleted file mode 100644 index a594c0fa8c..0000000000 --- a/examples/extract_keyval_pairs_re.nim +++ /dev/null @@ -1,8 +0,0 @@ -# Filter key=value pairs from "myfile.txt" -import re - -for x in lines("myfile.txt"): - if x =~ re"(\w+)=(.*)": - echo "Key: ", matches[0], " Value: ", matches[1] - - diff --git a/examples/hallo.nim b/examples/hallo.nim deleted file mode 100644 index d94da8c1f0..0000000000 --- a/examples/hallo.nim +++ /dev/null @@ -1,3 +0,0 @@ -# Hello world program - -echo "Hello World" diff --git a/examples/maximum.nim b/examples/maximum.nim deleted file mode 100644 index 3c43a48c96..0000000000 --- a/examples/maximum.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Shows how the method call syntax can be used to chain calls conveniently. - -import strutils, sequtils - -echo "Give a list of numbers (separated by spaces): " -stdin.readLine.split.map(parseInt).max.`$`.echo(" is the maximum!") diff --git a/examples/myfile.txt b/examples/myfile.txt deleted file mode 100644 index fb7cda984e..0000000000 --- a/examples/myfile.txt +++ /dev/null @@ -1,11 +0,0 @@ -kladsfa - -asdflksadlfasf - - -adsfljksadfl - - -key=/usr/bin/value -key2=/ha/ha - diff --git a/examples/readme.txt b/examples/readme.txt deleted file mode 100644 index 42446faead..0000000000 --- a/examples/readme.txt +++ /dev/null @@ -1,2 +0,0 @@ -In this directory you can find several examples for how to use the Nim -library. diff --git a/examples/statcsv.nim b/examples/statcsv.nim deleted file mode 100644 index 983cd555fb..0000000000 --- a/examples/statcsv.nim +++ /dev/null @@ -1,60 +0,0 @@ -# Example program to show the parsecsv module -# This program reads a CSV file and computes sum, mean, minimum, maximum and -# the standard deviation of its columns. -# The CSV file can have a header which is then used for the output. - -import os, streams, parsecsv, strutils, math, stats - -if paramCount() < 1: - quit("Usage: statcsv filename[.csv]") - -var filename = addFileExt(paramStr(1), "csv") -var s = newFileStream(filename, fmRead) -if s == nil: quit("cannot open the file " & filename) - -var - x: CsvParser - header: seq[string] - res: seq[RunningStat] -open(x, s, filename, separator=';', skipInitialSpace = true) -while readRow(x): - if processedRows(x) == 1: - newSeq(res, x.row.len) # allocate space for the result - if validIdentifier(x.row[0]): - # header line: - header = x.row - else: - newSeq(header, x.row.len) - for i in 0..x.row.len-1: header[i] = "Col " & $(i+1) - else: - # data line: - for i in 0..x.row.len-1: - push(res[i], parseFloat(x.row[i])) -x.close() - -# Write results: -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(header[i]) -stdout.write("\nSum") -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(res[i].sum) -stdout.write("\nMean") -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(res[i].mean) -stdout.write("\nMin") -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(res[i].min) -stdout.write("\nMax") -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(res[i].max) -stdout.write("\nStdDev") -for i in 0..header.len-1: - stdout.write("\t") - stdout.write(res[i].standardDeviation) -stdout.write("\n") - diff --git a/examples/talk/dsl.nim b/examples/talk/dsl.nim deleted file mode 100644 index 2dde517903..0000000000 --- a/examples/talk/dsl.nim +++ /dev/null @@ -1,33 +0,0 @@ - -import strutils - -template html(name, matter: untyped) = - proc name(): string = - result = "" - matter - result.add("") - -template nestedTag(tag: untyped) = - template tag(matter: typed) = - result.add("<" & astToStr(tag) & ">") - matter - result.add("") - -template simpleTag(tag: untyped) = - template tag(matter: untyped) = - result.add("<$1>$2" % [astToStr(tag), matter]) - -nestedTag body -nestedTag head -nestedTag ul -simpleTag title -simpleTag li - -html mainPage: - head: - title "now look at this" - body: - ul: - li "Nim is quite capable" - -echo mainPage() diff --git a/examples/talk/formatoptimizer.nim b/examples/talk/formatoptimizer.nim deleted file mode 100644 index 6e3d0c2c39..0000000000 --- a/examples/talk/formatoptimizer.nim +++ /dev/null @@ -1,55 +0,0 @@ -## This is the example that optimizes a modified "hello world" - -import macros - -proc invalidFormatString() = - echo "invalidFormatString" - -template formatImpl(handleChar: untyped) = - var i = 0 - while i < f.len: - if f[i] == '$': - case f[i+1] - of '1'..'9': - var j = 0 - i += 1 - while f[i] in {'0'..'9'}: - j = j * 10 + ord(f[i]) - ord('0') - i += 1 - result.add(a[j-1]) - else: - invalidFormatString() - else: - result.add(handleChar(f[i])) - i += 1 - -proc `%`*(f: string, a: openArray[string]): string = - template identity(x: untyped): untyped = x - result = "" - formatImpl(identity) - -macro optFormat{`%`(f, a)}(f: string{lit}, a: openArray[string]): untyped = - result = newNimNode(nnkBracket) - #newCall("&") - let f = f.strVal - formatImpl(newLit) - result = nestList(newIdentNode("&"), result) - -template optAdd1{x = y; add(x, z)}(x, y, z: string) = - x = y & z - -#template optAdd2{x.add(y); x.add(z)}(x, y, z: string) = -# x.add(y & z) - -proc `/&` [T: object](x: T): string = - result = "(" - for name, value in fieldPairs(x): - result.add("$1: $2\n" % [name, $value]) - result.add(")") - -type - MyObject = object - a, b: int - s: string -let obj = MyObject(a: 3, b: 4, s: "abc") -echo(/&obj) diff --git a/examples/talk/hoisting.nim b/examples/talk/hoisting.nim deleted file mode 100644 index 54e00884f9..0000000000 --- a/examples/talk/hoisting.nim +++ /dev/null @@ -1,23 +0,0 @@ -type - Regex = distinct string - -const maxSubpatterns = 10 - -proc re(x: string): Regex = - result = Regex(x) - -proc match(s: string, pattern: Regex, captures: var openArray[string]): bool = - true - -template optRe{re(x)}(x: string{lit}): Regex = - var g {.global.} = re(x) - g - -template `=~`(s: string, pattern: Regex): bool = - when not declaredInScope(matches): - var matches {.inject.}: array[maxSubPatterns, string] - match(s, pattern, matches) - -for line in lines("input.txt"): - if line =~ re"(\w+)=(\w+)": - echo "key-value pair; key: ", matches[0], " value: ", matches[1] diff --git a/examples/talk/lazyeval.nim b/examples/talk/lazyeval.nim deleted file mode 100644 index 77d9638343..0000000000 --- a/examples/talk/lazyeval.nim +++ /dev/null @@ -1,12 +0,0 @@ - -const - debug = true - -template log(msg: string) = - if debug: - echo msg -var - x = 1 - y = 2 - -log("x: " & $x & ", y: " & $y) diff --git a/examples/talk/quasiquote.nim b/examples/talk/quasiquote.nim deleted file mode 100644 index b3c7bb9712..0000000000 --- a/examples/talk/quasiquote.nim +++ /dev/null @@ -1,11 +0,0 @@ - -import macros - -macro check(ex: untyped): typed = - var info = ex.lineinfo - var expString = ex.toStrLit - result = quote do: - if not `ex`: - echo `info`, ": Check failed: ", `expString` - -check 1 < 2 diff --git a/examples/talk/tags.nim b/examples/talk/tags.nim deleted file mode 100644 index 8bf3450c9e..0000000000 --- a/examples/talk/tags.nim +++ /dev/null @@ -1,9 +0,0 @@ - -template htmlTag(tag: untyped) = - proc tag(): string = "<" & astToStr(tag) & ">" - -htmlTag(br) -htmlTag(html) - -echo br() -echo html() \ No newline at end of file diff --git a/examples/tunit.nim b/examples/tunit.nim deleted file mode 100644 index e8ff8a9527..0000000000 --- a/examples/tunit.nim +++ /dev/null @@ -1,47 +0,0 @@ - -import - unittest, macros - -var - a = 1 - b = 22 - c = 1 - d = 3 - -suite "my suite": - setup: - echo "suite setup" - var testVar = "from setup" - - teardown: - echo "suite teardown" - - test "first suite test": - testVar = "modified" - echo "test var: " & testVar - check a > b - - test "second suite test": - echo "test var: " & testVar - -proc foo: bool = - echo "running foo" - return true - -proc err = - raise newException(ArithmeticDefect, "some exception") - -test "final test": - echo "inside suite-less test" - - check: - a == c - foo() - d > 10 - -test "arithmetic failure": - expect(ArithmeticDefect): - err() - - expect(ArithmeticDefect, CatchableError): - discard foo()