Lisp Function: sysctl

Npt documentation.

Reference: ANSI Common Lisp npt

Lisp Function Specification

The following functions of the npt-system package are described.

defun sysctl
sysctl: memory-stream, size
sysctl: memory-stream, array
sysctl: memory-stream, cache
sysctl: clos, slots
sysctl: recovery, no-applicable-method
sysctl: recovery, no-next-method
sysctl: structure, check
sysctl: structure, delete
sysctl: structure, type
sysctl: random-state, integer
sysctl: random-state, make
sysctl: random-state, write

Function sysctl

This function performs the following operations.

(defun sysctl (type &rest args) ...) -> *

Input: type, object
Input: args
Output: *

The type can be any of the following

Function sysctl: memory-stream

Retrieves information from a memory-stream object.
Execution is done as follows.

* (setq x (make-memory-io-stream ...))
* (sysctl x ...)

Continue accepting the next argument.

sysctl: memory-stream, size

Get the size of memory-stream.
size is the number of bytes of the internal buffer.
An example of execution is shown below.

* (setq x (make-memory-io-stream :size 10))
* (sysctl x 'size)
10
T

sysctl: memory-stream, array

Get the array of memory-stream.
array is the number of internal buffers.
An example of execution is shown below.

* (setq x (make-memory-io-stream :array 20))
* (sysctl x 'array)
20
T

sysctl: memory-stream, cache

Get the cache of memory-stream.
The cache is whether the open function should use the cache or not.
An example of execution is shown below.

* (setq x (make-memory-io-stream :cache t))
* (sysctl x 'cache)
T
T

Function sysctl: clos

Get information from a clos object.
A clos object is anything created by make-instance, including instances of structure-object, structure-object.
It also includes instances of standard-class, structure-class, and built-in-class.
However, corresponding instances of class of built-in-class are not included because they are Lisp objects.

Execution is done as follows.

* (setq x (make-instance ...))
* (sysctl x ...)

Continue accepting the next argument.

sysctl: clos, slots

Get all slots.
An execution example is shown below.

* (sysctl (find-class 'class) 'slots)
(NPT-CLOS::NAME NPT-CLOS::DIRECT-SLOTS NPT-CLOS::DIRECT-SUBCLASSES
 NPT-CLOS::DIRECT-SUPERCLASSES NPT-CLOS:CLASS-PRECEDENCE-LIST NPT-CLOS::EFFECTIVE-SLOTS
 NPT-CLOS::FINALIZED-P NPT-CLOS::PROTOTYPE NPT-CLOS::DEFAULT-INITARGS
 NPT-CLOS::DIRECT-DEFAULT-INITARGS NPT-CLOS::VERSION NPT-CLOS::DOCUMENTATION
 NPT-CLOS::REDEFINED-CLASS)
T

Function sysctl: recovery

recovery restores the specified content to its initial state.
The execution is done as follows.

* (sysctl 'recovery ...)

The 'recovery argument is treated as a string and is checked with equalp.

It will continue to accept the next argument.

sysctl: recovery, no-applicable-method

Restore the generic function no-applicable-method to its initial state.
The execution is as follows.

* (sysctl 'recovery 'no-applicable-method)
T
T

sysctl: recovery, no-next-method

Restore the generic function no-next-method to its initial state.
The execution is as follows.

* (sysctl 'recovery 'no-next-method)
T
T

Function sysctl: structure

structure performs operations on structures.
Execution is done as follows.

* (sysctl 'structure ...)

The 'structure argument is treated as a string and is checked with equalp.

It continues to accept the next argument.

sysctl: structure, check

Checks for the existence of a structure with the specified name that does not belong to the structure-class.

When you define a structure, a class belonging to the structure-class is normally generated.
However, if you specify list or vector as the :type argument of defstruct, a structure different from the class system will be generated, which cannot be checked by functions such as find-class.
check will check for the existence of such a structure.

The execution is as follows.

* (defstruct (aaa (:type list)))
* (sysctl 'structure 'check 'aaa)
T
T
* (defstruct bbb)
* (sysctl 'structure 'check 'bbb)
NIL
T

sysctl: structure, delete

Deletes the structure with the specified name.

Removes both structures of structure-class and structures that do not belong to it.
Remove access functions, constructor, copier, and print-object for structures.

The following is an example of execution.

* (defstruct aaa)
* (sysctl 'structure 'delete 'aaa)
T
T
* (find-class 'aaa nil)
NIL

* (defstruct (bbb (:type vector)))
* (sysctl 'structure 'delete 'bbb)
T
T
* (sysctl 'structure 'check 'bbb)
NIL
T
* (fboundp 'make-bbb)
NIL

sysctl: structure, type

Returns the type of the structure with the specified name.

The returned value is as follows

An example of how to do this is shown below.

* (defstruct aaa)
* (defstruct (bbb (:type (vector (unsigned-byte 8)))))
* (sysctl 'structure 'type 'aaa)
CLASS
T
* (sysctl 'structure 'type 'bbb)
(VECTOR (UNSIGNED-BYTE 8))
T

Function sysctl: random-state

Performs operations on random-state objects.
Execution is done as follows.

* (sysctl 'random-state ...)

The 'random-state argument is treated as a string and is checked with equalp.

It continues to accept the next argument.

sysctl: random-state, integer

Output the internal state of random-state as an integer.

npt implements xorshift as a random number algorithm, and has 128-bit integer in the internal state of random-state.
This function outputs the internal state as an integer.
The output internal state can be restored by make and write.

The following is an example of execution.

* (setq *print-base* 16)
* (setq x (make-random-state t))
#<RANDOM-STATE #xF3F85807E6E2837033526396D518DAD1>
* (sysctl 'random-state 'integer x)
F3F85807E6E2837033526396D518DAD1
T

sysctl: random-state, make

Generates a random-state with the specified argument set to the internal state.

Since the argument is obtained by 128 bits with ldb, negative values can be set.

* (setq *print-base* 16)
* (setq x (sysctl 'random-state 'make #xABCD))
#<RANDOM-STATE #xABCD>
T
* (sysctl 'random-state 'integer x)
ABCD
T

sysctl: random-state, write

Specifies the internal state of a random-state object.

Since the argument is obtained by 128 bits with ldb, negative values can be set.

* (setq *random-state* (make-random-state t))
#<RANDOM-STATE #x14F392860E2329DE919C083F0B764EC5>
* (setq y (sysctl 'random-state 'integer *random-state*))
27849259905073490890992780948155027141
T
* (random 10)
3
* (random 10)
6
* (random 10)
7
* (sysctl 'random-state 'write *random-state* y)
#<RANDOM-STATE #x14F392860E2329DE919C083F0B764EC5>
T
* (random 10)
3
* (random 10)
6
* (random 10)
7