Skip to content

Commit

Permalink
Merge pull request #214 from sogaiu/clarify-keyword-style-argument-usage
Browse files Browse the repository at this point in the history
Explain use of symbol after &keys (#205)
  • Loading branch information
bakpakin committed Apr 15, 2024
2 parents 60192b0 + f719e28 commit f971e7c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions content/docs/functions.mdz
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@ arguments in curly brackets!
(make-recipe-3 ;(kvs args))
```

Note that what follows @code`&keys` does not have to be a struct and
can instead be a single symbol. The symbol can then be used as a name
within the function body for a struct containing the passed keys and
values:

@codeblock[janet]```
(defn feline-counter
[&keys animals]
(if-let [n-furries (get animals :cat)]
(printf "Awww, I see %d cat(s)!" n-furries)
(print "Shucks, where are my friends?")))

(feline-counter :ant 1 :bee 2 :cat 3)
```

## Optional Flags

As a matter of style, some Janet functions allow you to optionally
Expand Down

0 comments on commit f971e7c

Please sign in to comment.