[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?
From: |
Joshua Branson |
Subject: |
bug#46014: (define (thunk) (lambda (x) x)) should be a compile error? |
Date: |
Wed, 20 Jan 2021 21:04:47 -0500 |
Hello!
Consider this bit of simple code:
#+BEGIN_SRC scheme
(define (thunk)
(lambda (x)
x))
(thunk) ;; works ok, I guess.
(thunk "hello world!\n") ;; runtime error
;;; <stdin>:1074:0: warning: possibly wrong number of arguments to `thunk'
ice-9/boot-9.scm:1669:16: In procedure raise-exception:
Wrong number of arguments to #<procedure thunk ()>
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
#+END_SRC
Guile will compile this program seemingly with no error. Guile will
correctly report at runtime that procedure '(thunk "hello world!\n")'
takes no arguments, but it's lambda accepts 1 argument. Would it be
possible to report this error at compile time? Would that be
advantageous?
I personally can consider one time where reporting this error at
compile time would be advantageous. Here's how I found out about this
error. (would ya'll call this an error/bug/feature)?
#+BEGIN_SRC scheme
(use-modules
(srfi srfi-9))
(define-record-type <lunch>
(make-lunch food duration location)
lunch?
(food lunch-food)
(duration lunch-duration)
(location lunch-location))
(define dine-out
(make-lunch "pizza" "30 min" "downtown"))
;; maybe this should be a syntax error instead of a runtime error?
(define (list-lunch)
(match-lambda (($ <lunch> food duration location )
(list food duration location))))
;; this is the proper way to do it.
(define list-lunch
(match-lambda (($ <lunch> food duration location )
(list food duration location))))
#+END_SRC
I eventually discovered what the issue was, but I had to run the code
to discover it.
I don't know if this is a silly bug report. If it is, sorry for the
noise.
Thanks,
Joshua
P.S. Guile's error messages at compile time and runtime are super
well written. Thanks!
- bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?,
Joshua Branson <=
- bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?, Ricardo Wurmus, 2021/01/21
- bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?, Stefan Israelsson Tampe, 2021/01/21
- bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?, Joshua Branson, 2021/01/21
- bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?, Ricardo Wurmus, 2021/01/21
- bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?, Joshua Branson, 2021/01/22
- bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?, tomas, 2021/01/22
- bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?, Ricardo Wurmus, 2021/01/23
- bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?, Joshua Branson, 2021/01/23
- bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?, Ricardo Wurmus, 2021/01/23