3 :revdate: {sys:date "+%Y-%m-%d %H:%M:%S"}
7 lsp-misc.a - Misceallaneous useful functions.
11 .With packnl (example)
12 packnl _main.lsp_ *-A lsp-misc.a*
17 (archive "lsp-misc.a") +
22 *lsp-misc.a* provides a few global utility functions.
28 The *prog1* function is like a *begin* function except that it returns
29 the value of the first term rather than the last.
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.
37 .Example of stderr logging
38 (die nil 'This "is" 'printed "to stderr")
41 Print binary byte as octal or as ASCII character [32-126].
44 Print string as a succesion of +octal-byte+.
47 Return byte code as printable (string) or as code (number).
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.
56 This newlisp module provides Functional Object-Oriented Programming
57 (FOOP) modelling support.
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".
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.
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:
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).
86 (FOOP here there more)
87 (define (EX HERE THERE MORE) (list (context) HERE THERE MORE))
98 This newlisp module implements a small FOOP model based memory mapping
99 API that links in the _libc6_ functions _mmap_, _munmap_, _msync_ and
102 (*MMap* _FD_ _LENGTH_ [_OFFSET_ [_PROT_]])::
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.
110 .Access example (from test.lsp)
113 (println (setf X (MMap "mmap.lsp")))
114 (println (get-string (:%base X)))
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.
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.
125 The FOOP object includes get and set methods for the fields (in
126 order): _base_, _len_, _prot_, _flags_, _fd_ and _offset_.
130 This file is a small test of the MMap memory mapping.
138 Ralph Ronnquist <ralph.ronnquist@gmail.com>