Rebol Documentation

I can write a function like this:

f: func [ "a description" arg1 [string!] "a description of an argument 1" ][ arg1 ] 

Can i use ? / help to get information about the function (description, usage, list of arguments, description of each argument and its type)

 ? f USAGE: F arg1 DESCRIPTION: a description F is a function value. ARGUMENTS: arg1 -- a description of an argument 1 (Type: string) 

I canโ€™t document such dialects. Is there an automatic way to document dialects (e.g. func )? Do I have to do it manually?

+5
source share
1 answer

There is nothing for this, but it is a good idea. So good that someone suggested it before. :-)

Do I have to do it manually?

You can manually write a new generator that defines your dialect format. Then either do something like the HELP command, or expand HELP to recognize it.

A very short example to demonstrate a group of methods that can come in handy when doing something like this (not everyone should be obvious, but rather hint at flexibility):

 make-dialect: function [spec [block!] body [block!]] [ return function ['arg [block! word!]] compose/deep/only [ case [ arg = 'HELP [ foreach keyword (spec/keywords) [ print [keyword "-" {your help here}] ] ] block? arg [ do func [arg] (body) arg ] 'default [ print "Unrecognized command. Try HELP." ] ] ] ] 

So, your function that uses the dialect specification and performs the function. Once you have a generator, its use may be less manual:

 mumble: make-dialect [keywords: [foo baz bar]] [ print ["arg is" mold arg] ] >> mumble help foo - your help here baz - your help here bar - your help here >> mumble [<some> [dialect] {stuff}] arg is [<some> [dialect] {stuff}] 

The methods used here are:

  • Soft Quoting - Usually you need to say mumble 'help to "quote" the help information as a lit word! to convey this word! (as opposed to running the HELP command by default). But since arg was declared as 'arg in the generated function, it was "soft quoted" ... this means that words and paths will not be evaluated. (Parens, get-words and get-paths will still be.) This is a compromise because it means that if someone has a variable that they want to pass to you, they should say : var or (var) as an argument, not just var (imagine if the block for transmitting the dialect is in a variable), so you donโ€™t necessarily want to use it ... but I thought it was an interesting demo to make mumble help work without highlighting!

  • Deep composition. The spec and body variables that are passed to make-dialect exist only as long as make-dialect is executed. Once this is over, they will not be. Therefore, you cannot leave these words in the body of the function that you create. It uses COMPOSE / DEEP to evaluate the parens in the body before the function generator works to produce the result, effectively extracting data for the blocks and stitching them into the structure of the function body.

  • Reuse of function binding function. The generated function has a specification with the arg parameter that did not exist on the make-dialect call site. So arg should rebound to something, but what? This can be done manually, but one easy way is to let FUNC do the work for you.

Here are some of the methods that will be used in the proposed solution, which is intended not only for documenting dialects, but also for a simple method by which their keywords can be reassigned (for example, if one Rebol system was configured for another spoken language) .

+4
source

Source: https://habr.com/ru/post/1238787/


All Articles