Skip to content

Commit

Permalink
Merge pull request #24 from semperos/pervasive-time-functions
Browse files Browse the repository at this point in the history
More pervasive time functions
  • Loading branch information
semperos authored Oct 19, 2024
2 parents 3aab23a + 2d81c3a commit 34a659c
Show file tree
Hide file tree
Showing 13 changed files with 358 additions and 92 deletions.
1 change: 0 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Credits

- Implementation of `reshape` by anaseto, shared [on Matrix](https://matrix.to/#/#aplfarm-k:matrix.org)
- Implementation of `shape` by John Earnest, shared [in the k tree StackExchange chat](https://chat.stackexchange.com/transcript/message/54070438#54070438)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Non-exhaustive list:

- IN PROGRESS: Test coverage
- IN PROGRESS: Consider which of ari's functions should be pervasive; review Goal's approach and implement
- TODO: Consider which of ari's pervasive functions should operate on dictionaries
- TODO: BUG When using `-l` flag, loaded files aren't completely evaluated. Evaluation stops partway through and it's not immediately clear why.
- TODO: BUG `json.tbl` produces improper zero values when keys are missing. Where possible, column lists should be of uniform type and not generic if the data allows for it.
- TODO: Make version of `fmt.tbl` that allows setting maximum column width.
Expand Down
1 change: 0 additions & 1 deletion ari.goal
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/ Shape
istbl:{and["d"=@x;&/"s"=@'!x;&/{(@'x)¿"ANSI"}x;&/(*ls)=ls:#'x]} / is x a dictionary-as-table
reshape:{((*/x)#y){(-y)$x}/|1_x} / Implementation by anaseto, shared on Matrix
shape:{-1_#:'*:\x} / Implementation by John Earnest, shared on k-tree
depths:{[ind;l]?[(@l)~"A";,/o[ind+1]'l; (@l)¿"NSI";(#l)#ind; ind-1]} / list depths
zero:..[i:0;n:0.0;s:"";r:rx//;d:()!();f:(:);A:()] / handle, error don't fill
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
toolchain go1.22.0

require (
codeberg.org/anaseto/goal v0.44.1-0.20241011162947-26150a9b2b97
codeberg.org/anaseto/goal v0.44.1-0.20241018155253-99ede8744fba
github.com/charmbracelet/lipgloss v0.13.0
github.com/go-resty/resty/v2 v2.15.3
github.com/jarcoal/httpmock v1.3.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
codeberg.org/anaseto/goal v0.44.1-0.20241011162947-26150a9b2b97 h1:Uxj3Ga8TqZkDLj0531HAKwdrrVIVd52nzEj/4I2iTn4=
codeberg.org/anaseto/goal v0.44.1-0.20241011162947-26150a9b2b97/go.mod h1:oipi4mkQiwXW9Td2IxNhuMV0Ewq4obs6EvkqpyZ6qMs=
codeberg.org/anaseto/goal v0.44.1-0.20241018155253-99ede8744fba h1:PwBaT7eRHnn0JgTURYO18eoMZOfUqwGJx3ruYyFYCOo=
codeberg.org/anaseto/goal v0.44.1-0.20241018155253-99ede8744fba/go.mod h1:oipi4mkQiwXW9Td2IxNhuMV0Ewq4obs6EvkqpyZ6qMs=
github.com/apache/arrow/go/v17 v17.0.0 h1:RRR2bdqKcdbss9Gxy2NS/hK8i4LDMh23L6BbkN5+F54=
github.com/apache/arrow/go/v17 v17.0.0/go.mod h1:jR7QHkODl15PfYyjM2nU+yTLScZ/qfj7OSUZmJ8putc=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
Expand Down
16 changes: 16 additions & 0 deletions goal.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,19 @@ func helpForHTTPFn(s string) string {
" - RawPathParams",
}, "\n")
}

// panicType produces an bad type panic.
//
// Copied from Goal's implementation.
func panicType(op, sym string, x goal.V) goal.V {
return goal.Panicf("%s : bad type %q in %s", op, x.Type(), sym)
}

// panicLength produces an length mismatch panic.
//
// Copied from Goal's implementation.
//
//nolint:unused // Going to use in subsequent commits
func panicLength(op string, n1, n2 int) goal.V {
return goal.Panicf("%s : length mismatch: %d vs %d", op, n1, n2)
}
5 changes: 0 additions & 5 deletions sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ func SQLExec(sqlDatabase *SQLDatabase, sqlQuery string, args []any) (goal.V, err
return goal.NewD(ks, vs), nil
}

// Copied from Goal's implementation, a panic value for type mismatches.
func panicType(op, sym string, x goal.V) goal.V {
return goal.Panicf("%s : bad type %q in %s", op, x.Type(), sym)
}

// Implements sql.open to open a SQL database.
func VFSqlOpen(_ *goal.Context, args []goal.V) goal.V {
x := args[len(args)-1]
Expand Down
8 changes: 7 additions & 1 deletion testing/time-test.goal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tt.t{"Mon Jan _2 15:04:05 MST 2006"~time.UnixDate}; ft:time.RFC3339; pt:time.parse[ft;]
t1:pt@"2019-12-31T23:59:58.123456789Z";t2:pt@"2020-01-01T00:00:00Z"
t1:pt@"2019-12-31T23:59:58.123456789Z";t2:pt@"2020-01-01T00:00:00Z";t3:pt@"2024-07-01T00:00:00Z"
tt.t{2=time.weekday t1} / Tuesday
tt.t{3=time.weekday t2} / Wednesday
tt.t{365=time.yearday t1}
Expand Down Expand Up @@ -38,3 +38,9 @@ tt.t{pt["2019-02-03T04:05:06.789000000Z"]~time.date[2019;2;3;4;5;6;789000000]}
utc8:time.fixedzone["UTC-8";*/-8 60 60]
tt.t{time.parse[time.RFC822Z;"03 Feb 19 04:05 -0800"]~time.date[2019;2;3;4;5;0;0;utc8]}
tt.t{"UTC-8"~time.locationstring utc8}
tt.t{time.date[2020;1;1]~t2}
tt.t{time.date[2020;1;1;1]~time.Hour time.add t2}
tt.t{time.date[2020;1;1;2]~(2*time.Hour)time.add t2}
tt.t{(time.date[2020;1;1;1];time.date[2024;7;1;1])~time.Hour time.add (t2;t3)}
tt.t{time.date[2020;1;2;12]~t2 time.add (36*time.Hour)}
tt.t{(time.date[2020;1;1;3];time.date[2020;1;1;6];time.date[2020;1;1;9])~t2 time.add (3 6 9)*time.Hour}
Loading

0 comments on commit 34a659c

Please sign in to comment.