matchを使いたかったのですが、以下のようなエラーが出てしまい、実行できませんでした。
1 2 3 4 5 | *** ERROR: proper list required for function application or macro use: (attr value . rest) While compiling "/private/tmp/test.scm" at line 46: (define (make-player . args) (define (loop lis) (match lis (() '()) ((attr value . rest) (cons (cons ... While loading "/private/tmp/test.scm" at line 51 Stack Trace: |
問題のコードは以下の通りです。
プログラミングGaucheのサンプルなのですが、matchを使っているところでエラーになりました。
(define (make-player . args) (define ( loop lis) (match lis [() '()] [(attr value . rest) (cons (cons attr value) ( loop rest))])) ( loop args)) |
さっぱりですな。
ググってもよくわかりませんが、どうやらmatchを使うための事前準備が必要なようです。
(use util.match)を書いたらエラーになりませんでした。
1 2 3 4 5 6 7 8 9 10 | (use util.match) (define (make-player . args) (define ( loop lis) (match lis [() '()] [(attr value . rest) (cons (cons attr value) ( loop rest))])) ( loop args)) (make-player 'hp 320 'mp 66 'position #f 'inventory '(potion potion dagger cookie dagger)) |
初めての言語は勘所を掴むまでは、簡単な事でハマってしまいます。
0 件のコメント :
コメントを投稿