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

Deprecate "cry" in for loops #64

Open
jarcane opened this issue Jan 5, 2022 · 0 comments
Open

Deprecate "cry" in for loops #64

jarcane opened this issue Jan 5, 2022 · 0 comments

Comments

@jarcane
Copy link
Owner

jarcane commented Jan 5, 2022

It is possible to allow the user to bind their own name to the for loop's inner variable, and the code to do so is actually simpler than the current, more limited implementation.

A basic simplification is demonstrated as follows:

#lang racket

(require racket/stxparam)

(define-syntax-parameter break
  (lambda (stx)
    (raise-syntax-error "oops")))

(define-syntax-parameter carry
  (lambda (stx)
    (raise-syntax-error "oops")))

(define-syntax-rule (for-with (name val) (var lst) body ...)
  (let/ec break-k
    (syntax-parameterize
        ((break (syntax-rules ()
                  [(_ ret) (break-k ret)]
                  [(_) (break-k)])))
      (let loop ((name val)
                 (l lst))
        (cond [(null? l) name]
              [else (let ([var (car l)])
                      (loop
                       (call/ec
                        (lambda (k)
                          (syntax-parameterize
                              ([carry (make-rename-transformer #'k)])
                            body ...)
                          name))
                       (cdr l)))])))))

(for-with (i 0)
          (x '(1 2 3 4 5))
  (if (> i 8)
      (break i)
      (carry (+ i x))))

This also possibly could allow for the user to define multiple local values, since we're no longer doing any weird rebind tricks for their names. This would need more experimenting though, and might require multiple return to make sense, something Heresy doesn't support (and I'm not sure I'd want it to).

@jarcane jarcane modified the milestone: 0.5.0 Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant