From 8b8ca0515fe6f68b774f766f7e4f49ec26ba6590 Mon Sep 17 00:00:00 2001 From: Darren Bane Date: Thu, 19 Nov 2020 23:50:27 +0000 Subject: Try fix loading error --- basic.lsp | 2 +- parse.lsp | 43 ------------------------------------------- parsing.lsp | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 44 deletions(-) delete mode 100644 parse.lsp create mode 100644 parsing.lsp diff --git a/basic.lsp b/basic.lsp index 7f13acd..11771e9 100644 --- a/basic.lsp +++ b/basic.lsp @@ -2,7 +2,7 @@ (require "abs-syn") (require "lex") -(require "parse") +(require "parsing") (defpackage #:basic (:use #:openlisp) (:export diff --git a/parse.lsp b/parse.lsp deleted file mode 100644 index 9bedee3..0000000 --- a/parse.lsp +++ /dev/null @@ -1,43 +0,0 @@ -(defpackage #:parse - (:use #:openlisp #:lex #:abs-syn) - (:export - #:parse)) -(in-package #:parse) - -(defclass () () (:abstractp t)) -(defclass () ((expr :accessor expr))) -(defclass () ((bin-op :accessor bin-op))) -(defclass () ((unr-op :accessor unr-op))) -(defclass (") 'great))) - -(defun parse (str) - (let* ((cl (init-lex str)) - (tok (lexer cl))) - (cond ((instancep tok (class )) - (make-instance (class ) 'n n 'c (parse-cmd cl))) - ((instancep tok (class )) - (cond ((string= (ident tok) "LIST") - (create (class ))) - ((string= (ident tok) "RUN") - (create (class ))) - ((string= (ident tok) "END") - (create (class ))) - (t (error "Parse error")))) - (t (error "Parse error"))))) -(provide "parse") diff --git a/parsing.lsp b/parsing.lsp new file mode 100644 index 0000000..e79451a --- /dev/null +++ b/parsing.lsp @@ -0,0 +1,43 @@ +(defpackage #:parsing + (:use #:openlisp #:lex #:abs-syn) + (:export + #:parse)) +(in-package #:parsing) + +(defclass () () (:abstractp t)) +(defclass () ((expr :accessor expr))) +(defclass () ((bin-op :accessor bin-op))) +(defclass () ((unr-op :accessor unr-op))) +(defclass () ()) + +(defun unr-symb (s) + (cond ((string= s "!") 'not) + ((string= s "-") 'uminus) + (t (error "Parse error")))) + +(defun bin-symb (s) + (cond ((string= s "+") 'plus) + ((string= s "-") 'minus) + ((string= s "*") 'mult) + ((string= s "/") 'div) + ((string= s "%") 'mod) + ((string= s "=") 'equal) + ((string= s "<") 'less) + ((string= s "<=") 'lesseq) + ((string= s ">") 'great))) + +(defun parse (str) + (let* ((cl (init-lex str)) + (tok (lexer cl))) + (cond ((instancep tok (class )) + (create (class ) 'n n 'c (parse-cmd cl))) + ((instancep tok (class )) + (cond ((string= (ident tok) "LIST") + (create (class ))) + ((string= (ident tok) "RUN") + (create (class ))) + ((string= (ident tok) "END") + (create (class ))) + (t (error "Parse error")))) + (t (error "Parse error"))))) +(provide "parse") -- cgit 1.4.1-2-gfad0 From 29b8a4f8f178f83cffe2f41a3c22761030a8454a Mon Sep 17 00:00:00 2001 From: Darren Bane Date: Thu, 19 Nov 2020 23:51:17 +0000 Subject: Try fix loading --- parsing.lsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parsing.lsp b/parsing.lsp index e79451a..3e26a35 100644 --- a/parsing.lsp +++ b/parsing.lsp @@ -40,4 +40,4 @@ (create (class ))) (t (error "Parse error")))) (t (error "Parse error"))))) -(provide "parse") +(provide "parsing") -- cgit 1.4.1-2-gfad0 From da9f8c68fb8048a559626ea2d327a04b65c432c7 Mon Sep 17 00:00:00 2001 From: Darren Bane Date: Thu, 3 Dec 2020 19:35:03 +0000 Subject: Simplify TCP server --- echo.lsp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/echo.lsp b/echo.lsp index 20b5e7e..4c788e6 100755 --- a/echo.lsp +++ b/echo.lsp @@ -42,24 +42,16 @@ (defun echo-server () ;; Server side (server addr : 127.0.0.1) (with-server-socket (server 8192 "tcp") - (let ((fds (create-vector 16 ())) - (fdr (create-vector 16 ())) - (fdw (create-vector 16 ()))) - (select-clear fds) - (select-add server fds) - (while (eq (select 1 fds fdr fdw () 5.0) 0) - (print "Waiting ....")) - (let ((client (accept server))) - ;; Talk with client using standard I/O. - (with-standard-input client - (with-standard-output client - (while t - (let* ((line1 (read-line)) - (tag-len (length +content-length+)) - (content-length (convert (subseq line1 (- tag-len 1) (length line1)) ))) - (read-line) - (marshal (json-parse (read-chars content-length))))))) - (close client)) - (select-remove server fds)))) + (let ((client (accept server))) + ;; Talk with client using standard I/O. + (with-standard-input client + (with-standard-output client + (while t + (let* ((line1 (read-line)) + (tag-len (length +content-length+)) + (content-length (convert (subseq line1 (- tag-len 1) (length line1)) ))) + (read-line) + (marshal (json-parse (read-chars content-length))))))) + (close client)))) (provide "echo") (echo-server) -- cgit 1.4.1-2-gfad0 From 078ae5a0780015dfff775196d675fb23f0367060 Mon Sep 17 00:00:00 2001 From: Darren Bane Date: Fri, 4 Dec 2020 00:47:27 +0000 Subject: Can't get past that OpenLisp error; go back to sbcl --- cdbc.lisp | 2 ++ clex.lisp | 8 +++++++- cparse.lisp | 2 +- cutil.lisp | 6 +++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cdbc.lisp b/cdbc.lisp index 9d790ab..57e04e5 100644 --- a/cdbc.lisp +++ b/cdbc.lisp @@ -1,5 +1,7 @@ ;; Ported from https://rosettacode.org/wiki/Assertions_in_design_by_contract#Eiffel ;; Arguably not *quite* design-by-contract, but very close in vanilla CL +;; +;; NB: This has non-essential complexity compared to the ISLisp version. (defun average-of-absolutes (values) (declare (list values)) (assert (> (length values) 0)) diff --git a/clex.lisp b/clex.lisp index cdd6025..550ead4 100644 --- a/clex.lisp +++ b/clex.lisp @@ -4,7 +4,9 @@ #: #: #: - #:)) + #: + #: + #:ident)) (in-package #:clex) (defclass () () (:metaclass )) @@ -55,4 +57,8 @@ (and (char>= x #\0) (char<= x #\9)) (char= x #\_)))) (extract #'is-alpha-num cl))) + +(defgeneric lexer (cl)) +(defmethod lexer ((cl )) + ) (provide "clex") diff --git a/cparse.lisp b/cparse.lisp index 602dc76..31d7817 100644 --- a/cparse.lisp +++ b/cparse.lisp @@ -27,7 +27,7 @@ ((string= s ">") 'great))) (defun parse (str) - (let* ((cl (init-lex str)) + (let* ((cl (make-instance (find-class ') 's str)) (tok (lexer cl))) (cond ((instancep tok (find-class ')) (make-instance (find-class ') 'n n 'c (parse-cmd cl))) diff --git a/cutil.lisp b/cutil.lisp index e651b11..6b3f381 100644 --- a/cutil.lisp +++ b/cutil.lisp @@ -1,7 +1,8 @@ (defpackage #:cutil (:use #:common-lisp) (:export - #:)) + #: + #:instancep)) (in-package #:cutil) (defclass (standard-class) ()) @@ -18,4 +19,7 @@ (superclass )) t) +(defun instancep (obj cls) + (eq (class-of obj) cls)) + (provide "cutil") -- cgit 1.4.1-2-gfad0 From 10b5ba35c96f72e5b66698b36c7e0a38b555f394 Mon Sep 17 00:00:00 2001 From: Darren Bane Date: Fri, 4 Dec 2020 21:02:35 +0000 Subject: Start porting 'lexer' --- clex.lisp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/clex.lisp b/clex.lisp index 550ead4..7ca04f0 100644 --- a/clex.lisp +++ b/clex.lisp @@ -6,7 +6,8 @@ #: #: #: - #:ident)) + #:ident + #:lexer)) (in-package #:clex) (defclass () () (:metaclass )) @@ -60,5 +61,23 @@ (defgeneric lexer (cl)) (defmethod lexer ((cl )) + (flet ((lexer-char (c) + (cond ((member c '(#\space #\tab)) + (forward cl) + (lexer cl)) ; NB: tail recursion. ok? + ((or (and (char>= c #\a) (char<= c #\z)) + (and (char>= c #\A) (char<= c #\Z))) + (make-instance (find-class ') 'i (extract-ident cl))) + ((char= c #\") + (forward cl) + (let ((res (make-instance (find-class ') 's (extract (lambda (c) (char/= c #\")) cl)))) + (forward cl) + res)) + ((member c '(#\+ #\- #\* #\/ #\% #\& #\| #\! #\= #\( #\))) + (forward cl) + (make-instance (find-class ') 's (string c))) + ((member c '(#\< #\>)) + (forward cl) + ) (provide "clex") -- cgit 1.4.1-2-gfad0 From ca5768f305d4f7d152fe3f8098be28914086ca7e Mon Sep 17 00:00:00 2001 From: Darren Bane Date: Sun, 6 Dec 2020 12:52:55 +0000 Subject: Try port the Ada 16k MUD competition entry to CL --- ccap-muck.lisp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 ccap-muck.lisp diff --git a/ccap-muck.lisp b/ccap-muck.lisp new file mode 100644 index 0000000..3374606 --- /dev/null +++ b/ccap-muck.lisp @@ -0,0 +1,71 @@ +(defvar *terminate-program* nil) + +(defconstant +bold+ "[1m") +(defconstant +unbold+ "[0m") +(defconstant +q+ #\") + +(defclass () ((name :accessor name) + (playing :reader playing :initform nil) + (password :accessor password))) +(defvar *avatars* '()) + +(defvar *write-avatars* nil) + +(defclass () ((g :reader g) + (socket :reader socket) + (parser :reader parser) + (avatar :reader avatar) + (r :reader r))) +(defvar *connections* '()) + +(defconstant +port-number+ 6565) + +(defconstant +vd-type+ (vector 'n 's 'e 'w + 'u 'd)) + +(defclass () ((name :reader name) + (desc :reader desc) + (exits :reader exits))) +(defvar *rooms* '()) + +(defvar *write-rooms* nil) + +(defconstant +command-type+ (vector 'say 'help 'quit 'look + 'rooms 'make-room 'make-door 'teleport + 'n 's 'e 'w + 'u 'd 'password 'shutdown)) + +(defconstant +name-prompt+ "Please enter your character name:") + +(defconstant +rdb+ "room.tam") +(defconstant +adb+ "avatar.tam") + +(defun read-room-database () + (with-open-file (file +rdb+ :direction :input) + )) + +(defun write-room-database () + (with-open-file (file +rdb+ :direction output) + (mapcar (lambda (r) + (format file "~A~%" + +(defun read-avatar-database () + (setq *avatars* '()) + (with-open-file (file +adb+ :direction :input) + (do ((name (read-line file nil nil)) + (password (read-line file nil nil))) + ((or (null name) (null password))) + (let ((a (make-instance (find-class ')))) + (setf (name a) name) + (setf (password a) password) + (setq *avatars* (cons a *avatars*))))) + (setq *write-avatars* nil)) + +(defun write-avatar-database () + (with-open-file (file +adb+ :direction output) + (mapcar (lambda (a) (format file "~A~%~A~%" (name a) (password a))) *avatars*))) + +(read-avatar-database) +(read-room-database) +(while (not *terminate-program*) + (check-for-inputs)) -- cgit 1.4.1-2-gfad0 From 930adcd596cf28b41ee26c8ffdc98640dfc9b4bd Mon Sep 17 00:00:00 2001 From: Darren Bane Date: Thu, 10 Dec 2020 00:05:39 +0000 Subject: Making changes --- ccap-muck.lisp | 1 + doc/Makefile | 2 +- doc/breaking_rules.md | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ccap-muck.lisp b/ccap-muck.lisp index 3374606..d9de3b0 100644 --- a/ccap-muck.lisp +++ b/ccap-muck.lisp @@ -40,6 +40,7 @@ (defconstant +rdb+ "room.tam") (defconstant +adb+ "avatar.tam") +;; TODO: should I use print-object & the reader for serialisation? (defun read-room-database () (with-open-file (file +rdb+ :direction :input) )) diff --git a/doc/Makefile b/doc/Makefile index 4139f63..6e549c5 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -29,4 +29,4 @@ clean: .PHONY: push push: $(GEMINI) - scp $^ dbane@republic.circumlunar.space:/usr/home/dbane/gemini/lsp_doc + scp -6 $^ dbane@republic.circumlunar.space:/usr/home/dbane/gemini/lsp_doc diff --git a/doc/breaking_rules.md b/doc/breaking_rules.md index 29f20d1..7cfc99c 100644 --- a/doc/breaking_rules.md +++ b/doc/breaking_rules.md @@ -150,7 +150,7 @@ it may make sense to write the documentation (and contracts, and tests) "bottom- Depend only on GFM, in the same spirit as the software. The use of tools like -PP and Pandoc should be minised. +nw2md and Pandoc should be minised. PlantUML *should* be used where it can replace ad-hoc text. Documents should be stored under git in a "doc" subdirectory of the project. @@ -189,6 +189,7 @@ However, some of this documentation is better in the source code: ``` `lisp-critic` can be used to perform static analysis of the codebase. +But it's not worth writing custom rules. ### UI @@ -231,7 +232,7 @@ System tests grow in parallel with the requirements spec. It's ok for system tests to use the same interfaces as the ltk code. All tests should be automated, except possibly for the UI/view layer. -Q: These scripts could be generated from a literate test plan? A: yes, probably one of the few places to use "PP". +Q: These scripts could be generated from a literate test plan? A: yes, probably one of the few places to use nw2md. As much of the testing work should be pushed "back" in the V model to contracts for the functions, following the pattern above. -- cgit 1.4.1-2-gfad0 From f16f553f2effb7ac8120fb8a15b59bcdd480a97d Mon Sep 17 00:00:00 2001 From: Darren Bane Date: Thu, 10 Dec 2020 00:30:32 +0000 Subject: Nicer gemini output --- doc/Makefile | 5 +++-- doc/breaking_rules.md | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 6e549c5..8716885 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -6,7 +6,8 @@ GEMINI := breaking_rules.gmi bane.20.cdr15.gmi .PHONY: all -all: $(GEMINI) lkbib.txt +all: $(GEMINI) +# lkbib.txt can be made manually as needed # Write gfm. # Beyond that, YAGNI. @@ -18,7 +19,7 @@ lkbib.txt: macros.ms lkbib.ms refs.i groff -Tutf8 -R -ms -k -Kutf8 macros.ms lkbib.ms > $@ %.gmi: %.md - md2gemini -m $^ > $@ + md2gemini -m -l copy $^ > $@ refs.i: refs indxbib $^ diff --git a/doc/breaking_rules.md b/doc/breaking_rules.md index 7cfc99c..0c34594 100644 --- a/doc/breaking_rules.md +++ b/doc/breaking_rules.md @@ -55,8 +55,8 @@ without earning money. ## Design Decisions The programming language chosen is a particular style of Common Lisp. -A clean subset of CL is desired, -so cleave as [close to ISLisp](bane.20.cdr15.md) as practical[5]. +For readability my +[ISLisp-like subset of CL](bane.20.cdr15.md) should be followed where practical[5]. Reasons for this decision include: * Contrary to a lot of other languages, Lisp is fairly paradigm-agnostic. @@ -92,7 +92,7 @@ Even though this is a prototype, attention should be paid to basic craftsmanship * Use `declare` to check the types of parameters in public interfaces (see below). * Indent all the source code using Emacs. -* Some minimal documentation, at least an overview [README](https://tom.preston-werner.com/2010/08/23/readme-driven-development.html) file +* Some minimal documentation, at least an overview like in [README driven development](https://tom.preston-werner.com/2010/08/23/readme-driven-development.html) and man (actually, [mdoc](https://manpages.bsd.lv/toc.html)) pages[7]. * Certain parts of a system justify greater detail for a *complete* specification. These are (newly-designed) network protocols and complex persistent data models. @@ -204,8 +204,8 @@ For productisation you may want to add more features. Although the official ANSI standard is moribund, quasi-standard libaries are recommended on the -[awesome list](https://github.com/CodyReichert/awesome-cl), -or [portability layers](http://portability.cl/). +[Awesome-CL list](https://github.com/CodyReichert/awesome-cl), +or [CL portability layers](http://portability.cl/). Usage should be limited as follows, in order of preference. The language/library split isn't as clear in CL as in some other languages, -- cgit 1.4.1-2-gfad0