[ prog / sol / mona ]

prog


Running SchemeBBS using MIT Scheme 11.2

1 2021-10-17 01:02

MIT Scheme 11.2 was released March 2021.
https://www.gnu.org/software/mit-scheme/release.html

Maybe it's time to run SchemeBBS using MIT Scheme 11.2. MIT Scheme 11.2 is almost 100% compliant with R7RS-small.

2 2021-12-23 06:06

>>1

Maybe it's time to run SchemeBBS using MIT Scheme 11.2.

It will take years for that to happen. SchemeBBS runs on the inferior FreeBSD operating system, where MIT Scheme has not been updated in more than 7 years. On FreeBSD, MIT Scheme is still stuck at version 9.2 (released in 2014) [1], while the rest of the sane world has already upgraded to version 10.1.x (2018) or version 11.2 (2021).

I don't know why people use the inferior BSD operating systems. On NetBSD, MIT Scheme is stuck at version 7.7.1 (released in 2003!) [2]. On OpenBSD, MIT Scheme is not available at all!

[1]: https://cgit.freebsd.org/ports/tree/lang/mit-scheme/distinfo?h=release/13.0.0
[2]: https://pkgsrc.se/branch=pkgsrc-2021Q3/lang/mit-scheme-bin

3 2022-01-11 10:52 *

>>2

On NetBSD, MIT Scheme is stuck at version 7.7.1 (released in 2003!) [2]

it is real LOL

4 2022-05-26 14:07

Let's try to port SchemeBBS to MIT Scheme 11.2.

First, we need a patch to fix this error:

1 ]=> (listen server (string->number (car (command-line))))
;The object #f, passed as an argument to string-length, is not the correct type.

This is the patch:

--- bbs.scm.orig
+++ bbs.scm
@@ -414,4 +414,4 @@
                     (decode-formdata message)
                     (cdr validation)))))
 
-(listen server (string->number (car (command-line))))
+(listen server (string->number (car (command-line-arguments))))

There are no more error messages after applying the patch, but I am unable to view the webpage at localhost:8080. In Firefox, I get "The connection was reset". Does anyone know why?

5 2022-05-26 20:11

>>4

In Firefox, I get "The connection was reset"

Add debug prints, for example with format, inside the dynamic-winds of deps/server.scm:create-server:listen and see how far you get.

6 2022-05-27 00:41

..............
...';;;;'.............
.....oWMMWXk;.............
.......lKKNMMMXo'.............
...........,dNMMMd..............
..............kMMMNc..............
.............lNMMMM0'.............
............oNMMMMMWo.............
...........cNMMNOWMMXl............
..........,KMMMx,OWMMNc...........
.........,OMMMK,.,0MMM0,.........
.......;KMMMXc...:NMMMXko,.....
....'xKKKO;.....:0WMMW0,....
.................,::;,....
....................
............
textboarders this is your leader.
stay proggin' and prosper

7 2022-05-27 10:44

>>6
What does that ASCII art represent?
It looks like a dinosaurus reaching for some berries.

8 2022-05-27 14:39

>>7
It's a huge dingleberry hanging off the cusp

9 2022-05-29 14:58

>>5
Thank you. To see the errors, I had to remove one dynamic-wind:

--- a/deps/server.scm
+++ b/deps/server.scm
@@ -44,10 +44,7 @@ Initializes our web server.
         (lambda ()
           (do () ((channel-closed? socket))
             (let ((port (tcp-server-connection-accept socket #t #f)))
-              (dynamic-wind
-                (lambda () unspecific)
-                (lambda () (ignore-errors (lambda () (serve-request port))))
-                (lambda () (ignore-errors (lambda () (close-port port))))))))
+              (serve-request port))))
         (lambda () (channel-close socket)))))
 
   ;;; Private helper procedures

It turns out that the hidden error was:

;Unbound variable: guarantee-http-token-string

Apparently, many things in MIT Scheme's runtime/httpio.scm file have changed (the file has been renamed to runtime/http-io.scm). Many variables are gone, and many new ones added. So, I removed runtime/httpio.scm from SchemeBBS:

--- a/bbs.scm
+++ b/bbs.scm
@@ -11,7 +11,6 @@
 (load "lib/utils")
 (load "deps/irregex")
 (load "deps/srfi-26")
-(load "deps/httpio")
 (load "deps/server")
 (load "lib/html")
 (load "lib/parameters")
@@ -414,4 +413,4 @@
                     (decode-formdata message)
                     (cdr validation)))))
 
-(listen server (string->number (car (command-line))))
+(listen server (string->number (car (command-line-arguments))))

At this point we have another error:

;The object #[textual-i/o-port 14 for channel: #[channel 15]], passed as an argument to #[compiled-procedure 16 ("binary-port" #x2) #x1c #x2f1f6f4], is not the correct type.

This error is caused by the use of read-http-request in deps/server.scm. read-http-request expects a binary port, but it is given a textual port created by tcp-server-connection-accept. Maybe we should replace tcp-server-connection-accept with tcp-server-binary-connection-accept, which creates a binary port:

--- a/deps/server.scm
+++ b/deps/server.scm
@@ -43,11 +43,8 @@ Initializes our web server.
         (lambda () unspecific)
         (lambda ()
           (do () ((channel-closed? socket))
-            (let ((port (tcp-server-connection-accept socket #t #f)))
-              (dynamic-wind
-                (lambda () unspecific)
-                (lambda () (ignore-errors (lambda () (serve-request port))))
-                (lambda () (ignore-errors (lambda () (close-port port))))))))
+            (let ((port (tcp-server-binary-connection-accept socket #t #f)))
+              (serve-request port))))
         (lambda () (channel-close socket)))))
 
   ;;; Private helper procedures

Oops, another error:

;The object 3, passed as the second argument to vector-ref, is not in the correct range.

It turns out that we still need the modifications made to deps/httpio.scm. We can include those modifications by adding these lines to the beginning of bbs.scm using a technique similar to https://textboard.org/prog/140/88-89 :

(ge '(runtime http-i/o))

(load-option '*parser)

(define parse-request-line
  (*parser
    (seq (match (+ (char-set char-set:http-token)))
         " "
         (alt (map intern (match "*"))
              parse-uri
              parse-uri-authority)
         " "
         parse-http-version)))

(define (read-http-request port)
  (let ((line (read-ascii-line port)))
    (if (eof-object? line)
      line
      (receive (method uri version)
        (parse-line parse-request-line line "HTTP request line")
        (let ((headers (read-http-headers port)))
          (let ((b.t (or (%read-chunked-body headers port)
                         (%read-delimited-body headers port)
                         '())))
            (if (null? b.t)
              (make-http-request method uri version headers (bytevector))
              (make-http-request method uri version
                                 (append! headers (cdr b.t))
                                 (car b.t)))))))))

(ge '(user))

At this point, we get yet another error:

;Error while parsing RFC 2822 headers: Illegal character: peek-ascii-char

This error is caused by peek-ascii-char in runtime/rfc2822-headers.scm when it peeks at a carriage return character. peek-ascii-char only considers ASCII decimal 32 to 126 (inclusive) to be valid ASCII characters. So, let's try to patch it by adding this to the beginning of bbs.scm:

(ge '(runtime rfc2822-headers))

(define (peek-ascii-char port)
  (let ((byte (peek-u8 port)))
    (cond ((eof-object? byte)
           byte)
          ((and (fix:<= 0 byte) (fix:<= byte 127))
           (integer->char byte))
          (else (parse-error port "Illegal character:" 'peek-ascii-char)))))

Now, we get another error:

;The object "site root", passed as an argument to make-http-response, is not the correct type

This is easy to fix in bbs.scm:

     ;(pp (http-header 'host headers #f))
     (cond ((equal? method "GET")
 	   (match path
-	     (() () '(200 () "site root"))
+	     (() () `(200 () ,(string->utf8 "site root")))
 	     ((,board) () (view-index board))
 	     ((,board "list") () (view-list board))
 	     ((,board "preferences") () (set-preferences board query-string))

Then, we get another error:

;The object #[binary-i/o-port 35], passed as an argument to write-char, is not the correct type.

This error is raised in the string->tokens procedure in runtime/http-syntax.scm. write-char expects a textual port but we have a binary port.

I am going to take a break at this point. It seems that HTTP functionality is broken in MIT Scheme. For HTTP, some internal procedures expect a binary port while others expect a textual port.

10 2022-05-29 15:12

Addenda for >>9:
* To be clear, the errors appear after trying to access localhost:8080 through a web browser.
* The patched read-http-request procedure above differs from that in deps/httpio.scm. In deps/httpio.scm, we pass an empty string to make-http-request. Here, we pass it an empty bytevector.

11 2022-05-29 22:57

>>9 >>10
Very nicely done.

;The object #[binary-i/o-port 35], passed as an argument to write-char, is not the correct type.
This error is raised in the string->tokens procedure in runtime/http-syntax.scm. write-char expects a textual port but we have a binary port.

Are you sure about this part?
https://ftp.gnu.org/gnu/mit-scheme/stable.pkg/11.2/
Unless I'm missing something the only write-char in string->tokens uses a port created by open-output-string:

(let ((port (open-output-string)))
  (lambda (#!optional char)
    (if (default-object? char)
        (get-output-string! port)
        (write-char char port))))))

https://www.gnu.org/software/mit-scheme/documentation/stable/mit-scheme-ref/String-Ports.html#index-open_002doutput_002dstring

Returns a textual output port that will accumulate characters for retrieval by get-output-string.

Perhaps a different write-char call is involved.

12 2022-05-30 03:47

Errata for >>9:

So, I removed runtime/httpio.scm from SchemeBBS

This is supposed to be:
"So, I removed deps/httpio.scm from SchemeBBS"

13 2022-05-30 04:22

>>11

Perhaps a different write-char call is involved.

Yes, you are right. I was mistaken.
The error is raised in the write-http-response procedure in runtime/http-io.scm. The error is caused by the use of newline to write to a binary port. newline can only write to a textual port.

Fix:

--- src/runtime/http-io.scm.orig
+++ src/runtime/http-io.scm
@@ -188,7 +188,8 @@
 	(write-ascii (write-to-string (http-response-status response)) port)
 	(write-u8 (char->integer #\space) port)
 	(write-ascii (http-response-reason response) port)
-	(newline port)
+	(write-u8 (char->integer #\return) port)
+	(write-u8 (char->integer #\newline) port)
 	(write-http-headers (http-response-headers response) port)))
   (write-bytevector (http-response-body response) port)
   (flush-output-port port))
14 2022-05-30 04:50

>>13
Add that fix to the beginning of bbs.scm:

(ge '(runtime http-i/o))

(define (write-http-response response port)
  (if (http-response-version response)
    (begin
      (write-http-version (http-response-version response) port)
      (write-u8 (char->integer #\space) port)
      (write-ascii (write-to-string (http-response-status response)) port)
      (write-u8 (char->integer #\space) port)
      (write-ascii (http-response-reason response) port)
      (write-u8 (char->integer #\return) port)
      (write-u8 (char->integer #\newline) port)
      (write-http-headers (http-response-headers response) port)))
  (write-bytevector (http-response-body response) port)
  (flush-output-port port))

(ge '(user))

At this point, localhost:8080 should successfully display "site root"!

One more thing: I should have closed the port after serving each request.

--- a/deps/server.scm
+++ b/deps/server.scm
@@ -43,11 +43,9 @@ Initializes our web server.
         (lambda () unspecific)
         (lambda ()
           (do () ((channel-closed? socket))
-            (let ((port (tcp-server-connection-accept socket #t #f)))
-              (dynamic-wind
-                (lambda () unspecific)
-                (lambda () (ignore-errors (lambda () (serve-request port))))
-                (lambda () (ignore-errors (lambda () (close-port port))))))))
+            (let ((port (tcp-server-binary-connection-accept socket #t #f)))
+              (serve-request port)
+              (close-port port))))  ;; <- CLOSE PORT!
         (lambda () (channel-close socket)))))

Now that we have successfully displayed the site root, it's time to fix the board indexes, board lists, new thread creation, etc.

15 2022-05-30 06:15

Now, let's try to fix board indexes, board lists, and new thread creation.
All HTTP bodies are now represented using bytevectors, not strings. Fix:

--- a/deps/server.scm
+++ b/deps/server.scm
@@ -287,10 +285,10 @@ Initializes our web server.
 
 ;;; reads the string content at the given file path:
 (define (read-file filename)
-  (call-with-input-file filename
-                        (lambda (port)
-                          (read-string (char-set) port))))
-
+  (string->utf8
+    (call-with-input-file filename
+                          (lambda (port)
+                            (read-string (char-set) port)))))

(alternative fix: open file using open-binary-input-file, read file using call-with-port and read-bytevector)

and also:

--- a/bbs.scm
+++ b/bbs.scm
@@ -79,7 +79,7 @@
     ;(pp (http-header 'host headers #f))
     (cond ((equal? method "GET")
 	   (match path
-	     (() () '(200 () "site root"))
+	     (() () `(200 () ,(string->utf8 "site root")))
 	     ((,board) () (view-index board))
 	     ((,board "list") () (view-list board))
 	     ((,board "preferences") () (set-preferences board query-string))
@@ -102,11 +102,11 @@
 
 ;;; errors
 (define bad-request
-  `(400 () "Bad Request"))
+  `(400 () ,(string->utf8 "Bad Request")))
 (define not-found
-  `(404 () "Not found"))
+  `(404 () ,(string->utf8 "Not found")))
 (define method-not-allowed
-  '(405 () "Method not allowed"))
+  `(405 () ,(string->utf8 "Method not allowed")))
 
 (define (title board)
   (string-append "/" board "/ - SchemeBBS"))
@@ -215,7 +215,7 @@
            (let* ((t (call-with-input-file path read))
                   (posts (lookup-def 'posts t))
                   (post-number (+ 1 (car (last posts))))
-                  (body (http-request-body req))
+                  (body (utf8->string (http-request-body req)))
                   (params (parameters->alist body))
                   (frontpage (lookup-def 'frontpage params))
                   (message (decode-formdata (lookup-def 'epistula params)))
@@ -252,11 +252,11 @@
 		    (if newthread?
 			(add-query-string (string-append "/" board) query-string)
 			(string-append (add-query-string (string-append "/" board) query-string) "#t" thread "p" post))))
-	    "That was SICP quality!")
+	    ,(string->utf8 "That was SICP quality!"))
       `(303 ,(list (make-http-header
 		    'location
 		    (string-append  (add-query-string (string-append  "/" board "/" thread) query-string) "#t" thread "p" post)))
-	    "That was SICP quality")))
+	    ,(string->utf8 "That was SICP quality"))))
 
 (define (update-post-count board thread date post-count)
   (let ((cache (make-path *html* board "list")))
@@ -316,7 +316,7 @@
                 (threads (if (file-exists? list-path)
                              (call-with-input-file list-path read)
                              '()))
-                (body (http-request-body req))
+                (body (utf8->string (http-request-body req)))
                 (params (parameters->alist body))
                 (message (decode-formdata (lookup-def 'epistula params)))
                 (headline (decode-formdata (lookup-def 'titulus params)))

Then, to make redirections work correctly when creating new threads and messages, we need to add this fix to the beginning of bbs.scm: https://textboard.org/prog/140/88

SchemeBBS now works on MIT Scheme 11.2!

There's one problem left: multi-byte characters. If you try to submit "一二三" through the textarea, you will get something like "一二三". Not sure how to fix this.

16 2022-05-30 09:28

>>15

There's one problem left: multi-byte characters.

My guess: multi-byte characters are encoded using ISO 8859-1 in data/sexp/... but other parts of the code are assuming that the data is encoded using UTF-8.

17 2022-05-30 09:31

>>16
The string->iso8859-1 procedure might be useful here.

18 2022-05-30 13:40

>>15
This is a wasteful double conversion back to the source bytes that throws away the intermediate result. It also uses the deprecated form of read-string.

(string->utf8
    (call-with-input-file filename
                          (lambda (port)
                            (read-string (char-set) port)))))

https://www.gnu.org/software/mit-scheme/documentation/stable/mit-scheme-ref/Input-Procedures.html#index-read_002dstring

Note: MIT/GNU Scheme previously defined this procedure differently, and this alternate usage is deprecated; please use read-delimited-string instead. For now, read-string will redirect to read-delimited-string as needed, but this redirection will be eliminated in a future release.

(alternative fix: open file using open-binary-input-file, read file using call-with-port and read-bytevector)

You can use call-with-binary-input-file directly:

(define (read-file filename)
  (let ((size (file-length filename)))
    (if (zero? size)
        (make-bytevector 0)
        (call-with-binary-input-file
          filename
          (lambda (port)
            (read-bytevector size port))))))

SchemeBBS now works on MIT Scheme 11.2!

Conga rats.

There's one problem left: multi-byte characters. If you try to submit "一二三" through the textarea, you will get something like "一二三". Not sure how to fix this.

See whether https://textboard.org/prog/39#t39p263 still applies. If it doesn't, provide the hex bytes of a garbled post body and the corresponding original text from the textarea.

19 2022-05-30 15:30

The problems encountered in this thread show why MIT Scheme will only be used for academic toy programs. Better to use GNU Guile for practical tasks. Advantages of GNU Guile over MIT Scheme:

* Reported problems will be fixed
* Code base is covered by more unit tests
* Up to date and comprehensive documentation
* Large and active community (non-deserted mailing list and IRC channel with 100+ users)
* Relied on by practical programs such as GnuCash, Guix, LilyPond, GNU Artanis, etc.

20 2022-05-31 02:35

>>18
In your implementation of read-file, shouldn't there be at least two calls to read-bytevector, with the last call checking that it is an end-of-file object? If the file size changes between file-length and call-with-binary-input-file, we might get the wrong data. I think this is an example of a "time-of-check to time-of-use" bug.

21 2022-05-31 10:28

>>20
The file could also be shrunk, renamed, unlinked, edited in the same size, have its NFS mount connection go down, or have any number of other things happen to it. In the absence of a function provided by MIT Scheme that doesn't require a size and reads the entire file, whatever its size happens to be, I felt that chasing all these race conditions was pointless, because the proper solution would be for MIT Scheme to provide that function. If it already does, I missed it. You are, however, entitled to feel differently and provide a more robust function that loops on reading chunks into a growing buffer until EOF, as the race condition you pointed out is certainly a real one.

22 2022-05-31 22:54

To address anon's >>20 valid concerns:

(define (read-file filename)
  (let* ((chunksize   65536)
         (chunkbuffer (make-bytevector chunksize)))
    (call-with-binary-input-file
      filename
      (lambda (inport)
        (call-with-output-bytevector
          (lambda (outport)
            (let loop ()
              (let ((available (read-bytevector! chunkbuffer inport)))
                (when (not (eof-object? available))
                  (let ((written (write-bytevector chunkbuffer outport 0 available)))
                    (if (= written available)
                        (loop)
                        (error "out of memory in read-file" filename))))))))))))
23 2022-06-18 10:23

>>2

You are talking as if there is no fine OS for servers aside from *BSD crap.

Repository : aur
Name : mit-scheme
Keywords : None
Version : 11.2-4
Description : MIT/GNU Scheme
URL : https://www.gnu.org/software/mit-scheme/
AUR URL : https://aur.archlinux.org/packages/mit-scheme

Only reason textboard.org uses FreeBSD is just because its admin wants to be a unique snowflake.

24 2022-06-18 14:33 *

>>23

You are talking as if there is no fine OS for servers aside from *BSD crap.

So, you are suggesting using Arch (or a derivative) for a server... FreeBSD is much better choice (and so is Debian).

25 2022-06-18 16:30

>>24

So, you are suggesting using Arch (or a derivative) for a server

Nope, Debian/Ubuntu would work. https://packages.debian.org/bookworm/mit-scheme

But admin decided that his representation as a unique snowflake is more important than stable and appropriate server stack.

26 2022-06-18 16:31

One more thing is FreeBSD uses fucking cuck license. GNU/Linux doesn't have such flaw.

27 2022-06-18 17:41

Yesterday I got MIT Scheme 11.2 up and running nicely on OpenBSD. Follow the configure and what's in the patches (except for in confshared.h, they fixed that) and comment out line 1197 in src/microcode/uxsig.c.
https://www.mail-archive.com/mit-scheme-devel@gnu.org/msg01655.html

28 2022-06-18 18:09

>>27

Nice, why just don't use a normal server GNU/Linux distro and run one command to install a package?

29 2022-06-19 01:21 *

Because, >>28, you touch yourself at night.

30 2022-06-19 01:58

>>27
Why don't you add that to the OpenBSD ports tree?
The OpenBSD ports tree needs more Scheme implementations. There are only four at the moment: Chibi Scheme, Microscheme, Scheme 48, and TinyScheme.
https://openports.se/search.php?stype=folder&so=scheme

31 2022-06-19 03:36 *

>>26
License is fine, but the CoC is pozzed.

32 2022-06-19 04:55

>>30
Well, actually it has guile, gambit, gerbil, racket, and chicken too. It would be nice to see a BSD with an actual up-to-date MIT Scheme as a port, but I'm doubtful the demand for it would really be high enough, plus all the responsibility that comes with maintaining one will be someone else's.
It's easy enough to patch up and build yourself, if you really want it.

33 2022-06-19 08:28 *

>>29

Actually it was night in my country when you were posting. (01:21 AM)

34 2022-06-20 08:06 *

>>31

Nothing fine with cuck license.

https://wiki.installgentoo.com/wiki/Cuck_license

35 2022-09-09 12:04 *

>>2

It will take years for that to happen.

If only people took as much time debugging SchemeBBS than writing good LISP software ;_;

36 2022-09-13 09:57

>>4,9,10,12,13,14,15

Some of the bugs have been fixed in the master branch of MIT Scheme within the last two weeks. The next release of MIT Scheme would hopefully require less patches to run SchemeBBS.

37 2023-06-26 15:44

MIT Scheme 12.1 was released in January 2023.
Are there plans to update SchemeBBS to run on MIT Scheme 12.1?
It appears that most of the HTTP bugs from version 11.2 have been fixed in version 12.1.

38 2023-07-05 01:00 *

It should be, honestly. We are progressives, no?

39 2023-08-29 03:34

If it was running on 11.2 it should be running on 12.1 too.

40 2023-09-16 13:12

Status?

41 2023-10-17 08:15

Dead

42 2023-10-18 17:37

>>19
Guile was considered broken, half-baked abandonware for years and years, so it's been kind of wild to see it manage any degree of resurgence. But is it ready to host a website on the internet?

43 2023-10-18 17:42

>>42
https://4taba.net/ (our sister site) runs on Guile.

44 2023-10-18 18:40

>>43
Sick! So we can cocoa our own moai (so to speak) and call it a day?

45 2023-10-18 18:56

>>2

On NetBSD, MIT Scheme is stuck at version 7.7.1 (released in 2003!)

That was the last release before it was renamed to MIT/GNU Scheme and the license was changed from permissive to copyleft. I was not aware of this until today.

46 2023-12-24 06:24

>>43
Fantastic. 4taba is very nice! \(★ω★)/

47 2023-12-26 23:19

>>45
Oh, I see.

48 2023-12-28 11:10

>>6
Redeem your lambda sirs

01010001
10100000
00010101
10000000
00011110
00010111
11100111
10000101
11001111
000000111
10000101101
1011100111110
000111110000101
11101001 11010010
11001110 00011011
00001011 11100001
11110000 11100110
11110111 11001111
01110110 00011001
00011010 00011010

49 2023-12-28 11:11 *

>>48
Shit, it's ogre.

50 2023-12-29 20:50

>>46
4taba is back! (๑˃ᴗ˂)ﻭ
☆*・゜゚・(^O^)/・゜゚・*☆

51 2024-01-03 01:07

>>43
where's the source code?
this? https://github.com/ECHibiki/Kotatsu-V/

52 2024-01-03 11:02

I do believe that's the version that is running on the site.

53 2024-01-03 16:48

>>43,51

Hackable and easy to deploy imageboard software written in Guile.

Go home and be a family man. (ง •̀ω•́)ง✧

54 2024-01-04 23:23

>>51
It looks like it.

55 2024-01-05 14:49

>>53
When in doubt, Sonic Boom!
(っ ‘o’)ノ---===≡≡≡ 卍

56


VIP:

do not edit these