renamings
[rrq/lsp-utils.git] / lsp-misc / lsp-misc.a.8.adoc
1 = lsp-misc.a(8)
2 :doctype: manpage
3 :revdate: {sys:date "+%Y-%m-%d %H:%M:%S"}
4
5 == NAME
6
7 lsp-misc.a - Misceallaneous useful functions.
8
9 == SYNOPSIS
10
11 .With packnl (example)
12 packnl _main.lsp_ *-A lsp-misc.a*
13
14
15 .With incore.lsp
16 (load "incore.lsp") +
17 (archive "lsp-misc.a") +
18 (load "misc.lsp")
19
20 == DESCRIPTION
21
22 *lsp-misc.a* provides a few global utility functions.
23
24 === misc.lsp API
25
26 (prog1 [_term_]*)::
27
28 The *prog1* function is like a *begin* function except that it returns
29 the value of the first term rather than the last.
30
31 (die _N_ [_term_]*)::
32
33 The *die* function printes to stderr the join of term values as
34 strings with space separation, and if _N_ is a number, then the
35 function exits the program with that return code.
36 +
37 .Example of stderr logging
38 (die nil 'This "is" 'printed "to stderr")
39
40 (octal-byte _B_)::
41 Print binary byte as octal or as ASCII character [32-126].
42
43 (octals-string _S_)::
44 Print string as a succesion of +octal-byte+.
45
46 (human-byte _B_)::
47 Return byte code as printable (string) or as code (number).
48
49 (human-bytes _BL_)::
50
51 Return a list of human-byte elements from a list of byte codes but
52 also joining consecutive string elements to form packed strings.
53
54 === foop.lsp API
55
56 This newlisp module provides Functional Object-Oriented Programming
57 (FOOP) modelling support.
58
59 FOOP is an abstraction overlay using the newlisp context notion as a
60 simile to the _class_ notion in genuine object-oriented programming
61 languages. This is set out in newlisp by means of the representation
62 principle that an instance of a FOOP "class" (i.e. context) is a list
63 headed by the context itself, and followed by the "member values".
64
65 FOOP further includes by the "method invocation" syntax where a
66 function is preceded by ':' and then followed by the instance
67 concerned before actual function arguments. That instance is then
68 stoved away as implicitly available via the (self) function, and the
69 member values accessible via index, e.g. the term (self 3) refers to
70 the third member of the instance. The self references are
71 destructively assignable with setf.
72
73 This modelling support adds member name declaration together with
74 automatic getter and setter defintions. The (FOOP ...) term is used
75 for declaring member names in order. For example:
76
77 (FOOP [_name_])::
78
79 *FOOP* is like a language extension to declare the field names of a
80 FOOP class, and thereby gain "get" and "set" functions generated with
81 the respective naming formats (:%name obj) and (:!name obj value).
82
83 .illustration 
84 ----
85 (context 'MAIN:EX)
86 (FOOP here there more)
87 (define (EX HERE THERE MORE) (list (context) HERE THERE MORE))
88
89 (context MAIN)
90 (setf A (EX 1 2 3))
91 --> A = (EX 1 2 3)
92 (:!there A 4)
93 --> A = (EX 1 4 3)
94 ----
95
96 === mmap.lsp API
97
98 This newlisp module implements a small FOOP model based memory mapping
99 API that links in the _libc6_ functions _mmap_, _munmap_, _msync_ and
100 _lseek_.
101
102 (*MMap* _FD_ _LENGTH_ [_OFFSET_ [_PROT_]])::
103
104 This function creates a FOOP object that represents the memory mapping
105 of the given file descriptor. _FD_ may be the pathname string of a
106 file to memory map or an already opened file descriptor. The MMap
107 object represents the memory block starting at (:%base) and (%len)
108 bytes in length where the file is memory mapped.
109 +
110 .Access example (from test.lsp)
111 [caption=""]
112 ----
113 (println (setf X (MMap "mmap.lsp")))
114 (println (get-string (:%base X)))
115 ----
116 +
117 Note that only a plain text file would be accessed with _get-string_.
118 A binary file would rather be accessed with _unpack_. The memory
119 mapping provides read-only "random access" to the file content.
120 +
121 To set up read-write acces requires an _OFFSET_ and the _PROT_
122 argument 0x3, and writing should be accompanied by _MMap:msync_ calls
123 so as to synchronize with the backing file.
124 +
125 The FOOP object includes get and set methods for the fields (in
126 order): _base_, _len_, _prot_, _flags_, _fd_ and _offset_.
127
128 === test.lsp
129
130 This file is a small test of the MMap memory mapping.
131
132 == SEE ALSO
133
134 *newlisp*
135
136 == AUTHOR
137
138 Ralph Ronnquist <ralph.ronnquist@gmail.com>