Skip to content

Conversation

@BenedictHW
Copy link

Good Day,

I'm currently a beginner trying get started with Lisp. I've already invested
hours setting up my ideal Emacs & Common Lisp environment with the copious free
time only a student has. Therefore I began searching for a way to learn SICP
through the Common Lisp environment. It was then Mr. Joswig on HN who pointed me
towards pseudoscheme (https://news.ycombinator.com/item?id=16776704).

I decided to mark this Pull Request as a draft because I'm not entirely clear
why removing '#' from the Non-constituents allows the readtable to be
successfully set, and why this only occurs on SBCL. This is out of the two
implementations I tested, the other being CCL. But seeing resources online as sparse
as it is, I wanted to save future beginners some trouble by making this WIP PR public.

Loading pseudoscheme on SBCL v2.1.9 now does seem to work though. I ran some
scheme examples I found online and pasted the results in the description of commit
fba7323. I've also read online that it is most painless to use the version of
scheme (R5RS?) in the textbook and not modern MIT Scheme or Racket (which can
work with a compatibility module). So pseudoscheme seems to fit the bill
perfectly. In fact I think some historical value would be lost if all the
conditionals for ancient implementations were replaced. I think it's pretty cool
code that is 16 years older than me remains a vehicle to learn the timeless
concepts in SICP.

But now I've spent more time fooling around with the tooling instead of the
material so I'll leave it at that.

Cheers, and thanks for pseudoscheme!

My Emacs is configured to automatically delete trailing whitespaces.
Source file extensions and compiled file extensions have changed for CCL.

CL-USER> (pathname-type (compile-file-pathname "clever.lisp"))
"lx64fsl"
CL-USER> (pathname-type "clever.lisp")
"lisp"

I think all the all caps ".LISP" is no longer the preferred style? N.B. the
compiled file extension is prefixed with "lx64-" appropriately reflects my CPU
architecture.
Add new Source file extensions and compiled file extensions for SBCL.

CL-USER> (pathname-type (compile-file-pathname "clever.lisp"))
"fasl"
CL-USER> (pathname-type "clever.lisp")
"lisp"
This failure to successfully evaluate

(setq *readtable* ps::roadblock-readtable)

only occurs on SBCL (where the error is quoted in the commit title) and not CCL.
I don't understand why. Perhaps we need to first call
SET-DISPATCH-MACRO-CHARACTER for '#'. However the removal of '#' from the
Non-constituents does allow the above sexp to eval properly. Version of SBCL
used is 2.1.9.

CL-USER> (setq *readtable* ps::roadblock-readtable)
 #<READTABLE {10018F4573}>
CL-USER> (in-package :scheme)
 #<COMMON-LISP:PACKAGE "SCHEME">
SCHEME> (cons "banana" "split")
("banana" . "split")
SCHEME> (list (list 1 2 3) 5 (list "a" "b" "c"))
((1 2 3) 5 ("a" "b" "c"))
SCHEME> (symbol? 'Apple)
COMMON-LISP:T
SCHEME> (symbol? 10)
PS:FALSE
SCHEME> (define (make-stack)
                 (let ((s '()))
                   (define (push x)
                     (set! s (cons x s)))
                   (define (pop)
                     (if (null? s)
                         (error "Empty stack -- POP")
                       (let ((top (car s)))
                         (set! s (cdr s))
                         top)))
                   (define (initialize)
                     (set! s '())
                     'done)
                   (define (dispatch message)
                     (cond ((eq? message 'push) push)
                           ((eq? message 'pop) (pop))
                           ((eq? message 'initialize) (initialize))
                           (else (error "Unknown request -- STACK"
                                        message))))
                   dispatch))
;
; caught COMMON-LISP:STYLE-WARNING:
;   Call to PS:TRUEP could not be inlined because its source code was not saved. A
;   global INLINE or SB-EXT:MAYBE-INLINE proclamation must be in effect to save
;   function definitions for inlining.
;
; compilation unit finished
;   caught 1 STYLE-WARNING condition
MAKE-STACK defined.
SCHEME> (let ((s (make-stack)))
                 ((s 'push) 1)
                 ((s 'push) 2)
                 (s 'pop)
                 (s 'pop))
1 (1 bit, #x1, #o1, #b1)
@jar398
Copy link
Owner

jar398 commented Oct 28, 2021

So if I just type #t at a Common Lisp reader with the *roadblock-readtable* in effect, under your change, does that turn into the pseudoscheme true value? and similarly with other # syntaxes in scheme?

If so then I guess your fix is OK. If not it needs to be conditional on SBCL.

You probably know already that # is not a constituent character, but merely non-terminating (which is a sort of semi-constitutent status). (hyperspec) But for roadblock purposes the only thing that matters is its status as the first character of something, so making it a constituent with respect to the roadblock sounds wrong to me.

I am puzzled by the CCL changes - we're talking about Coral Common Lisp, right? Maybe CCL itself changed over the years. I never used it and must have gotten those conditionalizations from a contributor. Of course ideally all this knowledge of file extensions shouldn't reside inside Pseudoscheme itself. The underlying Lisp system obviously knows all of this and I'd expect there to be a way to query it in a modern Common Lisp. In retrospect the derived files should be foo-pso.lisp not foo.pso but remember - the file system I was using only supported 6 character file names.

Yes, this is very old code- I think mainly written around 1985, for the Symbolics Lisp Machine (which had only just implemented Common Lisp, which came out in 1984). It was never revised for ANSI Common Lisp or for ABCL. It's miraculous that it still works.

I believe the dialect implemented is R4RS, not R5RS.

Thanks for teaching me about 'draft' status PRs!

@BenedictHW
Copy link
Author

BenedictHW commented Oct 28, 2021

Typing just #t at the Common Lisp reader with *roadblock-readtable*
does work with CCL but not SBCL. The hyperspec seems mighty helpful. Yeah, I
need to find a SBCL specific way to set the dispatch reader macro for '#'.
Fudging about with reader macros is a bit out of my depth, so I'll shelve that
thought for now and just work with CCL.

With reference to CCL, and I just learned this myself yesterday, it went roughly
from

1984 - Coral Common Lisp

1988 - Macintosh Common Lisp (acquired by Apple)

2001 - OpenMCL (open sourced bits of MCL)

2007 - Clozure Common Lisp (after the entire MCL was open sourced, renamed to
avoid confusion. We've come full circle!)

https://ccl.clozure.com/history.html

6 character file names? That's crazy lol. I am hoping the 'sicp.scm' included file will
paper over any difference between R4RS and R5RS for my use case.

I'm pretty stubborn about getting this to work on SBCL as it happens to be the
most active CL implementation in the year of our Lord 2021. If I ever persevere
through the exercises, it will be my first priority to repay my debt of
gratitude by 'modernizing' pseudoscheme. All the best,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants