On this page:
get-conf
unpack-submission
make-evaluator/  submission
call-with-evaluator
call-with-evaluator/  submission
evaluate-all
evaluate-submission
check-proc
check-defined
look-for-tests
user-construct
test-history-enabled
message
set-run-status
current-value-printer
reraise-exn-as-submission-problem
log-line
timeout-control
get-user-assignment-directory
get-assignment-name
get-submit-on-error?
server-dir

6.2 Utilities🔗ℹ

 (require handin-server/utils) package: handin

procedure

(get-conf key)  any/c

  key : symbol?
Returns a value from the configuration file (useful for reading things like field names, etc.). Known keys (see Server Setup) have defaults and some have their values go through a translation (for example, 'active-dirs produces a list of complete paths). Other keys get neither, and an exception is raised if the key is not specified.

procedure

(unpack-submission submission)

  
(is-a?/c text%) (is-a?/c text%)
  submission : bytes?
Returns two text% objects corresponding to the submitted definitions and interactions windows.

procedure

(make-evaluator/submission language    
  require-paths    
  content)  (any/c . -> . any)
  language : 
(or/c module-path?
      (list/c (one-of/c 'special) symbol?)
      (list/c (one-of/c 'module) module-path?)
      (cons/c (one-of/c 'begin) list?))
  require-paths : (listof path-string?)
  content : bytes?
Like make-evaluator, but the definitions content is supplied as a submission byte string. The byte string is opened for reading, with line-counting enabled.

In addition to the language specification for make-evaluator, the language argument can be a list that begins with 'module. In this case, make-module-language is used to create an evaluator, and the module code must be using the specified language in its language position. In this case, the requires-paths argument is used only for paths that are allowed to be accessed (the allow-read argument to make-evaluator, since the submission is expected to be a complete submission.)

procedure

(call-with-evaluator language    
  require-paths    
  input-program    
  proc)  any
  language : 
(or/c module-path?
      (list/c (one-of/c 'special) symbol?)
      (list/c (one-of/c 'module) module-path?)
      (cons/c (one-of/c 'begin) list?))
  require-paths : (listof path-string?)
  input-program : any/c
  proc : (any/c . -> . any)
Calls proc with an evaluator for the given language, teachpack paths, and initial definition content as supplied by input-program (see make-evaluator). It also sets the current error-value print handler to print values in a way suitable for language, it initializes set-run-status with "executing your code", and it catches all exceptions to re-raise them in a form suitable as a submission error. See make-evaluator/submission for further details.

procedure

(call-with-evaluator/submission language    
  require-paths    
  submission    
  proc)  any
  language : 
(or/c module-path?
      (list/c (one-of/c 'special) symbol?)
      (list/c (one-of/c 'module) module-path?)
      (cons/c (one-of/c 'begin) list?))
  require-paths : (listof path-string?)
  submission : bytes?
  proc : (any/c . -> . any)
Like call-with-evaluator, but the definitions content is supplied as a byte string. The byte string is opened for reading, with line-counting enabled. See call-with-evaluator and make-evaluator/submission for further details.

procedure

(evaluate-all source input-port eval)  any

  source : any
  input-port : port?
  eval : (any/c . -> . any)
Like load on an input port.

procedure

(evaluate-submission submission eval)  any

  submission : bytes?
  eval : (any/c . -> . any)
Like load on a submission byte string.

procedure

(check-proc eval    
  expect-v    
  compare-proc    
  proc-name    
  arg ...)  any
  eval : (any/c . -> . any)
  expect-v : any/c
  compare-proc : (any/c any/c . -> . any)
  proc-name : symbol?
  arg : any/c
Calls the function named proc-name using the evaluator eval, giving it the (unquoted) arguments arg ... Let result-v be the result of the call; unless (compare-proc result-v expect-v) is true, an exception is raised.

Every exception or result mismatch during the call to compare-proc is phrased suitably for the handin client.

procedure

(check-defined eval name)  any

  eval : (any/c . -> . any)
  name : symbol?
Checks whether name is defined in the evaluator eval, and raises an error if not (suitably phrased for the handin client). If it is defined as non-syntax, its value is returned. Warning: in the beginner language level, procedure definitions are bound as syntax.

procedure

(look-for-tests text name n)  any

  text : (is-a?/c text%)
  name : symbol?
  n : number?
Inspects the given text% object to determine whether it contains at least n tests for the function name. The tests must be top-level expressions.

procedure

(user-construct eval name arg ...)  any

  eval : (any/c . -> . any)
  name : symbol?
  arg : any/c
Like check-proc, but with no result checking. This function is often useful for calling a student-defined constructor.

parameter

(test-history-enabled)  any/c

(test-history-enabled on?)  void?
  on? : any/c
Controls how run-time errors are reported to the handin client. If the parameter’s value is true, then the complete sequence of tested expressions is reported to the handin client for any test failure. Set this parameter to true when testing programs that use state.

procedure

(message string)  void?

  string : string?
(message string styles)  void?
  string : string?
  styles : 'final
(message string styles)  any
  string : string?
  styles : 
(listof (or/c 'ok 'ok-cancel 'yes-no
              'caution 'stop))
The first case of message is intended to update the client on the current activity — it updates the status line in the submission dialog box on the client. Use it to indicate operations that might take a while and/or indicate progress during these operations.

In the second case, where 'final is used as a flag, does not show the text immediately — instead, it causes it to be displayed in the status line after a successful submission instead of the usual “Handin successful” message. This is useful for submissions that are accepted but had some problems.

The third case, when styles is a list of symbols, opens a message-box dialog on the client side, and the resulting value is returned as the result of message. The styles list is passed as the style argument to message-box. You can use this to send warnings to the student or to ask for confirmation, for example, “your submission does not pass 3 tests, continue?”.

procedure

(set-run-status status)  void?

  status : (or/c false? string?)
Registers information about the current actions of the checker, in case the session is terminated due to excessive memory consumption or a timeout. For example, a checker might set the status to indicate which instructor-supplied test was being executed when the session aborted.

parameter

(current-value-printer)  (any/c . -> . string?)

(current-value-printer proc)  void?
  proc : (any/c . -> . string?)
Controls how values are printed. The proc must be a procedure that expects a Racket value and returns a string representation for it. The default value printer uses pretty-print, with DrRacket-like settings.

procedure

(reraise-exn-as-submission-problem thunk)  any

  thunk : (-> any)
Calls thunk in a context that catches exceptions and re-raises them in a form suitable as a submission error. It returns the value returned by thunk if no exception occurs.

procedure

(log-line fmt args ...)  void?

  fmt : string?
  args : any/c
Produces a line in the server log file, using the given format string and arguments. This function arranges to print the line fast (to avoid mixing lines from different threads) to the error port, and flush it. (The log port will prefix all lines with a time stamp and a connection identifier.)

procedure

(timeout-control msg)  void?

  msg : any?
Controls the timeout for this session. The timeout is initialized by the value of the session-timeout configuration entry, and the checker can use this procedure to further control it: if msg is 'reset the timeout is reset to session-timeout seconds; if msg is a number the timeout will be set to that many seconds in the future. The timeout can be completely disabled using 'disable or #f. (Note that before the checker is used (after the pre-checker, if specified), the timer will be reset to the 'session-timeout value.)

Returns the path for a submission currently being checked.

procedure

(get-assignment-name)  string?

Returns the name of the assignment for a submission currently being checked.

Returns #t if the client is configured to include an Submit even if server reports problems checkbox and the user checked it, #f otherwise.

The main directory the server is running from. Useful for getting to files that are not local to a specific submission.