Re: Do I need macros to flag unbound identifiers as failing unit tests?

Sage Gerard <[email protected]>
Newsgroups gmane.comp.lang.racket.user,gmane.lisp.scheme.plt
Message-ID <CAMHoVxDY=Bx16N1kSFTtQ0RPJ_EihpSzCBMFcbujSLodCgiuhQ@mail.gmail.com>
Regarding #lang racket/koans, I opened
https://github.com/zyrolasting/racket-koans/issues/24 and would appreciate
comments from those more familiar with defining syntaxes if there are rough
edges in this design.

On Sun, Aug 12, 2018 at 10:57 AM Sage Gerard <[email protected]> wrote:

> This is great feedback, thank you both so much! I like using a language
> for this approach as the project evolves, and You's feedback is a good
> stopgap that does work, and can be applied in-place.
>
>
> On Sat, Aug 11, 2018 at 1:01 PM Matthew Butterick <[email protected]> wrote:
>
>>
>> On Aug 11, 2018, at 9:00 AM, Sage Gerard <[email protected]> wrote:
>>
>> I'm starting to think writing these kind of exercises in a friendly way
>> is only possible with macros, but before I go that far, is it possible for
>> me to catch a module-level unbound identifier error and print a rackunit
>> failure outright *without *distracting the student?
>>
>> I'd appreciate feedback on the design here too, since I have to pick a
>> direction to handle this kind of problem project-wide.
>>
>>
>> Perhaps consider making a little `racket/koan` language for your
>> exercises that includes some extra conveniences. For instance, one way to
>> address your unbound identifiers is to redefine `#%top` as shown below. But
>> you could move that into `racket/koan`.
>>
>>
>> #lang racket/base
>>
>> (require rackunit)
>>
>> (require (for-syntax racket/base))
>> (define-syntax (#%top stx)
>>   (syntax-case stx ()
>>     [(_ . id) (not (identifier-binding #'id)) #'(λ _ (format "unbound
>> identifier: ~a" 'id))]
>>     [(_ . id) #'id]))
>>
>> ;; Produce a single struct that passes all assertions.
>> (let ([p "?"])
>>   (check-pred racketeer? p)
>>   (check-pred programmer? p)
>>   (check-pred struct? p)
>>   (check-pred procedure? set-programmer-salary!)
>>   (check-equal? (programmer-confusion-level p) 10)
>>   (check-equal? (racketeer-desire-for-racket-jobs p) 9001))
>>
>

-- 
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.