From: Ralph Ronnquist Date: Thu, 13 Apr 2023 09:12:06 +0000 (+1000) Subject: slight refactoring X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=1898ef96b70cb93c53a84e6a7536d0a3bceb35d6;p=rrq%2Flsp-utils.git slight refactoring --- diff --git a/Makefile b/Makefile index 93cfb40..a6575e2 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -LSPLIB = -A lsp-util/lsp-util.a -A lsp-dbus/lsp-dbus.a +LSPLIB = -A lsp-misc/lsp-misc.a -A lsp-dbus/lsp-dbus.a LSPSRC = lsp-dbus-test.lsp diff --git a/lsp-misc/Makefile b/lsp-misc/Makefile new file mode 100644 index 0000000..e691976 --- /dev/null +++ b/lsp-misc/Makefile @@ -0,0 +1,6 @@ +# Create the newlisp library foop.lsplib + +LSPSRC = misc.lsp foop.lsp + +lsp-misc.a: ${LSPSRC} + ar r $@ $^ diff --git a/lsp-misc/foop.lsp b/lsp-misc/foop.lsp new file mode 100644 index 0000000..1724d3c --- /dev/null +++ b/lsp-misc/foop.lsp @@ -0,0 +1,61 @@ +;; This newlisp module provides FOOP modelling support +;; +;; Functional Object-Oriented Programming (FOOP) is an abstraction +;; overlay using the newlisp context notion as similar to the class +;; notion in genuine object-oriented programming languages. This is +;; set out in newlisp by means of the representation principle that an +;; instance of a FOOP "class" (i.e. context) is a list headed by the +;; context itself, and followed by the "member values". +;; +;; FOOP further includes by the "method invocation" syntax where a +;; function is preceded by ':' and then followed by the instance +;; concerned before actual function arguments. That instance is then +;; stoved away as implicitly available via the (self) function, and +;; the member values accessible via index, e.g. the term (self 3) +;; refers to the third member of the instance. The self references are +;; destructively assignable with setf. +;; +;; This modelling support adds member name declaration together with +;; automatic getter and setter defintions. The (FOOP ...) term is used +;; for declaring member names in order. For example: +;; +;; (context 'MAIN:EX") +;; (FOOP a b c) +;; (define (EX:EX n) (list (context) (+ n 4) 3 2)) +;; +;; That would declare a FOOP context EX with instances having three +;; members named a, b and c. The declaratin results in a variable EX:. +;; whose value is (FOOP a b c), as well as three access functions for +;; each member: the member position index (.member), a getter +;; (%member) and a setter (!member V). +;; +;; As indicated in the example, (FOOP a b c) does not define the +;; "constructor". It only defines the access functions. + +(context 'FOOP) + +;; Helper function to make a new symbol for the context of S by +;; preceeding it with string P. +(define (name P S) (sym (string P (term S)) (prefix S))) + +;; (FOOP name ...) +; foop is a language extension to declare the field names of a FOOP +; object type, and thereby gain getter and setter functions with the +; naming formats (:%name obj) and (:!name obj value) respectively . +(define-macro (FOOP:FOOP) + (let ((K (sym "." (prefix (first (args))))) + (V (cons (context) (args))) + (I 0)) + (set K V) + (dolist (S (args)) + (letex ((GET (name "%" S)) + (SET (name "!" S)) + (IT (name "." S)) + (V (sym "V" (prefix S))) + (I (inc I))) + (define (IT) I) + (define (GET) (self I)) + (define (SET V) (setf (self I) V)))) + )) + +"foop.lsp" diff --git a/lsp-misc/misc.lsp b/lsp-misc/misc.lsp new file mode 100644 index 0000000..cf92d9c --- /dev/null +++ b/lsp-misc/misc.lsp @@ -0,0 +1,16 @@ +(define (prog1 X) X) +(global 'prog1) + +(define (die N) + (when (args) (write-line 2 (join (map string (args)) " "))) + (exit N)) +(global 'die) + +;; Print binary byte as octal or as ASCII character [32-126] +(define (octal-byte x) + (if (and (> x 31) (< x 127)) (char x) (format "\\%o" x))) + +;; Print string as binary octals +(define (octals-string S) + (join (map octal-byte (unpack (dup "b" (length S)) S))) "") +(global 'octals-string 'octal-byte) diff --git a/lsp-util/Makefile b/lsp-util/Makefile deleted file mode 100644 index 526e46f..0000000 --- a/lsp-util/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# Create the newlisp library foop.lsplib - -LSPSRC = foop.lsp misc.lsp - -lsp-util.a: ${LSPSRC} - ar r $@ $^ diff --git a/lsp-util/foop.lsp b/lsp-util/foop.lsp deleted file mode 100644 index 1724d3c..0000000 --- a/lsp-util/foop.lsp +++ /dev/null @@ -1,61 +0,0 @@ -;; This newlisp module provides FOOP modelling support -;; -;; Functional Object-Oriented Programming (FOOP) is an abstraction -;; overlay using the newlisp context notion as similar to the class -;; notion in genuine object-oriented programming languages. This is -;; set out in newlisp by means of the representation principle that an -;; instance of a FOOP "class" (i.e. context) is a list headed by the -;; context itself, and followed by the "member values". -;; -;; FOOP further includes by the "method invocation" syntax where a -;; function is preceded by ':' and then followed by the instance -;; concerned before actual function arguments. That instance is then -;; stoved away as implicitly available via the (self) function, and -;; the member values accessible via index, e.g. the term (self 3) -;; refers to the third member of the instance. The self references are -;; destructively assignable with setf. -;; -;; This modelling support adds member name declaration together with -;; automatic getter and setter defintions. The (FOOP ...) term is used -;; for declaring member names in order. For example: -;; -;; (context 'MAIN:EX") -;; (FOOP a b c) -;; (define (EX:EX n) (list (context) (+ n 4) 3 2)) -;; -;; That would declare a FOOP context EX with instances having three -;; members named a, b and c. The declaratin results in a variable EX:. -;; whose value is (FOOP a b c), as well as three access functions for -;; each member: the member position index (.member), a getter -;; (%member) and a setter (!member V). -;; -;; As indicated in the example, (FOOP a b c) does not define the -;; "constructor". It only defines the access functions. - -(context 'FOOP) - -;; Helper function to make a new symbol for the context of S by -;; preceeding it with string P. -(define (name P S) (sym (string P (term S)) (prefix S))) - -;; (FOOP name ...) -; foop is a language extension to declare the field names of a FOOP -; object type, and thereby gain getter and setter functions with the -; naming formats (:%name obj) and (:!name obj value) respectively . -(define-macro (FOOP:FOOP) - (let ((K (sym "." (prefix (first (args))))) - (V (cons (context) (args))) - (I 0)) - (set K V) - (dolist (S (args)) - (letex ((GET (name "%" S)) - (SET (name "!" S)) - (IT (name "." S)) - (V (sym "V" (prefix S))) - (I (inc I))) - (define (IT) I) - (define (GET) (self I)) - (define (SET V) (setf (self I) V)))) - )) - -"foop.lsp" diff --git a/lsp-util/misc.lsp b/lsp-util/misc.lsp deleted file mode 100644 index cf92d9c..0000000 --- a/lsp-util/misc.lsp +++ /dev/null @@ -1,16 +0,0 @@ -(define (prog1 X) X) -(global 'prog1) - -(define (die N) - (when (args) (write-line 2 (join (map string (args)) " "))) - (exit N)) -(global 'die) - -;; Print binary byte as octal or as ASCII character [32-126] -(define (octal-byte x) - (if (and (> x 31) (< x 127)) (char x) (format "\\%o" x))) - -;; Print string as binary octals -(define (octals-string S) - (join (map octal-byte (unpack (dup "b" (length S)) S))) "") -(global 'octals-string 'octal-byte)