3 :revdate: {sys:date "+%Y-%m-%d %H:%M:%S"}
7 newlisp-libmisc.a - Newlisp archive comprosing useful functions.
11 .With packnl (example)
12 packnl _main.lsp_ *-A newlisp-libmisc.a*
17 (archive "newlisp-libmisc.a") +
22 *newlisp-libmisc.a* is a newlisp archive file that provides loadable
23 modules with utility functions.
29 The *prog1* function is like a *begin* function except that it returns
30 the value of the first term rather than the last.
34 The *die* function printes to stderr the join of term values as
35 strings with space separation, and if _N_ is a number, then the
36 function exits the program with that return code.
38 .Example of stderr logging
39 (die nil 'This "is" 'printed "to stderr")
42 Print binary byte as octal or as ASCII character [32-126].
45 Print string as a succesion of +octal-byte+.
48 Return byte code as printable (string) or as code (number).
52 Return a list of human-byte elements from a list of byte codes but
53 also joining consecutive string elements to form packed strings.
57 This newlisp module provides Functional Object-Oriented Programming
58 (FOOP) modelling support.
60 FOOP is an abstraction overlay using the newlisp context notion as a
61 simile to the _class_ notion in genuine object-oriented programming
62 languages. This is set out in newlisp by means of the representation
63 principle that an instance of a FOOP "class" (i.e. context) is a list
64 headed by the context itself, and followed by the "member values".
66 FOOP further includes by the "method invocation" syntax where a
67 function is preceded by ':' and then followed by the instance
68 concerned before actual function arguments. That instance is then
69 stoved away as implicitly available via the (self) function, and the
70 member values accessible via index, e.g. the term (self 3) refers to
71 the third member of the instance. The self references are
72 destructively assignable with setf.
74 This modelling support adds member name declaration together with
75 automatic getter and setter defintions. The (FOOP ...) term is used
76 for declaring member names in order. For example:
80 *FOOP* is like a language extension to declare the field names of a
81 FOOP class, and thereby gain "get" and "set" functions generated with
82 the respective naming formats (:%name obj) and (:!name obj value).
87 (FOOP here there more)
88 (define (EX HERE THERE MORE) (list (context) HERE THERE MORE))
99 This newlisp module implements a small FOOP model based memory mapping
100 API that links in the _libc6_ functions _mmap_, _munmap_, _msync_ and
103 (*MMap* _FD_ _LENGTH_ [_OFFSET_ [_PROT_]])::
105 This function creates a FOOP object that represents the memory mapping
106 of the given file descriptor. _FD_ may be the pathname string of a
107 file to memory map or an already opened file descriptor. The MMap
108 object represents the memory block starting at (:%base) and (%len)
109 bytes in length where the file is memory mapped.
111 .Access example (from test.lsp)
114 (println (setf X (MMap "mmap.lsp")))
115 (println (get-string (:%base X)))
118 Note that only a plain text file would be accessed with _get-string_.
119 A binary file would rather be accessed with _unpack_. The memory
120 mapping provides read-only "random access" to the file content.
122 To set up read-write acces requires an _OFFSET_ and the _PROT_
123 argument 0x3, and writing should be accompanied by _MMap:msync_ calls
124 so as to synchronize with the backing file.
126 The FOOP object includes get and set methods for the fields (in
127 order): _base_, _len_, _prot_, _flags_, _fd_ and _offset_.
131 This file is a small test of the MMap memory mapping.
139 Ralph Ronnquist <ralph.ronnquist@gmail.com>