Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

destructuring binding at lambda formal #183

Closed
nyuichi opened this issue Aug 4, 2014 · 6 comments
Closed

destructuring binding at lambda formal #183

nyuichi opened this issue Aug 4, 2014 · 6 comments

Comments

@nyuichi
Copy link
Member

nyuichi commented Aug 4, 2014

(define f (lambda ((a . b)) (+ a b)))

(f (cons 1 2)) ;=> 3

; because let expands to a lambda form, you will be able to do destructuring bind in let forms.
(let (((a . b) (cons 1 2)))
  (+ a b))
@KeenS
Copy link
Member

KeenS commented Aug 6, 2014

FYI there is a pattern matching library https://github.com/SaitoAtsushi/pattern-match-lambda.
I tried to run test with picrin but an error prevented me.

@nyuichi
Copy link
Member Author

nyuichi commented Aug 6, 2014

@KeenS

What kind of error did you get?

@KeenS
Copy link
Member

KeenS commented Aug 6, 2014

@wasabiz below.
macroexpand error while application: macroexpand error while definition: macroexpand error while application: pair required

The cause is this code.

  (define-syntax %if-match-vector
    (syntax-rules ()
      ((_ (literals ...) #() ind e seq alt) seq)
      ((_ (literals ...) #(p r ...) ind e seq alt)
       (%if-match (literals ...) p (vector-ref e ind)
                  (let ((i ind))
                    (%if-match-vector (literals ...) #(r ...) (+ i 1) e seq alt))
                  alt))))

Detailed (debug) log is too long to paste even onto gist.

@zeptometer
Copy link
Contributor

@KeenS This error seems caused when expanding rules including vector. And I think this bug is fixed by #186. Can you test with this fix? (I made branch 'fix-syntax-rules' at this repository)

@KeenS
Copy link
Member

KeenS commented Aug 6, 2014

@zeptometer It seems not to be fixed. I got this error
macroexpand error while application: pic_get_args: expected vector, but got (0).
The cause is

(define fact
  (pattern-match-lambda ()
                        ((0) 1)
                        ((n) (* n (fact (- n 1))))))

Too specialized to vector?

@nyuichi
Copy link
Member Author

nyuichi commented Sep 9, 2014

In (picrin experimental lambda) library, there exists what this issue proposed.

@nyuichi nyuichi closed this as completed Jun 19, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants