Ricardo Wurmus <rek...@elephly.net> writes:

> Hi,
>
>> 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?
>
> This is not a bug.  What you call “thunk” here is a procedure that
> returns a procedure.  That’s very common and is often done to delay
> evaluation.
>
> It is in fact an error to call the procedure “thunk” with an argument.
> It doesn’t matter that it happens to return a procedure that *can* take
> an argument.  The procedure it returns is just like any other value,
> though, and isn’t inspected any further.
>
> That said, it is not true that Guile will compile this without a
> complaint.  I dumped your code snippet in a file foo.scm and
> compiled it:
>
> guild compile foo.scm
> foo.scm:6:0: warning: wrong number of arguments to `thunk'
> wrote 
> `/home/rekado/.cache/guile/ccache/3.0-LE-8-4.4/home/rekado/dev/gx/gwl/foo.scm.go'
>
> Isn’t that exactly what you’re asking for?

Gotcha.  Thanks for explaining!  I suppose what I meant to say is,
should guile refuse to compile the above?  In other languages, like C I
suppose, writing a function simultaneous with one and two arguments
would refuse to compile.  The compiler would make you fix the code.

Should guile do this as well?

When I look at

#+BEGIN_SRC scheme
(define (thunk)
   (lambda (x)
     x))
#+END_SRC

or

#+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 refuse to compile?
(define (list-lunch)
     (match-lambda (($ <lunch> food duration location )
                    (list food duration location))))
#+END_SRC

My thought is, this is clearly a mistake.  This person needs to change
the above code.

Thanks,

Joshua

P.S.  I'm not a scheme expert.  I'm only reporting this, because I
recently read a blog post about free software users rarely report
perceived issues.  I'm just trying to be helpful.  :)  Thanks for the
speedy response time.

--
Joshua Branson (joshuaBPMan in #guix)
Sent from Emacs and Gnus
  https://gnucode.me
  https://video.hardlimit.com/accounts/joshua_branson/video-channels
  https://propernaming.org
  "You can have whatever you want, as long as you help
enough other people get what they want." - Zig Ziglar



  • bug#46014: (def... Bug reports for GUILE, GNU's Ubiquitous Extension Language
    • bug#46014:... Ricardo Wurmus
      • bug#46... Stefan Israelsson Tampe
        • bu... Bug reports for GUILE, GNU's Ubiquitous Extension Language
      • bug#46... Bug reports for GUILE, GNU's Ubiquitous Extension Language
        • bu... Ricardo Wurmus
          • ... Bug reports for GUILE, GNU's Ubiquitous Extension Language
            • ... tomas
            • ... Ricardo Wurmus
              • ... Bug reports for GUILE, GNU's Ubiquitous Extension Language
                • ... Ricardo Wurmus
    • bug#46014:... Bug reports for GUILE, GNU's Ubiquitous Extension Language

Reply via email to