Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
; an imaginary syntax for docstrings. Goals:
;
; - runtime introspectable
; - DRY including explicit docs for each procedure
; argument, and its return value
; - hyperlinks in docstrings
; - executable code examples (doctests)
; - docstrings are rewrapped/formatted and docs for args
; and return value are formatted and appended for
; (procedure-documentation <proc>)
;
; Scheme's double-quote works for multi-line strings, but
; I'd still like Python's triple-double-quoted strings here
; so that I don't need to worry about escaping quote
; characters in long multiline docstrings.
;
; Texinfo seems to be the favored doc format in the Scheme
; community but it's full of ugly markup. I prefer
; markdown.
;
; Python likes the closing tripledoublequote for its
; docstrings on its own line to make paragraph wrapping
; easier in emacs. Not sure if I want to adopt that
; convention.
;
; Should there be some kind of formal/programmatically
; accessible type information? my gut says no
(define/doc
(gcd "an integer, the greatest common divisor of x and y" ; doc for return value
x "an integer" ; argument and doc
y "an integer") ; argument and doc
"""The "greatest common divisor" (gcd) of two or more
integers, when at least one of them is not zero, is the
largest positive integer that divides the numbers without
a remainder.
(gcd 8 12)
4
The greatest common divisor is also known as the greatest
common factor (gcf), highest common factor (hcf),
greatest common measure (gcm), or highest common divisor.
From [Wikipedia](https://en.wikipedia.org/wiki/Greatest_common_divisor).
"""
(if (= y 0)
x
(gcd y (rem x y))))
(define/doc
(factorial "an integer, the factorial of n"
n "a non-negative integer")
"""The factorial of a non-negative integer n, denoted by
n!, is the product of all positive integers less than or
equal to n."""
(if (<= n 1)
1
(* n (factorial (- n 1)))))
; With:
; srfi-119 (wisp significant whitespace syntax),
; an imaginary format-string syntax
; an imaginary paragraph-formatter "wrap"
define-module : gnu packages less
. #:use-module : guix licenses ; gpl3+
. #:use-module : gnu packages ncurses ; ncurses
. #:use-module : guix packages ; package name version source origin method ...
. #:use-module : guix download ; url-fetch
. #:use-module : guix build-system gnu ; gnu-build-system
define-public less
package
name "less"
version "481"
source
origin
method url-fetch
uri "mirror://gnu/less/less-{version}.tar.gz"
sha256
base32 "19fxj0h10y5bhr3a1xa7kqvnwl44db3sdypz8jxl1q79yln8z8rz"
build-system gnu-build-system
inputs
`
"ncurses" ,ncurses
home-page "https://www.gnu.org/software/less/"
synopsis "Paginator for terminals"
description : wrap "
GNU less is a pager, a program that allows you to view large amounts of
text in page-sized chunks. Unlike traditional pagers, it allows both
backwards and forwards movement through the document. It also does not
have to read the entire input file before starting, so it starts faster
than most text editors.
"
license gpl3+ ; some files are under GPLv2+
; vim: set sw=2 ts=2 :
(define-module (gnu packages less)
#:use-module (guix licenses)
#:use-module (gnu packages ncurses)
#:use-module (guix packages)
#:use-module (guix download)
#:use-module (guix build-system gnu))
(define-public less
(package
(name "less")
(version "481")
(source
(origin
(method url-fetch)
(uri (string-append "mirror://gnu/less/less-"
version ".tar.gz"))
(sha256
(base32
"19fxj0h10y5bhr3a1xa7kqvnwl44db3sdypz8jxl1q79yln8z8rz"))))
(build-system gnu-build-system)
(inputs `(("ncurses" ,ncurses)))
(home-page "https://www.gnu.org/software/less/")
(synopsis "Paginator for terminals")
(description
"GNU less is a pager, a program that allows you to view large amounts
of text in page-sized chunks. Unlike traditional pagers, it allows both
backwards and forwards movement through the document. It also does not have
to read the entire input file before starting, so it starts faster than most
text editors.")
(license gpl3+))) ; some files are under GPLv2+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment