Skip to content

Instantly share code, notes, and snippets.

@Metaxal
Created October 18, 2021 13:33
Show Gist options
  • Save Metaxal/f6ac67013ba494b6911dc1696d19f0b8 to your computer and use it in GitHub Desktop.
Save Metaxal/f6ac67013ba494b6911dc1696d19f0b8 to your computer and use it in GitHub Desktop.
Using quickscripts as normal racket modules
#lang racket/base
(require quickscript-extra/scripts/provided-by ; exports the `provided-by` script, which is also a function
racket/class)
;; Create a mock class to avoid creating an actior editor% from the framework.
(define my-ed%
(class object%
(init-field string)
(define/public (get-start-position) 0)
(define/public (get-end-position) 0)
(define/public (get-backward-sexp start-pos) 0)
(define/public (get-forward-sexp start-pos) 0)
(define/public (get-text start end) string)
(super-new)))
(provided-by "" #:editor (new my-ed% [string "string-join"]))
(provided-by "" #:editor (new my-ed% [string "first"]))
@Metaxal
Copy link
Author

Metaxal commented Oct 18, 2021

This example shows how a quickscript can be used entirely outside of DrRacket. There's no running dependency on racket/gui (nor on DrRacket). We can create a mock editor% class that just returns what the script needs [1].

There are, however, installing dependencies on quickscript and quickscript-extra, and the former has dependencies on DrRacket. [2]

[1] A better design of the script would provide an intermediate function that doesn't depend on the editor, but at least this example shows how to make it work even with a bad design.

[2] Possibly the core of quickscript could be extracted to an independent package quickscript-core, say, without an dependency on DrRacket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment