Giter Club home page Giter Club logo

generic-bind's People

Contributors

alexknauth avatar jackfirth avatar rmculpepper avatar stchang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

generic-bind's Issues

yield inside ~for reports an arity mismatch

The following example illustrates the problem:

#lang racket

(require racket/generator generic-bind)

(define (gen1 seq)
  (in-generator
   (let ([refs (make-hash)])
     (for ([seq-item seq])
       (match-let ([(cons a b) seq-item])
         (hash-set! refs a b)
         (yield a))))))

(displayln (sequence->list (gen1 (list (cons 'a 'b) (cons 'c 'd)))))

(define (gen2 seq)
  (in-generator
   (let ([refs (make-hash)])
     (~for ([($: a b) seq])
       (hash-set! refs a b)
       (yield a)))))

(displayln (sequence->list (gen2 (list (cons 'a 'b) (cons 'c 'd)))))

Output (with errortrace enabled):

(a c)
result arity mismatch;
 expected number of values not received
  expected: 1
  received: 0
  values...:
  errortrace...:
   /Users/hinsen/projects/racket/gbind.rkt:18:7: (yield a)
   /Users/hinsen/projects/racket/gbind.rkt:15:3: (let-values (((refs) (make-hash))) (let-values (((temp14) (let-values (....) ....))) (void temp14)))
   /Users/hinsen/projects/racket/gbind.rkt:23:11: (sequence->list (gen2 (list (cons (quote a) (quote ....)) (cons (quote ....) (....)))))
   /Users/hinsen/projects/racket/gbind.rkt:23:0: (displayln (sequence->list (gen2 (list (cons (....) ....) (cons ....)))))
   /Users/hinsen/projects/racket/gbind.rkt:23:0: (call-with-values (lambda () (displayln (sequence->list (gen2 ....)))) print-values)
  context...:
   g18
   generator
   /Users/hinsen/Applications/Racket/collects/racket/generator.rkt:93:4: cont

My Racket installation (including generic-bind) was up to date yesterday evening.

Request: `~for/foldr`

Given the other ones, I was surprised that ~for/foldr isn't implemented. I'd like that, if you have the time.

#:final in ~for/X doesnt match racket's for/X

:final will execute one more iteration of the current sequence, rather than one more iteration total

(~for/list ([i 4] #:final (= i 2) [j 2]) (list i j))
=> '((0 0) (0 1) (1 0) (1 1) (2 0) (2 1))
(for/list ([i 4] #:final (= i 2) [j 2]) (list i j))
=> '((0 0) (0 1) (1 0) (1 1) (2 0))

Support for partially applied functions

Currently partially applied functions can't be defined with generic binding instances. For example, the following code gives a syntax error:

(~struct pos (x y))

(~define ((pos+ ($pos x1 y1)) ($pos x2 y2))
  (pos (+ x1 x2) (+ y1 y2)))

The error claims x1 and y1 are unbound. However, partially applied functions can still be defined if you only use the generic binding patterns in the outermost arguments that aren't used for partial application:

(~define ((pos+ x1 y1) ($pos x2 y2))
  (pos (+ x1 x2) (+ y1 y2)))

Would it be difficult to implement full support for partially applied functions?

warning when installing and links don't work for docs

When I updated it I noticed these warnings:
raco setup: --- building documentation ---
raco setup: 1 running: /generic-bind/generic-bind/generic-bind.scrbl
raco setup: WARNING: undefined tag in /generic-bind/generic-bind/generic-bind.scrbl:
raco setup: ((lib "generic-bind/main.rkt") $)
raco setup: ((lib "generic-bind/main.rkt") $:)
raco setup: ((lib "generic-bind/main.rkt") $list)
...
raco setup: ((lib "generic-bind/main.rkt") ⋈)

And then I noticed that if I search the racket documentation and click on the docs for generic-bind, it's rendered in the new style, but the links don't work, and they're underlined in red.

Scoping borked

In the following code, the ~for_/fold use I would expect to have the same behavior as the for_/fold use. It instead lets unsafe-undefined escape.

lang racket

(require generic-bind)
(struct Foo (x))
;; Good
(let ([c Foo])
(for_/fold ([out (set)])
([mumble (in-set (set (Foo 'hrmm)))])
(match mumble
[(and (Foo x) (app (λ _ c) c))
(set-add out (c x))])))
;; bad
(let ([c Foo])
(~for_/fold ([out (set)])
([($ (and (Foo x) (app (λ _ c) c)))
(in-set (set (Foo 'grumble)))])
(set-add out (c x))))

Support for partially applied functions

Currently defining functions with generic binding instances does not support partially applied functions. For example, the following code gives a syntax error:

(~struct pos (x y))

(~define ((pos+ ($pos x1 y1)) ($pos x2 y2))
  (pos (+ x1 x2)
       (+ y1 y2)))

The error claims x1 and y1 are unbound. Would this be exceptionally difficult to implement?

support gen-bind in function rest arg

I was thinking of something like this, which doesn't work anyway: (but it might be nice if it did)

lang racket

(require generic-bind)
(define-match-bind list-no-order)
(~define (proc-rename . ($list-no-order (? procedure? proc) (? symbol? sym)))
(procedure-rename proc sym))

See pr #17

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.