Support typed constants, all constants, and arrays with constant lengths
Pre-releaseAll (exported) constants are now wrapped; evaluation of constant expressions is now done via go/types
, go/importer
, and go/constant
, rather than via custom code in gostd
.
Constant types are now preserved. E.g. go.std.net/FlagUp
is of type net.Flags
, not Number
, so this now works (as go.std.net/Flags
is the type for FlagUp
and defines a String()
method for it and other constants), instead of just 1N
being printed:
user=> go.std.net/FlagUp
up
user=> (int go.std.net/FlagUp)
1
user=>
Constants and variables whose names match Joker type names are no longer renamed away. Use explicit namespace resolution to specify them; or, if referring a namespace that shadows a Joker type (which is not recommended), quote the type when using it as a tag. E.g.:
user=> Int
Int
user=> (type Int)
Type
user=> go.std.go.constant/Int
3
user=> (use 'go.std.go.constant)
nil
user=> Int
3
user=> (type Int)
GoObject
user=> (defn ^Int foo [])
user=> (meta (var foo))
{:line 12, :column 1, :file "<repl>", :ns user, :name foo, :tag 3, :arglists ([])}
user=> (defn ^"Int" foo [])
user=> (meta (var foo))
{:line 14, :column 1, :file "<repl>", :ns user, :name foo, :tag "Int", :arglists ([])}
user=>
Note that the first argument to catch
in a try
is known to specify a type, so the builtin Joker types will be checked first, as will likely be desirable (since catch
does not support GoType
s). E.g.:
user=> (use 'go.std.go.scanner)
nil
user=> Error
go.std.go.scanner/Error
user=> (type Error)
GoType
user=> (try true (catch Error e))
true
user=> (try true (catch go.std.go.scanner/Error e))
<repl>:26:18: Parse error: Unable to resolve type: go.std.go.scanner/Error, got: {:type :var-ref, :var #'go.std.go.scanner/Error}
user=>
The BigFloat
type is now supported for std
-generated libraries (namespaces in the std
subdirectory and built into Joker).
Further, BigFloat
s created from strings (such as 1.3M
) are given a minimum precision of 53 (the same precision as a Double
, aka float64
) or more precision based on the number of digits and the number of bits each digit represents (3.3 for decimal; 1, 3, or 4 for binary, octal, and hex).
All arrays with constant lengths are now supported. Previously only easily-evaluated lengths (such as literal constants) were supported; now, any constant expression works. This results in more functions being wrapped.
A new joker.core/precision
function has been introduced mainly to inspect BigFloat
types, though it supports a few others.