Generating Scheme graphics with external files

Some month ago, I managed to follow the guides on generating scheme graphics by putting the code into a Scheme session in TeXmacs, but the following code no longer gives me any output:

(define pi (acos -1))

(define (pt x y)
  '(point ,(number->string x) ,(number->string y)))

(define pA (pt -2 0))
(define pB (pt 2 0))
(define pC (pt xC yC))

(stree->tree
 '(with "gr-geometry" 
     (tuple "geometry" "400px" "300px" "center")
     (graphics
        (with "color" "red"   (cline ,pA ,pB ,pC)))))

Anyway, https://texmacs.github.io/notes/docs/modular-scheme-graphics.html says

we also plan to write a post on how to generate Scheme graphics with external files.

This would help me a lot, but I’m afraid no one has found time for this so far.
It would be great if someone could quickly sketch the necessary steps here.

Let me first post the working code

(begin
  (define pi (acos -1))

(define (pt x y)
  `(point ,(number->string x) ,(number->string y)))

(define pA (pt -2 0))
(define pB (pt 2 0))
(define xC (- (* 2 (cos (/ pi 3))))); x-coordinate for point C
(define yC (* 2 (sin (/ pi 3)))); y-coordinate for point C
(define pC (pt xC yC))

(stree->tree
 `(with "gr-geometry"
     (tuple "geometry" "400px" "300px" "center")
     (graphics
        (with "color" "red" (cline ,pA ,pB ,pC))))))

In place of the quotes ' you need the backquotes

`

Quotes in Scheme direct the program to return the quoted code literally. Backquoted code, on the other hand, directs the program to interpret any part that is preceded by commas, and to return literally the rest.
In the code you posted Scheme needs to do some calculations (calculate the value of pA for example) so you need backquotes.

Let me return later to the Scheme graphics with external files (I wrote the posts on Scheme graphics, then never completed the series).

1 Like

Thanks a lot!
Stupid me, copying the code from the articles messed up the backquotes.

Please try “Paste from -> Verbatim”, it might preserve all of the characters.