What does `#:` mean in Guile? - scheme

I normally use MIT/GNU Scheme, but found some Guile code in github (guile-2d).
(define main-menu
(make-scene
"Main Menu"
#:init create-menu
#:enter menu-enter
#:exit menu-exit
#:draw draw-menu
#:update update-menu
#:events `((key-down . ,menu-key-down))))
I first checked the MIT/GNU Scheme reference, which turned up additional notations, but that had nothing about #: in it.
I then glanced through the Guile manual, and found a few mentions (Profile Commands, Debugging Commands) that looked like it perhaps specified optional arguments? Something akin to this in Python:
def foo(test):
return test
foo(bar="test")
Anyone know for sure what it means?

That's just syntax for Guile's keyword arguments. Take a look at the documentation for more details.

That is the keyword argument syntax introduced by PLT Scheme 4.

Related

Colon in Scheme

(show-data 'YHOO :config 'my-config)
I saw some Scheme code (in Guile) like the line above and get confused with the colon syntax :config .
What kind of language features of this? Is it a intrinsic feature of Scheme, or specially designed for the Guile lib? How does it work? I kept searching this online but still found nothing. Thanks.
It's a keyword and its purpose is to make the invocation of a procedure that receives optional arguments easier and convenient.
You can read more about this feature in this section of the Guile Reference Manual.

Strings in the middle of lisp S-exp?

I have Googled a handful of things such as "lisp documentation strings", "lisp comments", and a few others and I cant find anything that specifically addresses this.
I see a lot of code (especially in CL and elisp) that looks like
(defvar test 1
"This is a quoted string and it says things"
)
Where I would normally do
; This is a comment
(defvar test 1)
Which is preferred? Do each serve a different purpose? Thanks!
Many objects in Common Lisp can have a documentation string, that can be retrieved with the generic function documentation and set with the generic function (setf documentation). According to the specification:
Documentation strings are made available for debugging purposes. Conforming programs are permitted to use documentation strings when they are present, but should not depend for their correct behavior on the presence of those documentation strings. An implementation is permitted to discard documentation strings at any time for implementation-defined reasons.
So the first case allows the definition of a variable together with its documentation string, that can be used to store at run-time, if the implementation permits so, information useful for documentation and debugging purposes, either used through the IDE, or directly, through a form like:
(documentation 'test 'variable)
The second case, instead, is just a comment inside a source file, useful only for human consumption, and it is completely ignored by the reader/compiler of the system.
Development environments will use these documentation features. For example GNU Emacs / SLIME:
Move the text cursor onto the symbol test.
Type c-c c-d c-d (Describe Symbol).
Now SLIME displays a buffer with the following content:
COMMON-LISP-USER::TEST
[symbol]
TEST names a special variable:
Value: 1
Documentation:
This is a quoted string and it says things
A simple comment in the source code won't enable this form of development environment integration and documentation lookup.
I saw your tag included scheme and elisp as well. In CL and Elisp always use docstrings. They are used by documentation systems in their languages. Scheme does not have that feature so you will have to continue using comments to document functions.
Did't you try to see hyperspec for defvar?
defvar takes an optional argument - document string, and this is what are you talking about.
Documentation specified this way can be acessed throug documentation:
CL-USER> (defvar *a* "A variable" "A docstring")
*A*
CL-USER> (documentation '*a* 'variable)
"A docstring"

"require" not working in dr racket

I am new to scheme and I am trying to trace a function. I have to load the "trace" function. According to the racket documentation, I have to execute a:
(require racket/trace)
But the response I am getting back is
require: undefined;
cannot reference undefined identifier
I am baffled. I am using language "R5RS" if that makes a difference. can't find anything online or on stack overflow on this.
Try this:
(#%require racket/trace)
Chris Jester-Young's comment is correct: don't use R5RS. In the standard R5RS language, there's no such thing as a module. Go look at http://www.schemers.org/Documents/Standards/R5RS/; not a word about a module, right?
Racket takes the standard more seriously than you'd expect: if you tell it to work in R5RS mode, it will turn off language features that the standard does not describe.
If you're using the Racket toolchain, don't use the R5RS language unless you really want to work in a restrictive language. Use standard #lang racket instead. See: http://docs.racket-lang.org/guide/intro.html which shows how to use it in that mode.

Where to find Scheme library functions?

Is there a reference website to look up syntax for Scheme library function like http://www.cplusplus.com/reference/?
I'm looking for syntax of fold, but google gave me nothing :(
Thanks,
fold is from SRFI 1. Many functions have good documentation if you know where it "comes from".
Also, since you're using Racket (as mentioned in your previous questions), you should check out the Racket documentation. It has a very nice search facility. (Also, you might like to know about Racket's foldl, which is identical to SRFI 1's fold.)

Guile scheme - quoted period?

What does the following Guile scheme code do?
(eq? y '.)
(cons x '.)
The code is not valid in MzScheme, is there a portable equivalent across scheme implementations?
I am trying to port this code written by someone else. Guile seems to respond to '. with #{.}#, but I'm not sure what it means or how to do this in another scheme.
Okay, it seems that '. is valid syntax for (string->symbol ".") in Guile, whereas MzScheme at least requires |.| for the period as a symbol.
#{.}# is Guile specific way to define the symbol contains some delimiters of Scheme.
http://www.gnu.org/software/guile/manual/html_node/Symbol-Read-Syntax.html
For other Scheme dialect, there should be another way.
I'm surprised any Scheme system will accept a dot symbol at all. My advice is to use another symbol as (I'm sure you're aware) the dot is a shorthand to represent a pair, and even if you can find a Scheme that will take your code you will likely confuse anyone that has the unfortunate task of actually reading your code.

Resources