# The use of #: in the program listing below

**URL:** <https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505>\
**Category:** Questions & Answers\
**Tags:** question\
**Created:** [January 21, 2025, 4:19pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505 "2025-01-21T16:19:59Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![munroec](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@munroec](https://racket.discourse.group/u/munroec)\
**Post date:** [January 21, 2025, 4:19pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/1 "2025-01-21T16:19:59Z")

</div>

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..

```scheme
#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")

```

---

<div class="post-metadata">

**Author:** ![damien\_mattei](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/damien_mattei/32/2706_2.png) [@damien\_mattei](https://racket.discourse.group/u/damien_mattei)\
**Post date:** [January 21, 2025, 5:06pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/2 "2025-01-21T17:06:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [January 21, 2025, 5:41pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/3 "2025-01-21T17:41:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![munroec](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@munroec](https://racket.discourse.group/u/munroec)\
**Post date:** [January 21, 2025, 7:10pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/4 "2025-01-21T19:10:30Z")

</div>

Thanks for the reply however I may be a little dense (or a tad senile 🤣) 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,

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [January 21, 2025, 9:17pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/5 "2025-01-21T21:17:20Z")

</div>

> [@munroec](#):
>
> `#: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)"))`

(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."

---

<div class="post-metadata">

**Author:** ![munroec](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@munroec](https://racket.discourse.group/u/munroec)\
**Post date:** [January 21, 2025, 10:47pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/6 "2025-01-21T22:47:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [January 22, 2025, 12:10am UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/7 "2025-01-22T00:10:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![munroec](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@munroec](https://racket.discourse.group/u/munroec)\
**Post date:** [January 22, 2025, 5:46pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/8 "2025-01-22T17:46:04Z")

</div>

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.

```scheme
(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")

```

---

<div class="post-metadata">

**Author:** ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)\
**Post date:** [January 22, 2025, 10:33pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/9 "2025-01-22T22:33:10Z")

</div>

> 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_

---

<div class="post-metadata">

**Author:** ![munroec](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@munroec](https://racket.discourse.group/u/munroec)\
**Post date:** [January 23, 2025, 4:56am UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/10 "2025-01-23T04:56:14Z")

</div>

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! 🤣 Seriously though I do appreciate the comments, they're quite helpful and this is all great fun.

Cheers,

---

<div class="post-metadata">

**Author:** ![munroec](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@munroec](https://racket.discourse.group/u/munroec)\
**Post date:** [January 24, 2025, 1:34pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/11 "2025-01-24T13:34:10Z")

</div>

Greg,

Is this sorta what you meant or is there as better method?

#lang racket  
(define omega (\* 2 pi 1000))  
(define L 0.12)  
(define XL (\* omega L))  
XL

Thanks again  
Cheers,

---

<div class="post-metadata">

**Author:** ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)\
**Post date:** [January 24, 2025, 2:10pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/12 "2025-01-24T14:10:02Z")

</div>

@munroec One way to understand that Alan Perlis quote ("If you have a procedure with ten parameters, you probably forgot some"): Functions should take fewer parameters, and you should compose them.

He has another quote ~= "100 functions on 1 data structure are better than 20 on 20".

Seems he's a fan defining many, more-specific functions.

Which is good advice. But sometimes it's hard to avoid a function or data structure taking a big "duffel bag" of a dozen values.

[Maybe some real-world spec determines that, and you're modeling it. Or maybe you want to supply a convenience function for people who don't want to learn how to compose a bazillion functions exactly perfectly. Or maybe you want to de-duplicate code from various simple "flavor" functions into a core, private, helper function. Or some other scenario.]

* * *

Then you have the classic choice of "by position" or "by name". Do you call the function (or init the data structure) by position: `(foo 0 1 2)`? With three values, it's not too bad, but if you have a dozen, you're likely make a mistake. So by name is "safer": `(foo #:a 0 #:b 1 #:c 2)` is clear; `(foo #:c 2 #:b 1 #:a 0)` is identical (order doesn't matter).

There's also the choice of default values. Often, if you have a dozen parameters, some will have reasonable defaults most of the time (like `0` or `#false` or whatever). So it can be nice for functions to have _optional_ parameters -- if you don't supply a value, a default value will be used. But these much "safer" as named, keyword arguments.

Finally, it might be OK or preferable for a function to take one or two "obvious" required parameters by-position, and the rest are named and/or optional.

* * *

TL;DR: In Racket you can say `(define (foo a #:b b #:c [c 42]) ___)` to define a function `foo` that takes

- a required by-position argument bound to `a` inside the function
- a required keyword argument `#:b` (value bound to `b` inside the function)
- an optional keyword argument `#:c` (`c` defaulting to `42` if not supplied)

This can be called as `(foo "hello")`, `(foo "hello" #:b "world")`, or `(foo "hello" #:b "world" #:c 999)`.

`plot` is an example of using this technique.

---

<div class="post-metadata">

**Author:** ![munroec](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@munroec](https://racket.discourse.group/u/munroec)\
**Post date:** [January 24, 2025, 3:02pm UTC](https://racket.discourse.group/t/the-use-of-in-the-program-listing-below/3505/13 "2025-01-24T15:02:25Z")

</div>

Awesome, thank you! : 🙂
