At Thu, 26 Sep 2019 00:46:23 +0000, "'Wayne Harris' via Racket Users" wrote:
> I think my message below neither asked any question nor did it contain the
> adequate politeness which I so much think every e-mail should have.
I don't see any problem with your message. It's more that the handin
server doesn't get a lot of love. I know the little part that I use,
and not much else...
> > I haven't figured out how to forbid the use of length in submitted code.
> I'm a little lost with
> >
> > :language
> > :with-submission-bindings
> >
> > I did understand
> >
> > :requires
> >
> > so I'm able to let submissions use extra libraries, but I'd like to forbid,
> say, length in '(special beginner) too.
There doesn't seem to be a simple way of disallowing the use of
`length`. Since `submission` is bound to the whole submission content,
you could have `pre:` action that reads and searches for the symbol
'length:
#lang s-exp handin-server/checker
(require racket/gui/base)
(check: :language '(special beginner))
(pre:
(define (mentions-length? r)
(cond
[(eq? r 'length) #t]
[(pair? r) (or (mentions-length? (car r))
(mentions-length? (cdr r)))]
[else #f]))
(define-values (defns interactions) (unpack-submission submission))
(define p (open-input-text-editor defns))
(parameterize ([read-accept-reader #t])
(let loop ()
(define r (read p))
(unless (eof-object? r)
(when (mentions-length? r)
(error "length not allowed"))
(loop)))))
A more precise approach would be to expand the program and check
whether there's any identifier bound to `length` that was part of the
original program (as opposed to introduced by a macro), but that's
probably more than you need. Or, of course, you could have a language
that's like Beginner without `length`, but that's probably too much
trouble for your students to set up.