~williewillus/r16

4cb45101934379f1e21e3018269dc8ffa3153b39 — Vincent Lee 30 days ago cfbdc0c
Add currently running trick name to the environment
2 files changed, 17 insertions(+), 4 deletions(-)

M backend.rkt
M scribblings/r16.scrbl
M backend.rkt => backend.rkt +13 -4
@@ 20,12 20,13 @@
    (init-field db)
    (field [start-time (current-seconds)])

    (define (evaluation-context enrich-context context-id trick args parent-ctx)
    (define (evaluation-context enrich-context context-id trick name args parent-ctx)
      (define this-context #f)

      (define/contract (call-subtrick name arguments)
        (-> (or/c symbol? string?) any/c any)
        (define trick-obj (db:get-trick db context-id (~a name)))
        (define strname (~a name))
        (define trick-obj (db:get-trick db context-id strname))
        (if trick-obj
            (let ()
              (define rr


@@ 35,6 36,7 @@
                  enrich-context
                  context-id
                  trick-obj
                  strname
                  (if arguments (~a arguments) "")
                  this-context)
                 (const #t)))


@@ 52,6 54,7 @@
        `(((string-args    . ,args)
           (read-args      . ,read-args)
           (call-trick     . ,call-subtrick)
           (trick-name     . ,name)
           (parent-context . ,(and parent-ctx (make-hash (car parent-ctx)))))
          threading))
      (set! this-context (enrich-context base trick args parent-ctx))


@@ 62,7 65,10 @@

    (define/public (evaluate code)
      (define enrich-context (send (current-frontend) get-enrich-context))
      (define ev-ctx (evaluation-context enrich-context (current-context-id) #f "" #f))
      (define ev-ctx (evaluation-context
                      enrich-context
                      (current-context-id)
                      #f "" "" #f))
      (ev:run code ev-ctx response?))

    (define/public (call name args)


@@ 77,7 83,10 @@
                             t)
                           (const #t))
         (define enrich-context (send (current-frontend) get-enrich-context))
         (define ev-ctx (evaluation-context enrich-context (current-context-id) trick-obj args #f))
         (define ev-ctx (evaluation-context
                         enrich-context
                         (current-context-id)
                         trick-obj name args #f))
         (define code (trick-body trick-obj))
         (ev:run code ev-ctx response?)]
        [else

M scribblings/r16.scrbl => scribblings/r16.scrbl +4 -0
@@ 60,6 60,10 @@ If @racket[argument] is @racket[#f], then an empty string is passed to the subtr
Text of the message after the bot command, as a string.
}

@defthing[trick-name string?]{
The name of the currently running trick, as a string. For ad-hoc evaluations, the string is empty.
}

@defproc[(read-args) (or/c (listof any/c) #f)]{
Function that returns @racket[string-args], but as a list of datums read by @racket[read]. If there is a read failure, @racket[#f] is returned.
}