Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nils M Holm code #34

Open
jcubic opened this issue Aug 8, 2021 · 14 comments
Open

Nils M Holm code #34

jcubic opened this issue Aug 8, 2021 · 14 comments

Comments

@jcubic
Copy link
Contributor

jcubic commented Aug 8, 2021

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.

@lassik
Copy link
Member

lassik commented Aug 8, 2021

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.

@lassik
Copy link
Member

lassik commented Aug 8, 2021

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.

@jcubic
Copy link
Contributor Author

jcubic commented Aug 8, 2021

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:

http://t3x.org/s9fes/amb.scm.html

@jcubic
Copy link
Contributor Author

jcubic commented Aug 8, 2021

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.

@jcubic jcubic mentioned this issue Aug 8, 2021
@lassik
Copy link
Member

lassik commented Aug 8, 2021

amb is a Lisp classic, it would be great to have it in the cookbook.

@jcubic
Copy link
Contributor Author

jcubic commented Aug 8, 2021

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.

@lassik
Copy link
Member

lassik commented Aug 9, 2021

The old book Teach Yourself Scheme in Fixnum Days explains and implements amb, but it's also using define-macro.

@lassik
Copy link
Member

lassik commented Aug 9, 2021

If you can rewrite it using syntax-rules, that would be great!

@jcubic
Copy link
Contributor Author

jcubic commented Aug 9, 2021

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)

@jcubic
Copy link
Contributor Author

jcubic commented Aug 9, 2021

But it seems both works in Guile.

@jcubic jcubic mentioned this issue Aug 9, 2021
Merged
@lassik
Copy link
Member

lassik commented Aug 9, 2021

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)

@lassik
Copy link
Member

lassik commented Aug 9, 2021

(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.)

@sjamaan
Copy link

sjamaan commented Aug 10, 2021

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.

@lassik
Copy link
Member

lassik commented Aug 11, 2021

From Nils:

Regarding the recipes for the cookbook: maybe this page is helpful:

http://t3x.org/s9fes/CATEGORIES.html

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

No branches or pull requests

3 participants