Open jcubic opened 2 years ago
Great. Does he have a specific wish for what we should do with the code? Some of those files are quite big and require non-standard libraries, (load-from-library "foo.scm")
. It would be a non-trivial amount of work to pick the procedures that would be a good fit for a cookbook format, and refactor them to use SRFIs where possible.
We should also go over the Schematics cookbook for the same purpose. The only question is who does all the work :)
Maybe we could split the work so each of us could try to send PRs for a few procedures per week. It would be a great help if Nils could prepare some of the code, or at least pick which files would be good for the cookbook.
I'm looking at the code, there are some small examples, we can use those:
http://t3x.org/s9fes/adjoin.scm.html http://t3x.org/s9fes/collect.scm.html
I would leave the big ones maybe except for the amb operator:
But there is problematic define-syntax
the code uses Lisp-like macros. Because the code is for Scheme implementation from scratch.
Will check only small functions and create a PR with those files.
amb
is a Lisp classic, it would be great to have it in the cookbook.
Maybe we can find it elsewhere or reimplement it with syntax-rules
. I can try to write a scheme macro based on Nils's code.
The old book Teach Yourself Scheme in Fixnum Days explains and implements amb
, but it's also using define-macro
.
If you can rewrite it using syntax-rules
, that would be great!
It seems that Chicken Scheme doesn't support any way of nesting ellipsis in syntax-rules
.
I've tested this: Both works in my Scheme implementation, the code is from my unit tests:
(define-syntax funcall
(syntax-rules ::: ()
((_ name args :::) (name args :::))))
(display (funcall list 1 2 3))
(newline)
(define-syntax be-like-begin
(syntax-rules ()
((be-like-begin name)
(define-syntax name
(syntax-rules ()
((name expr (... ...))
(begin expr (... ...))))))))
(be-like-begin sequence)
(display (sequence 1 2 3 4))
(newline)
But it seems both works in Guile.
These work in Chibi-Scheme, Chicken, Gauche, Kawa, Sagittarius:
(define-syntax funcall
(syntax-rules ellipsis ()
((_ name args ellipsis) (name args ellipsis))))
(display (funcall list 1 2 3))
(newline)
(define-syntax be-like-begin
(syntax-rules ()
((be-like-begin name)
(define-syntax name
(syntax-rules ellipsis ()
((name expr ellipsis)
(begin expr ellipsis)))))))
(be-like-begin sequence)
(display (sequence 1 2 3 4))
(newline)
(syntax-rules ::: ()
doesn't work in Chicken because Chicken reads anything starting with :
as a keyword, not a symbol. (About 10 Scheme implementations have keywords similar to Clojure, Common Lisp, and Emacs Lisp, though keywords are not part of the Scheme standards.)
Alternatively you could use |:::|
to force the reader to see it as a symbol identifier, but that looks a bit ugly. It should be portable to all R7RS-compliant Schemes though.
From Nils:
Regarding the recipes for the cookbook: maybe this page is helpful:
Just got a message from Nils M Holm. He did few books about Scheme and pointed to:
http://t3x.org/s9fes/lib.html and http://t3x.org/s9fes/contrib.html
the code is from the book "Scheme 9 from Empty Space" all examples are in the public domain.