Introspect

Dynamic functions that return information about the s-expressions associated to a binding.

arguments

dynamic

Dynamic

                        (arguments binding)
                    

What are the arguments to this binding?

  • When binding is a function, returns the argument array.
  • When binding is a command, returns the argument array.
  • When binding is a primitive, returns the argument array.
  • When binding is an interface, returns the argument array.
  • When binding is a struct, returns the fields.
  • When binding is a sumtype, returns a list of the type arguments of each constructor.
  • Otherwise it returns an empty list.

arity

dynamic

Dynamic

                        (arity binding)
                    

What's the arity of this binding?

  • When binding is a function, returns the number of arguments.
  • When binding is a command, returns the number of arguments.
  • When binding is a primitive, returns the number of arguments.
  • When binding is an interface, returns the number of arguments.
  • When binding is a struct, returns the number of fields.
  • When binding is a sumtype, returns a list of the number of type arguments of each constructor.
  • Otherwise it returns 0.

command?

dynamic

Dynamic

                        (command? binding)
                    

Is this binding a command?

dynamic?

dynamic

Dynamic

                        (dynamic? binding)
                    

Is this binding a dynamic binding?

external?

dynamic

Dynamic

                        (external? binding)
                    

Is this binding external?

function?

dynamic

Dynamic

                        (function? binding)
                    

Is this binding a function?

implements?

macro

Macro

                        (implements? interface function)
                    

Does function implement interface?

interface?

dynamic

Dynamic

                        (interface? binding)
                    

Is this binding an interface?

macro?

dynamic

Dynamic

                        (macro? binding)
                    

Is this binding a macro?

module?

dynamic

Dynamic

                        (module? binding)
                    

Is this binding a module?

primitive?

dynamic

Dynamic

                        (primitive? binding)
                    

Is this binding a primitive?

struct?

dynamic

Dynamic

                        (struct? binding)
                    

Is this binding a struct?

sumtype?

dynamic

Dynamic

                        (sumtype? binding)
                    

Is this binding a sumtype?

type?

dynamic

Dynamic

                        (type? binding)
                    

Is this binding a type?

variable?

dynamic

Dynamic

                        (variable? binding)
                    

Is this binding a variable?

with-copy

macro

Macro

                        (with-copy function arg)
                    

Returns a reference to an anonymous 'proxied' variant of function in which the argument in position arg (indexed from 0) is copied from a reference before being passed to function:

;; Array.reduce expects a function that takes a *ref* in its second argument:
;;   (Fn [a (Ref b c)] ...)
;; so we can't use a function like `+` directly; enter proxy
(reduce (with-copy + 2) 0 &[1 2 3])
=> 6
;; compare this with an inline anonymous function that achieves the same thing:
(reduce &(fn [x y] (+ x @y)) 0 &[1 2 3]) === (reduce (with-copy + 2) 0 &[1 2 3])

This is useful when using higher-order functions that operate over structures that return references to their inhabitants, such as arrays or structs. It allows you to use a function over values without writing a custom anonymous function to handle copying.

Furthermore, one can define bespoke variants for working with particular higher-order functions. For instace, reduce always expacts a reference in the second positon:

(defmacro reducer [function]
  (eval (list with-copy function 2)))
(reduce (reducer +) 0 &[1 2 3])
=> 6