mirror of
https://github.com/sharkdp/bat.git
synced 2025-08-19 04:17:31 +02:00
Add Odin submodule and syntax test file
This commit is contained in:
27
tests/syntax-tests/highlighted/Odin/test.odin
vendored
Normal file
27
tests/syntax-tests/highlighted/Odin/test.odin
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
[38;2;249;38;114mpackage[0m[38;2;248;248;242m main[0m
|
||||
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mcore:fmt[0m[38;2;230;219;116m"[0m
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mcore:math[0m[38;2;230;219;116m"[0m
|
||||
|
||||
[38;2;166;226;46mVector[0m[38;2;248;248;242m :: [0m[3;38;2;102;217;239mstruct[0m[38;2;248;248;242m {[0m
|
||||
[38;2;248;248;242m components: [0m[38;2;248;248;242m[[0m[38;2;248;248;242m][0m[3;38;2;102;217;239mf64[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;166;226;46meuclidean_distance[0m[38;2;248;248;242m :: [0m[3;38;2;102;217;239mproc[0m[38;2;248;248;242m(v1: Vector, v2: Vector) -> [0m[3;38;2;102;217;239mf64[0m[38;2;248;248;242m {[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m [0m[38;2;102;217;239mlen[0m[38;2;248;248;242m(v1.components) != [0m[38;2;102;217;239mlen[0m[38;2;248;248;242m(v2.components) {[0m
|
||||
[38;2;248;248;242m [0m[38;2;102;217;239mpanic[0m[38;2;248;248;242m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mVectors must be same dimension[0m[38;2;230;219;116m"[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m }[0m
|
||||
[38;2;248;248;242m sum: [0m[3;38;2;102;217;239mf64[0m[38;2;248;248;242m = [0m[38;2;190;132;255m0.0[0m[38;2;248;248;242m;[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m i, comp [0m[38;2;249;38;114min[0m[38;2;248;248;242m v1.components {[0m
|
||||
[38;2;248;248;242m diff := comp - v2.components[i];[0m
|
||||
[38;2;248;248;242m sum += diff * diff;[0m
|
||||
[38;2;248;248;242m }[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mreturn[0m[38;2;248;248;242m math.[0m[38;2;102;217;239msqrt[0m[38;2;248;248;242m(sum);[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;166;226;46mmain[0m[38;2;248;248;242m :: [0m[3;38;2;102;217;239mproc[0m[38;2;248;248;242m() {[0m
|
||||
[38;2;248;248;242m v1: Vector = Vector{components = [0m[38;2;248;248;242m[[0m[38;2;248;248;242m][0m[3;38;2;102;217;239mf64[0m[38;2;248;248;242m{[0m[38;2;190;132;255m1.0[0m[38;2;248;248;242m, [0m[38;2;190;132;255m2.0[0m[38;2;248;248;242m, [0m[38;2;190;132;255m3.0[0m[38;2;248;248;242m}};[0m
|
||||
[38;2;248;248;242m v2: Vector = Vector{components = [0m[38;2;248;248;242m[[0m[38;2;248;248;242m][0m[3;38;2;102;217;239mf64[0m[38;2;248;248;242m{[0m[38;2;190;132;255m4.0[0m[38;2;248;248;242m, [0m[38;2;190;132;255m6.0[0m[38;2;248;248;242m, [0m[38;2;190;132;255m8.0[0m[38;2;248;248;242m}};[0m
|
||||
[38;2;248;248;242m dist: [0m[3;38;2;102;217;239mf64[0m[38;2;248;248;242m = [0m[38;2;102;217;239meuclidean_distance[0m[38;2;248;248;242m(v1, v2);[0m
|
||||
[38;2;248;248;242m fmt.[0m[38;2;102;217;239mprintln[0m[38;2;248;248;242m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mDistance:[0m[38;2;230;219;116m"[0m[38;2;248;248;242m, dist);[0m
|
||||
[38;2;248;248;242m}[0m
|
27
tests/syntax-tests/source/Odin/test.odin
vendored
Normal file
27
tests/syntax-tests/source/Odin/test.odin
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:math"
|
||||
|
||||
Vector :: struct {
|
||||
components: []f64,
|
||||
}
|
||||
|
||||
euclidean_distance :: proc(v1: Vector, v2: Vector) -> f64 {
|
||||
if len(v1.components) != len(v2.components) {
|
||||
panic("Vectors must be same dimension")
|
||||
}
|
||||
sum: f64 = 0.0;
|
||||
for i, comp in v1.components {
|
||||
diff := comp - v2.components[i];
|
||||
sum += diff * diff;
|
||||
}
|
||||
return math.sqrt(sum);
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
v1: Vector = Vector{components = []f64{1.0, 2.0, 3.0}};
|
||||
v2: Vector = Vector{components = []f64{4.0, 6.0, 8.0}};
|
||||
dist: f64 = euclidean_distance(v1, v2);
|
||||
fmt.println("Distance:", dist);
|
||||
}
|
Reference in New Issue
Block a user