If I understand correctly, the difference to getting the code to type
check was:
>         (apply fprintf (cons anomaly (cons message messageargs)))

becomes:
>        (apply fprintf anomaly message messageargs)

Since the documentation explains that the arguments to fprintf are
effectively gathered in a list*, could someone explain why the change makes
a difference? Would it the answer depend on whether messagesargs was a
list?.

Also, the first version with the cons's looks strange to me. Is there a
reason why the statement was originally coded that way? Is it perhaps an
artifact from attempting to force the result of list* to produce a list?
regardless of what is the type of of the value passed in messageargs?

Thanks in advance,

Kieron


On Sat, Apr 11, 2020 at 7:43 AM Hendrik Boom <hend...@topoi.pooq.com> wrote:

> 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 <hend...@topoi.pooq.com>
> 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 racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/20200411134316.yff5tg7kwtglcs62%40topoi.pooq.com
> .
>

-- 
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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAEEP09AhmxLHeRdOpzpuG7qC9jOuPTrpog92G_3b6nJWwZDzbw%40mail.gmail.com.

Reply via email to