Documentation ¶
Index ¶
- Constants
- type PrintfFunc
- func (obj *PrintfFunc) ArgGen(index int) (string, error)
- func (obj *PrintfFunc) Build(typ *types.Type) (*types.Type, error)
- func (obj *PrintfFunc) FuncInfer(partialType *types.Type, partialValues []types.Value) (*types.Type, []*interfaces.UnificationInvariant, error)
- func (obj *PrintfFunc) Info() *interfaces.Info
- func (obj *PrintfFunc) Init(init *interfaces.Init) error
- func (obj *PrintfFunc) Stream(ctx context.Context) error
- func (obj *PrintfFunc) String() string
- func (obj *PrintfFunc) Validate() error
Constants ¶
const ( // PrintfFuncName is the name this function is registered as. // FIXME: should this be named sprintf instead? PrintfFuncName = "printf" // PrintfAllowNonStaticFormat allows us to use printf when the zeroth // argument (the format string) is not known statically at compile time. // The downside of this is that if it changes while we are running, it // could change from "hello %s" to "hello %d" or "%s %d...". If this // happens we can generate ugly format strings, instead of preventing it // from even running at all. The behaviour if this happens is determined // by PrintfAllowFormatError. // // NOTE: It's useful to allow dynamic strings if we were generating // custom log messages (for example) where the format comes from a // database lookup or similar. Of course if we knew that such a lookup // could be done quickly and statically (maybe it's a read from a local // key-value config file that's part of our deploy) then maybe we can do // it before unification speculatively. PrintfAllowNonStaticFormat = true // PrintfAllowFormatError will cause the function to shutdown if it has // an invalid format string. Otherwise this will cause the output of the // function to return a garbled message. This is similar to golang's // format errors, eg: https://pkg.go.dev/fmt#hdr-Format_errors PrintfAllowFormatError = true )
const (
// ModuleName is the prefix given to all the functions in this module.
ModuleName = "fmt"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PrintfFunc ¶
type PrintfFunc struct { Type *types.Type // final full type of our function // contains filtered or unexported fields }
PrintfFunc is a static polymorphic function that compiles a format string and returns the output as a string. It bases its output on the values passed in to it. It examines the type of the arguments at compile time and then determines the static function signature by parsing the format string and using that to determine the final function signature. One consequence of this is that the format string must be a static string which is known at compile time. This is reasonable, because if it was a reactive, changing string, then we could expect the type signature to change, which is not allowed in our statically typed language.
func (*PrintfFunc) ArgGen ¶
func (obj *PrintfFunc) ArgGen(index int) (string, error)
ArgGen returns the Nth arg name for this function.
func (*PrintfFunc) Build ¶
Build takes the now known function signature and stores it so that this function can appear to be static. That type is used to build our function statically.
func (*PrintfFunc) FuncInfer ¶
func (obj *PrintfFunc) FuncInfer(partialType *types.Type, partialValues []types.Value) (*types.Type, []*interfaces.UnificationInvariant, error)
FuncInfer takes partial type and value information from the call site of this function so that it can build an appropriate type signature for it. The type signature may include unification variables.
func (*PrintfFunc) Info ¶
func (obj *PrintfFunc) Info() *interfaces.Info
Info returns some static info about itself.
func (*PrintfFunc) Init ¶
func (obj *PrintfFunc) Init(init *interfaces.Init) error
Init runs some startup code for this function.
func (*PrintfFunc) Stream ¶
func (obj *PrintfFunc) Stream(ctx context.Context) error
Stream returns the changing values that this func has over time.
func (*PrintfFunc) String ¶
func (obj *PrintfFunc) String() string
String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.
func (*PrintfFunc) Validate ¶
func (obj *PrintfFunc) Validate() error
Validate makes sure we've built our struct properly. It is usually unused for normal functions that users can use directly.