mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-05 04:44:12 +03:00
d93985d7e7
Carp preserves tabulation and other whitespace in strings, as it should. This sometimes results in awkward code indentation when it comes to long doc strings that exceed 80 characters. Often, one has to continue the string on a newline, but needs to avoid adding tabs to prevent Carp from rendering them in the output. This change alters the behavior of doc to take a series of strings as a rest parameter instead, allowing for neater organization in the source, for example, after this change the following long doc string for compose: ~~~ "Returns the composition of two functions `f` and `g` for functions of any arity; concretely, returns a function accepting the correct number of arguments for `g`, applies `g` to those arguments, then applies `f` to the result. If you only need to compose functions that take a single argument (unary arity) see `comp`. Comp also generates the form that corresponds to the composition, compose contrarily evaluates 'eagerly' and returns a computed symbol. For exmaple: ``` ;; a silly composition ((compose empty take) 3 [1 2 3 4 5]) ;; => [] (String.join (collect-into ((compose reverse map) Symbol.str '(p r a c)) array)) ;; => 'carp' ;; comp for comparison ((comp (curry + 1) (curry + 2)) 4) ;; => (+ 1 (+ 2 4)) ```" ~~~ becomes: ~~~ "Returns the composition of two functions `f` and `g` for functions of any" "arity; concretely, returns a function accepting the correct number of" "arguments for `g`, applies `g` to those arguments, then applies `f` to the" "result." "" "If you only need to compose functions that take a single argument (unary arity)" "see `comp`. Comp also generates the form that corresponds to the composition," "compose contrarily evaluates 'eagerly' and returns a computed symbol." "```" ";; a silly composition" "((compose empty take) 3 [1 2 3 4 5])" ";; => []" "" "(String.join (collect-into ((compose reverse map) Symbol.str '(p r a c)) array))" ";; => 'carp'" "" ";; comp for comparison" "((comp (curry + 1) (curry + 2)) 4)" ";; => (+ 1 (+ 2 4))" "```") ~~~ And the output remains the same; this just enables better alignment in the source file. The strings passed to doc are newline separated by default, but one can circumvent this behavior by passing a bool along with the string as follows: ~~~ (doc foo ("My amazing doc " false) "continues on one line." "" "And then another.") ~~~ The above doc string will result in the following output: ~~~ My amazing doc continues on one line. And then another. ~~~ Of course, the original behavior of doc also remains valid, so if one prefers to use the old indentation-mixed single string format, one still can! This change also reformats the doc strings in macro to utilize the new rest parameter and make the source a bit neater. |
||
---|---|---|
.. | ||
Array.carp | ||
ArrayExt.carp | ||
Bench.carp | ||
Binary.carp | ||
Bool.carp | ||
Byte.carp | ||
carp_bench.h | ||
carp_binary.h | ||
carp_bool.h | ||
carp_byte.h | ||
carp_char.h | ||
carp_debug.h | ||
carp_double.h | ||
carp_float.h | ||
carp_int.h | ||
carp_io.h | ||
carp_long.h | ||
carp_memory.h | ||
carp_pattern.h | ||
carp_safe_int.h | ||
carp_stdbool.h | ||
carp_stdint.h | ||
carp_string.h | ||
carp_system.h | ||
carp_utf8.h | ||
Char.carp | ||
Collection.carp | ||
Color.carp | ||
Control.carp | ||
Core.carp | ||
core.h | ||
Debug.carp | ||
Double.carp | ||
Dynamic.carp | ||
Filepath.carp | ||
Float.carp | ||
Format.carp | ||
Generics.carp | ||
Geometry.carp | ||
GLFW.carp | ||
Heap.carp | ||
Int.carp | ||
Interfaces.carp | ||
Introspect.carp | ||
IO.carp | ||
Long.carp | ||
Macros.carp | ||
Map.carp | ||
Maybe.carp | ||
Opaque.carp | ||
OpenGL.carp | ||
Pattern.carp | ||
Phantom.carp | ||
Pointer.carp | ||
Random.carp | ||
Result.carp | ||
SafeInt.carp | ||
SDL_gfx.carp | ||
SDL_image.carp | ||
SDL_mixer.carp | ||
SDL_ttf.carp | ||
SDL.carp | ||
SDLHelper.h | ||
Sort.carp | ||
StaticArray.carp | ||
Statistics.carp | ||
StdInt.carp | ||
String.carp | ||
System.carp | ||
Test.carp | ||
Tuples.carp | ||
Unsafe.carp | ||
Vector.carp |