On Fri, Apr 10, 2020 at 08:18:38PM -0400, Jon Zeppieri wrote: > (define (unique [list : (Listof Any)] [message : String] . > [messageargs : Any *]) > ; return the only element of the list, or '() if there is none. > ; Produce message if not just one. > (if (equal? 1 (length list)) (car list) > (begin > (apply fprintf anomaly message messageargs) > (if (null? list) list (car list)))))
Thank you. That worked. The change to the apply syntax surprised me. -- hendrik > > On Fri, Apr 10, 2020 at 7:49 PM Hendrik Boom <[email protected]> wrote: > > > > Trying to convert the following to typed Racket: > > > > (define (unique list message . messageargs) > > ; return the only element of the list, or '() if there is none. > > ; Produce message if not just one. > > (if (equal? 1 (length list)) (car list) > > (begin > > (apply fprintf (cons anomaly (cons message messageargs))) > > (if (null? list) list (car list)) > > ) > > ) > > ) > > > > It's an error message function tat accepts a list to test. > > If the test fails it uses fprintf to print a message with the > > arguments for the ~s items. > > > > I got so far, but I don't know what to do with the . messageargs : > > > > (define (unique [list (Listof Any)] [message : String] . messageargs) > > ; return the only element of the list, or '() if there is none. > > ; Produce message if not just one. > > (if (equal? 1 (length list)) (car list) > > (begin > > (apply fprintf (cons anomaly (cons message messageargs))) > > (if (null? list) list (car list)) > > ) > > ) > > ) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20200411134316.yff5tg7kwtglcs62%40topoi.pooq.com.

