The use of #: in the program listing below

I'm less than a week into learning DrRacket and one of my books on Racket had a brief routine to plot 2 cycles of a sine wave. It didn't run as written in the book but it was fairly easy to get it to run in DrRacket however, in the listing below I do not understand the last two #: statements and even after reading the DrRacket documentation I do not understand. A simple explanation would be greatly appreciated..

#lang racket
(require plot)
(plot-new-window? #t)
(plot (function sin #:color "Blue")
      #:x-min (* -2 pi) #:x-max {* 2 pi}
      #:title "The Sine Function")
1 Like

i'm not sure to understand well the question... but #: seems to be used to use named parameters and the {* 2 pi} could be (* 2 pi) even if the 2 are working in Racket { } is used in SRFI-105 curly-infix.

See the plot docs and then Keywords in the Reference which also links to the Guide.

You might also want to know how to make your own procedures that accept keyword arguments; see Procedure expressions as a possible starting point, or maybe Notation for documentation.

Thanks for the reply however I may be a little dense (or a tad senile :rofl:) but this usage #:x-min (* -2 pi) #:x-max {* 2 pi) wasn’t obvious like this is (plot (function sin (* -2 pi)(* 2 pi) #:label "y = sin(x)")) . I will go back and re-read the stuff on :# and see if I can see where I missed the boat.

Cheers,

(Code formatting mine, and I switched an erroneous {* 2 pi) for (* 2 pi) even though the original post had {* 2 pi}.)

The docs for how a keyword affects the procedure are in the documentation for that procedure (so plot, I linked above).

I may not be understanding your question, though.

Are you familiar with other programming languages? Python calls these keyword arguments with a plot(x_min=2*pi, …) syntax. Some other languages call these "named arguments."

Other programming languages, FORTRAN 66 using IBM punch cards on mainframe computer. that filled a very large room. When I got my first computer running CP/M with a Z80 running at a blazing 4MHz, I used C-Basic until the initial release of Turbo Pascal which I used in my work for a decade or so, also briefly flirted with Modula2 however around 1970 I switched to FORTH for the remainder of may 52 year career. Since retiring I have been using Mathematica for all of my post retirement consulting work however, it takes the concept of a "High Level Language" to extreme heights. So, for my personal computing needs I looked for something different and after trying a few things things settled on DrRacket which is not all that much like any of my previous experience. However, it's much fun and the DrRacket IDE is great.

1 Like

On Jan 21, 2025, at 5:57 PM, munroec wrote that "it's much fun and the DrRacket IDE is great.” Thanks for your feedback and I am sure Robby loves to receive this well-deserved compliment in writing.

1 Like

Thank you all that helped get me by this latest sticking point. BTW I have found that this form of the problem is the one that I'm most comfortable with.

(require plot)
(plot-new-window? #t)
(plot (function cosh #:color "Red")
                     #:x-min (* -2 pi) 
                     #:x-max {* 2 pi}
                     #:title "The  Hyperbolic Cosine (cosh) Function")

If you have a procedure with ten parameters, you probably missed some, but meanwhile at least use keyword arguments.

-- Sort of but not quite Alan Perlis

2 Likes

You're undoubtedly correct and every other language I have experience with that is the method, however the truth is I have not gotten that far in the book that I'm working from to know how to create a named variable! :rofl: Seriously though I do appreciate the comments, they're quite helpful and this is all great fun.

Cheers,

1 Like