(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.
Related
Is it possible to write documentation in source files like in Common Lisp or Go, for example, and extract it from source files? Or everybody uses Scribble to document their code?
The short answer is you can write in-source documentation by using scribble/srcdoc.
Unlike the other languages you mentioned, these aren't "doc strings":
Although you can write plain text, you have full Racket at-expressions and may use scribble/manual forms and functions.
Not only does this allow for "richer" documentation, the documentation goes into its own documentation submodule -- similar to how you can put tests into test submodules. This means the documentation or tests add no runtime overhead.
You do need one .scrbl file, in which you use scribble/extract to include the documentation submodule(s). However you probably want such a file, anyway, for non-function-specific documentation (topics such as introduction, installation, or "user's guide" prose as opposed to "reference" style documentation).
Of course you can define your own syntax to wrap scribble/srcdoc. For example, in one project I defined a little define/doc macro, which expands into proc-doc/names as well as a (module+ test ___) form. That way, doc examples can also be used as unit tests.
How Racket handles in-source documentation intersects a few interesting aspects of Racket:
Submodules let you define things like "test-time" and "doc-time" as well as run-time.
At-expressions are a different syntax for s-expressions, especially good when writing text.
Scribble is an example of using a custom language -- documentation-as-a-program -- demonstrating Racket's ability to be not just a programming language, but a programming-language programming language.
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"
I don't really understand the arguments and usage of define-syntax within Scheme. For what it's worth, I'm using Petite Chez Cheme. I've looked at a few sources:
define-syntax issue in scheme
Scheme Macro for nesting expressions
http://docs.racket-lang.org/guide/pattern-macros.html
However, they haven't given me the understanding I'm looking for. I'm looking for an explicit explanation of what's happening when the new syntax is applied. I'm particularly curious about the use of ellipses ("...") when the syntax is defined.
I managed to find a detailed document about patterns and define-syntax through a little bit more search. If anybody else is curious, here is the link:
http://www.cs.uml.edu/~giam/91.531/Textbooks/RKDybvig.pdf
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.
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.